Skip to content

Commit

Permalink
Update mongooseim_metrics_SUITE to use instrumentation
Browse files Browse the repository at this point in the history
By removing the last global metric, we need to switch this suite to
use instrumentation, because otherwise ther would be nothing to report
to the Graphite mock.
  • Loading branch information
chrzaszcz committed Jul 16, 2024
1 parent cdfa58e commit f193cb0
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions test/mongooseim_metrics_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@ init_per_suite(C) ->
application:load(exometer_core),
application:set_env(exometer_core, mongooseim_report_interval, 1000),
{Port, Socket} = carbon_cache_server:start(),
mongoose_config:set_opts(opts()),
C1 = async_helper:start(C, mongoose_instrument, start_link, []),
Reporters = get_reporters_cfg(Port),
application:set_env(exometer_core, report, Reporters),
PortServer = carbon_cache_server:wait_for_accepting(),
gen_tcp:controlling_process(Socket, PortServer),
{ok, _Apps} = application:ensure_all_started(exometer_core),
exometer:new([carbon, packets], spiral),
[{carbon_port, Port}, {carbon_server, PortServer}, {carbon_socket, Socket} | C1].
[{carbon_port, Port}, {carbon_server, PortServer}, {carbon_socket, Socket} | C].

end_per_suite(C) ->
async_helper:stop_all(C),
mongoose_config:erase_opts(),
CarbonServer = ?config(carbon_server, C),
erlang:exit(CarbonServer, kill),
CarbonSocket = ?config(carbon_socket, C),
Expand All @@ -48,15 +44,16 @@ end_per_suite(C) ->
C.

init_per_group(Group, C) ->
mongoose_config:set_opt(all_metrics_are_global, Group =:= all_metrics_are_global),
mongoose_metrics:init(),
mongoose_config:set_opts(opts(Group)),
C1 = async_helper:start(C, mongoose_instrument, start_link, []),
mongoose_system_probes:start(), % required to have some metrics to report
mongoose_metrics:init_mongooseim_metrics(),
C.
C1.

end_per_group(_Group, _C) ->
mongoose_metrics:remove_host_type_metrics(<<"localhost">>),
mongoose_metrics:remove_host_type_metrics(global),
mongoose_config:unset_opt(all_metrics_are_global).
end_per_group(_Group, C) ->
mongoose_system_probes:stop(),
async_helper:stop_all(C),
mongoose_config:erase_opts().

subscriptions_initialised(_C) ->
true = wait_for_update(exometer:get_value([carbon, packets], count), 60).
Expand All @@ -69,10 +66,14 @@ wait_for_update({ok, [{count,0}]}, N) ->
timer:sleep(1000),
wait_for_update(exometer:get_value([carbon, packets], count), N-1).

opts() ->
#{hosts => [<<"localhost">>],
opts(Group) ->
AllGlobal = Group =:= all_metrics_are_global,
InstrConfig = #{exometer => #{all_metrics_are_global => AllGlobal}},
#{all_metrics_are_global => AllGlobal, % legacy, remove with mongoose_metrics
hosts => [<<"localhost">>],
host_types => [],
instrumentation => config_parser_helper:default_config([instrumentation])}.
internal_databases => #{},
instrumentation => config_parser_helper:config([instrumentation], InstrConfig)}.

get_reporters_cfg(Port) ->
[{reporters, [
Expand Down

0 comments on commit f193cb0

Please sign in to comment.