test: `/prometheus/stats` endpoint format in json

This commit is contained in:
JimMoen 2024-01-30 18:15:29 +08:00
parent e57e19c9f1
commit 9e16f33c31
No known key found for this signature in database
2 changed files with 26 additions and 21 deletions

View File

@ -22,21 +22,23 @@
-compile(nowarn_export_all). -compile(nowarn_export_all).
-compile(export_all). -compile(export_all).
-define(LEGACY_CONF_DEFAULT, << -define(CLUSTER_RPC_SHARD, emqx_cluster_rpc_shard).
"prometheus {\n" %% erlfmt-ignore
" push_gateway_server = \"http://127.0.0.1:9091\"\n" -define(LEGACY_CONF_DEFAULT, <<"
" interval = \"1s\"\n" prometheus {
" headers = { Authorization = \"some-authz-tokens\"}\n" push_gateway_server = \"http://127.0.0.1:9091\"
" job_name = \"${name}~${host}\"\n" interval = \"1s\"
" enable = true\n" headers = { Authorization = \"some-authz-tokens\"}
" vm_dist_collector = disabled\n" job_name = \"${name}~${host}\"
" mnesia_collector = disabled\n" enable = true
" vm_statistics_collector = disabled\n" vm_dist_collector = disabled
" vm_system_info_collector = disabled\n" mnesia_collector = disabled
" vm_memory_collector = disabled\n" vm_statistics_collector = disabled
" vm_msacc_collector = disabled\n" vm_system_info_collector = disabled
"}\n" vm_memory_collector = disabled
>>). vm_msacc_collector = disabled
}
">>).
-define(CONF_DEFAULT, #{ -define(CONF_DEFAULT, #{
<<"prometheus">> => <<"prometheus">> =>

View File

@ -279,20 +279,23 @@ t_stats_no_auth_api(_) ->
ok ok
end, end,
emqx_dashboard_listener:regenerate_minirest_dispatch(), emqx_dashboard_listener:regenerate_minirest_dispatch(),
Json = [{"accept", "application/json"}], Headers = accept_josn_header(),
request_stats(Json, []). request_stats(Headers, []).
t_stats_auth_api(_) -> t_stats_auth_api(_) ->
{ok, _} = emqx:update_config([prometheus, enable_basic_auth], true), {ok, _} = emqx:update_config([prometheus, enable_basic_auth], true),
emqx_dashboard_listener:regenerate_minirest_dispatch(), emqx_dashboard_listener:regenerate_minirest_dispatch(),
Auth = emqx_mgmt_api_test_util:auth_header_(), Auth = emqx_mgmt_api_test_util:auth_header_(),
JsonAuth = [{"accept", "application/json"}, Auth], Headers = [Auth | accept_josn_header()],
request_stats(JsonAuth, Auth), request_stats(Headers, Auth),
ok. ok.
request_stats(JsonAuth, Auth) -> accept_josn_header() ->
[{"accept", "application/json"}].
request_stats(Headers, Auth) ->
Path = emqx_mgmt_api_test_util:api_path(["prometheus", "stats"]), Path = emqx_mgmt_api_test_util:api_path(["prometheus", "stats"]),
{ok, Response} = emqx_mgmt_api_test_util:request_api(get, Path, "", JsonAuth), {ok, Response} = emqx_mgmt_api_test_util:request_api(get, Path, "", Headers),
Data = emqx_utils_json:decode(Response, [return_maps]), Data = emqx_utils_json:decode(Response, [return_maps]),
?assertMatch(#{<<"client">> := _, <<"delivery">> := _}, Data), ?assertMatch(#{<<"client">> := _, <<"delivery">> := _}, Data),
{ok, _} = emqx_mgmt_api_test_util:request_api(get, Path, "", Auth), {ok, _} = emqx_mgmt_api_test_util:request_api(get, Path, "", Auth),