Skip to content

Commit

Permalink
Use fixes for segmented_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Aug 24, 2022
1 parent 7fe804d commit ba2e32f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/mongoose_user_cache.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ start_new_cache(HostType, Module, Opts) ->

do_start_new_cache(HostType, Module, Opts) ->
CacheName = gen_mod:get_module_proc(HostType, Module),
CacheOpts = #{merger_fun => fun maps:merge/2,
CacheOpts = #{scope => mim_scope,
merger_fun => fun maps:merge/2,
segment_num => gen_mod:get_opt(number_of_segments, Opts),
strategy => gen_mod:get_opt(strategy, Opts),
ttl => gen_mod:get_opt(time_to_live, Opts)},
Expand All @@ -78,15 +79,15 @@ do_start_new_cache(HostType, Module, Opts) ->

create_metrics(HostType, Module, CacheName) ->
telemetry:attach(CacheName,
[segmented_cache, request],
[CacheName, request],
fun ?MODULE:handle_telemetry_event/4,
#{host_type => HostType, module => Module}),
#{host_type => HostType, cache_name => CacheName, module => Module}),
mongoose_metrics:ensure_metric(HostType, [Module, hit], counter),
mongoose_metrics:ensure_metric(HostType, [Module, miss], counter),
mongoose_metrics:ensure_metric(HostType, [Module, latency], histogram).

handle_telemetry_event([segmented_cache, request], #{hit := Hit, time := Latency},
_, #{host_type := HostType, module := Module}) ->
handle_telemetry_event([CacheName, request], #{hit := Hit, time := Latency},
_, #{host_type := HostType, cache_name := CacheName, module := Module}) ->
case Hit of
true -> mongoose_metrics:update(HostType, [Module, hit], 1);
false -> mongoose_metrics:update(HostType, [Module, miss], 1)
Expand Down
2 changes: 1 addition & 1 deletion test/batches_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ end_per_group(_, _Config) ->
ok.

init_per_testcase(_TestCase, Config) ->
pg:start_link(),
pg:start_link(mim_scope),
mim_ct_sup:start_link(ejabberd_sup),
meck:new(gen_mod, [passthrough]),
Config.
Expand Down

0 comments on commit ba2e32f

Please sign in to comment.