Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed Jun 13, 2022
1 parent 6cdf682 commit 27190b8
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 27 deletions.
1 change: 0 additions & 1 deletion big_tests/dynamic_domains.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{hosts, [{mim, [{node, mongooseim@localhost},
{domain, <<"domain.example.com">>},
{host_type, <<"test type">>},
{metric_host_type, <<"test_type">>},
{secondary_domain, <<"domain.example.org">>},
{secondary_host_type, <<"test type">>},
{dynamic_domains, [{<<"test type">>, [<<"domain.example.com">>, <<"domain.example.org">>]},
Expand Down
1 change: 0 additions & 1 deletion big_tests/test.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
{hosts, [{mim, [{node, mongooseim@localhost},
{domain, <<"localhost">>},
{host_type, <<"localhost">>},
{metric_host_type, <<"localhost">>},
{vars, "mim1"},
{cluster, mim},
{secondary_domain, <<"localhost.bis">>},
Expand Down
4 changes: 0 additions & 4 deletions big_tests/tests/domain_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
host_types/1,
host_type/0,
host_type/1,
metric_host_type/0,
domain_to_host_type/2,
domain/0,
domain/1,
Expand All @@ -35,9 +34,6 @@ domain() ->
host_type(NodeKey) ->
get_or_fail({hosts, NodeKey, host_type}).

metric_host_type() ->
get_or_fail({hosts, mim, metric_host_type}).

domain_to_host_type(Node, Domain) ->
{ok, HostType} = rpc(Node, mongoose_domain_core, get_host_type, [Domain]),
HostType.
Expand Down
12 changes: 8 additions & 4 deletions big_tests/tests/graphql_metric_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ get_by_name_global_erlang_metrics(Config) ->
variables => #{}, operationName => <<"Q1">>}, Config),
ParsedResult = ok_result(<<"metric">>, <<"getMetrics">>, Result),
Map = maps:from_list([{Name, X} || X = #{<<"name">> := Name} <- ParsedResult]),
Info = maps:get([<<"global">>,<<"erlang">>, <<"system_info">>], Map),
Info = maps:get([<<"global">>, <<"erlang">>, <<"system_info">>], Map),
%% VMSystemInfoMetric type
#{<<"type">> := <<"vm_system_info">>} = Info,
check_metric_by_type(Info),
Expand Down Expand Up @@ -152,6 +152,7 @@ get_by_name_metrics_as_dicts(Config) ->
Result = execute_auth(#{query => get_by_args_metrics_as_dicts_call(Args),
variables => #{}, operationName => <<"Q1">>}, Config),
ParsedResult = ok_result(<<"metric">>, <<"getMetricsAsDicts">>, Result),
[_|_] = ParsedResult,
%% Only xmppStanzaSent type
lists:foreach(fun(#{<<"dict">> := Dict, <<"name">> := [_, <<"xmppStanzaSent">>]}) ->
check_spiral_dict(Dict)
Expand All @@ -163,7 +164,7 @@ get_metrics_as_dicts_with_key_one(Config) ->
operationName => <<"Q1">>}, Config),
ParsedResult = ok_result(<<"metric">>, <<"getMetricsAsDicts">>, Result),
Map = dict_objects_to_map(ParsedResult),
SentName = [domain_helper:metric_host_type(), <<"xmppStanzaSent">>],
SentName = [metric_host_type(), <<"xmppStanzaSent">>],
[#{<<"key">> := <<"one">>, <<"value">> := One}] = maps:get(SentName, Map),
true = is_integer(One).

Expand All @@ -188,7 +189,7 @@ get_by_name_cluster_metrics_as_dicts(Config) ->
%% Contains data for at least two nodes
true = maps:size(Map) > 1,
%% Only xmppStanzaSent type
maps:map(fun(_Node, NodeRes) ->
maps:map(fun(_Node, [_|_] = NodeRes) ->
lists:foreach(fun(#{<<"dict">> := Dict,
<<"name">> := [_, <<"xmppStanzaSent">>]}) ->
check_spiral_dict(Dict)
Expand All @@ -208,7 +209,7 @@ check_node_result_is_valid(ResList, MetricsAreGlobal) ->
Map = dict_objects_to_map(ResList),
SentName = case MetricsAreGlobal of
true -> [<<"global">>, <<"xmppStanzaSent">>];
false -> [domain_helper:metric_host_type(), <<"xmppStanzaSent">>]
false -> [metric_host_type(), <<"xmppStanzaSent">>]
end,
check_spiral_dict(maps:get(SentName, Map)),
[#{<<"key">> := <<"value">>,<<"value">> := V}] =
Expand Down Expand Up @@ -310,3 +311,6 @@ check_spiral_dict(Dict) ->

values_are_integers(Map, Keys) ->
lists:foreach(fun(Key) -> true = is_integer(maps:get(Key, Map)) end, Keys).

metric_host_type() ->
binary:replace(domain_helper:host_type(), <<" ">>, <<"_">>, [global]).
4 changes: 2 additions & 2 deletions big_tests/tests/mam_helper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,9 @@ send_muc_rsm_messages(Config) ->
escalus:wait_for_stanzas(Alice, 3),

%% Alice sends messages to Bob.
lists:foreach(fun(N) ->
lists:foreach(fun(NN) ->
escalus:send(Alice, escalus_stanza:groupchat_to(
RoomAddr, generate_message_text(N)))
RoomAddr, generate_message_text(NN)))
end, lists:seq(1, N)),
assert_list_size(N, escalus:wait_for_stanzas(Bob, N)),
assert_list_size(N, escalus:wait_for_stanzas(Alice, N)),
Expand Down
1 change: 1 addition & 0 deletions priv/graphql/schemas/admin/metric.gql
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type HistogramMetric {
min: Int
"Max value"
max: Int
"Median value"
median: Int
"50th percentile"
p50: Int
Expand Down
11 changes: 2 additions & 9 deletions src/graphql/admin/mongoose_graphql_metric_admin_query.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,7 @@ prepare_key(X) when is_integer(X) -> %% For percentiles

prepare_name(null) ->
[];
prepare_name([<<"global">> | T]) ->
[global | prepare_name2(T)];
prepare_name([H | T]) ->
[binary_to_atom(H) | prepare_name2(T)];
prepare_name([]) ->
[].

prepare_name2(Segments) ->
prepare_name(Segments) ->
lists:map(fun binary_to_atom/1, Segments).

make_metric_result({Name, Dict}) ->
Expand Down Expand Up @@ -164,7 +157,7 @@ format_merged_inet_stats(#{connections := Cons,
<<"send_pend">> => SPend}.

format_rdbms_stats(#{recv_cnt := RCnt, recv_max := RMax, recv_oct := ROct,
send_cnt := SCnt,send_max := SMax, send_oct := SOct,
send_cnt := SCnt, send_max := SMax, send_oct := SOct,
send_pend := SPend, workers := Workers}) ->
#{<<"type">> => <<"rdbms_stats">>, <<"workers">> => Workers,
<<"recv_cnt">> => RCnt, <<"recv_max">> => RMax, <<"recv_oct">> => ROct,
Expand Down
7 changes: 1 addition & 6 deletions src/graphql/mongoose_graphql_union.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@ execute(#{<<"type">> := <<"gauge">>, <<"name">> := _, <<"value">> := _}) ->
{ok, <<"GaugeMetric">>};
execute(#{<<"type">> := <<"merged_inet_stats">>, <<"connections">> := _}) ->
{ok, <<"MergedInetStatsMetric">>};
execute(#{<<"type">> := <<"merged_inet_stats">>, <<"connections">> := _}) ->
{ok, <<"MergedInetStatsMetric">>};
execute(#{<<"type">> := <<"vm_stats_memory">>, <<"processes_used">> := _}) ->
{ok, <<"VMStatsMemoryMetric">>};
execute(#{<<"type">> := <<"vm_system_info">>, <<"port_count">> := _}) ->
{ok, <<"VMSystemInfoMetric">>};
execute(#{<<"type">> := <<"probe_queues">>, <<"fsm">> := _}) ->
{ok, <<"ProbeQueuesMetric">>};
execute(#{<<"type">> := <<"rdbms_stats">>, <<"workers">> := _}) ->
{ok, <<"RDBMSStatsMetric">>};
execute(Value) ->
?LOG_ERROR(#{what => graphql_unknown_type, value => Value}),
{error, unknown_type}.
{ok, <<"RDBMSStatsMetric">>}.

0 comments on commit 27190b8

Please sign in to comment.