test(prometheus): `{Registry, Collector}` tuple
This commit is contained in:
parent
7832bbc0a4
commit
0dca9905dd
|
@ -25,6 +25,10 @@
|
|||
-export([conf/0, is_push_gateway_server_enabled/1]).
|
||||
-export([to_recommend_type/1]).
|
||||
|
||||
-ifdef(TEST).
|
||||
-export([all_collectors/0]).
|
||||
-endif.
|
||||
|
||||
update(Config) ->
|
||||
case
|
||||
emqx_conf:update(
|
||||
|
|
|
@ -103,13 +103,16 @@ init_group() ->
|
|||
ok = mria_rlog:wait_for_shards([?CLUSTER_RPC_SHARD], infinity),
|
||||
meck:new(emqx_alarm, [non_strict, passthrough, no_link]),
|
||||
meck:expect(emqx_alarm, activate, 3, ok),
|
||||
meck:expect(emqx_alarm, deactivate, 3, ok).
|
||||
meck:expect(emqx_alarm, deactivate, 3, ok),
|
||||
meck:new(emqx_license_checker, [non_strict, passthrough, no_link]),
|
||||
meck:expect(emqx_license_checker, expiry_epoch, fun() -> 1859673600 end).
|
||||
|
||||
end_group() ->
|
||||
ekka:stop(),
|
||||
mria:stop(),
|
||||
mria_mnesia:delete_schema(),
|
||||
meck:unload(emqx_alarm),
|
||||
meck:unload(emqx_license_checker),
|
||||
emqx_common_test_helpers:stop_apps([emqx_prometheus]).
|
||||
|
||||
end_per_group(_Group, Config) ->
|
||||
|
|
|
@ -128,8 +128,8 @@ t_legacy_prometheus_api(_) ->
|
|||
Conf2 = emqx_utils_json:decode(Response2, [return_maps]),
|
||||
?assertEqual(NewConf, Conf2),
|
||||
|
||||
EnvCollectors = application:get_env(prometheus, collectors, []),
|
||||
PromCollectors = prometheus_registry:collectors(default),
|
||||
EnvCollectors = env_collectors(),
|
||||
PromCollectors = all_collectors(),
|
||||
?assertEqual(lists:sort(EnvCollectors), lists:sort(PromCollectors)),
|
||||
?assert(lists:member(prometheus_vm_statistics_collector, EnvCollectors), EnvCollectors),
|
||||
|
||||
|
@ -221,8 +221,8 @@ t_prometheus_api(_) ->
|
|||
Conf2 = emqx_utils_json:decode(Response2, [return_maps]),
|
||||
?assertMatch(NewConf, Conf2),
|
||||
|
||||
EnvCollectors = application:get_env(prometheus, collectors, []),
|
||||
PromCollectors = prometheus_registry:collectors(default),
|
||||
EnvCollectors = env_collectors(),
|
||||
PromCollectors = all_collectors(),
|
||||
?assertEqual(lists:sort(EnvCollectors), lists:sort(PromCollectors)),
|
||||
?assert(lists:member(prometheus_vm_statistics_collector, EnvCollectors), EnvCollectors),
|
||||
|
||||
|
@ -308,3 +308,16 @@ request_stats(JsonAuth, Auth) ->
|
|||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
%%% Internal Functions
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
env_collectors() ->
|
||||
do_env_collectors(application:get_env(prometheus, collectors, []), []).
|
||||
|
||||
do_env_collectors([], Acc) ->
|
||||
lists:reverse(Acc);
|
||||
do_env_collectors([{_Registry, Collector} | Rest], Acc) when is_atom(Collector) ->
|
||||
do_env_collectors(Rest, [Collector | Acc]);
|
||||
do_env_collectors([Collector | Rest], Acc) when is_atom(Collector) ->
|
||||
do_env_collectors(Rest, [Collector | Acc]).
|
||||
|
||||
all_collectors() ->
|
||||
emqx_prometheus_config:all_collectors().
|
||||
|
|
Loading…
Reference in New Issue