Skip to content

Simplify XMPP element metrics #4520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
36 changes: 20 additions & 16 deletions big_tests/tests/component_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,26 @@ register_one_component(Config) ->
CheckServer = fun(#{lserver := S}) -> S =:= ComponentAddr end,

%% Expect events for handshake, but not for 'start stream'.
instrument_helper:assert(xmpp_element_size_out, #{connection_type => component}, FullCheckF,
instrument_helper:assert(xmpp_element_out, ht_labels(), FullCheckF,
#{expected_count => 1, min_timestamp => TS}),
instrument_helper:assert(xmpp_element_size_in, #{connection_type => component}, FullCheckF,
instrument_helper:assert(xmpp_element_in, ht_labels(), FullCheckF,
#{expected_count => 1, min_timestamp => TS}),

instrument_helper:assert(component_auth_failed, #{}, FullCheckF,
#{expected_count => 0, min_timestamp => TS}),
instrument_helper:assert(tcp_data_in, #{connection_type => component}, CheckBytes,
instrument_helper:assert(tcp_data_in, labels(), CheckBytes,
#{min_timestamp => TS}),
instrument_helper:assert(tcp_data_out, #{connection_type => component}, CheckBytes,
instrument_helper:assert(tcp_data_out, labels(), CheckBytes,
#{min_timestamp => TS}),

TS1 = instrument_helper:timestamp(),
verify_component(Config, Component, ComponentAddr),

% Message from Alice
instrument_helper:assert(xmpp_element_size_out, #{connection_type => component}, FullCheckF,
instrument_helper:assert(xmpp_element_out, ht_labels(), FullCheckF,
#{expected_count => 1, min_timestamp => TS1}),
% Reply to Alice
instrument_helper:assert(xmpp_element_size_in, #{connection_type => component}, FullCheckF,
#{expected_count => 1, min_timestamp => TS1}),
instrument_helper:assert(component_element_in, #{}, CheckServer,
#{expected_count => 1, min_timestamp => TS1}),
instrument_helper:assert(component_element_out, #{}, CheckServer,
instrument_helper:assert(xmpp_element_in, ht_labels(), FullCheckF,
#{expected_count => 1, min_timestamp => TS1}),

component_helper:disconnect_component(Component, ComponentAddr).
Expand All @@ -151,9 +147,9 @@ register_one_component_tls(Config) ->
end,
CheckBytes = fun(#{byte_size := S}) -> S > 0 end,
CheckServer = fun(#{lserver := S}) -> S =:= ComponentAddr end,
instrument_helper:assert(tls_data_in, #{connection_type => component}, CheckBytes,
instrument_helper:assert(tls_data_in, labels(), CheckBytes,
#{min_timestamp => TS}),
instrument_helper:assert(tls_data_out, #{connection_type => component}, CheckBytes,
instrument_helper:assert(tls_data_out, labels(), CheckBytes,
#{min_timestamp => TS}),

TS1 = instrument_helper:timestamp(),
Expand Down Expand Up @@ -187,9 +183,9 @@ intercomponent_communication(Config) ->
FullCheckF = fun(#{byte_size := S, lserver := LServer}) ->
S > 0 andalso LServer =:= CompAddr1 orelse LServer =:= CompAddr2
end,
instrument_helper:assert(xmpp_element_size_out, #{connection_type => component}, FullCheckF,
instrument_helper:assert(xmpp_element_out, ht_labels(), FullCheckF,
#{expected_count => 1, min_timestamp => TS}),
instrument_helper:assert(xmpp_element_size_in, #{connection_type => component}, FullCheckF,
instrument_helper:assert(xmpp_element_in, ht_labels(), FullCheckF,
#{expected_count => 1, min_timestamp => TS}),

component_helper:disconnect_component(Comp1, CompAddr1),
Expand Down Expand Up @@ -241,10 +237,10 @@ register_two_components(Config) ->
S > 0 andalso LServer =:= CompAddr1 orelse LServer =:= CompAddr2
end,
% Msg to Alice, msg to Bob
instrument_helper:assert(xmpp_element_size_in, #{connection_type => component}, FullCheckF,
instrument_helper:assert(xmpp_element_in, ht_labels(), FullCheckF,
#{expected_count => 2, min_timestamp => TS}),
% Msg from Bob, msg from Alice
instrument_helper:assert(xmpp_element_size_out, #{connection_type => component}, FullCheckF,
instrument_helper:assert(xmpp_element_out, ht_labels(), FullCheckF,
#{expected_count => 2, min_timestamp => TS}),

component_helper:disconnect_component(Comp1, CompAddr1),
Expand Down Expand Up @@ -591,6 +587,14 @@ restore_domain(Config) ->
events() ->
instrument_helper:declared_events(mongoose_component_listener, [#{}]).

%% Data metrics have only the connection_type label
labels() ->
#{connection_type => component}.

%% XMPP element metric labels include host_type, but components don't have host types
ht_labels() ->
(labels())#{host_type => <<>>}.

%%--------------------------------------------------------------------
%% Stanzas
%%--------------------------------------------------------------------
Expand Down
29 changes: 15 additions & 14 deletions big_tests/tests/graphql_metric_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ get_all_metrics_as_dicts(Config) ->
check_node_result_is_valid(ParsedResult, false).

get_by_name_metrics_as_dicts(Config) ->
Name = [<<"c2s_element_in">>, <<"stanza_count">>],
Name = [<<"xmpp_element_in">>, <<"c2s">>, <<"stanza_count">>],
Result = get_metrics_as_dicts_by_name([<<"_">> | Name], Config),
ParsedResult = get_ok_value([data, metric, getMetricsAsDicts], Result),
[_|_] = ParsedResult,
%% Only c2s_element_in type
%% Only xmpp_element_in type
lists:foreach(fun(#{<<"dict">> := Dict, <<"name">> := [_ | N]}) when N =:= Name ->
check_spiral_dict(Dict)
end, ParsedResult).
Expand All @@ -227,23 +227,23 @@ get_metrics_as_dicts_with_key_one(Config) ->
Result = get_metrics_as_dicts_with_keys([<<"one">>], Config),
ParsedResult = get_ok_value([data, metric, getMetricsAsDicts], Result),
Map = dict_objects_to_map(ParsedResult),
SentName = [metric_host_type(), <<"c2s_element_out">>, <<"stanza_count">>],
SentName = [metric_host_type(), <<"xmpp_element_out">>, <<"c2s">>, <<"stanza_count">>],
[#{<<"key">> := <<"one">>, <<"value">> := One}] = maps:get(SentName, Map),
?assert(is_integer(One)).

get_metrics_as_dicts_with_nonexistent_key(Config) ->
Result = get_metrics_as_dicts_with_keys([<<"not_existing">>], Config),
ParsedResult = get_ok_value([data, metric, getMetricsAsDicts], Result),
Map = dict_objects_to_map(ParsedResult),
RecvName = [<<"global">>, <<"xmpp_element_size_in">>, <<"c2s">>, <<"byte_size">>],
RecvName = [metric_host_type(), <<"xmpp_element_in">>, <<"c2s">>, <<"byte_size">>],
[] = maps:get(RecvName, Map).

get_metrics_as_dicts_empty_args(Config) ->
%% Empty name
Result = get_metrics_as_dicts([], [<<"median">>], Config),
ParsedResult = get_ok_value([data, metric, getMetricsAsDicts], Result),
Map = dict_objects_to_map(ParsedResult),
RecvName = [<<"global">>, <<"xmpp_element_size_in">>, <<"c2s">>, <<"byte_size">>],
RecvName = [metric_host_type(), <<"xmpp_element_in">>, <<"c2s">>, <<"byte_size">>],
[#{<<"key">> := <<"median">>, <<"value">> := Median}] = maps:get(RecvName, Map),
?assert(is_integer(Median)),
%% Empty keys
Expand Down Expand Up @@ -272,13 +272,13 @@ get_cluster_metrics(Config) ->
check_node_result_is_valid(Res2, true).

get_by_name_cluster_metrics_as_dicts(Config) ->
Name = [<<"c2s_element_in">>, <<"stanza_count">>],
Name = [<<"xmpp_element_in">>, <<"c2s">>, <<"stanza_count">>],
Result = get_cluster_metrics_as_dicts_by_name([<<"_">> | Name], Config),
NodeResult = get_ok_value([data, metric, getClusterMetricsAsDicts], Result),
Map = node_objects_to_map(NodeResult),
%% Contains data for at least two nodes
?assert(maps:size(Map) > 1),
%% Only c2s_element_in type
%% Only xmpp_element_in type
maps:map(fun(_Node, [_|_] = NodeRes) ->
lists:foreach(fun(#{<<"dict">> := Dict, <<"name">> := [_ | N]}) when N =:= Name ->
check_spiral_dict(Dict)
Expand Down Expand Up @@ -317,7 +317,7 @@ get_cluster_metrics_empty_args(Config) ->
ParsedResult = get_ok_value([data, metric, getClusterMetricsAsDicts], Result),
[#{<<"node">> := Node, <<"result">> := ResList}] = ParsedResult,
Map = dict_objects_to_map(ResList),
SentName = [<<"global">>, <<"c2s_element_in">>, <<"stanza_count">>],
SentName = [<<"global">>, <<"xmpp_element_in">>, <<"c2s">>, <<"stanza_count">>],
[#{<<"key">> := <<"one">>, <<"value">> := One}] = maps:get(SentName, Map),
?assert(is_integer(One)),
%% Empty keys
Expand Down Expand Up @@ -351,15 +351,16 @@ get_cluster_metrics_empty_strings(Config) ->
check_node_result_is_valid(ResList, MetricsAreGlobal) ->
%% Check that result contains something
Map = dict_objects_to_map(ResList),
SentName = case MetricsAreGlobal of
true -> [<<"global">>, <<"c2s_element_in">>, <<"stanza_count">>];
false -> [metric_host_type(), <<"c2s_element_in">>, <<"stanza_count">>]
end,
Prefix = case MetricsAreGlobal of
true -> <<"global">>;
false -> metric_host_type()
end,
SentName = [Prefix, <<"xmpp_element_in">>, <<"c2s">>, <<"stanza_count">>],
check_spiral_dict(maps:get(SentName, Map)),
[#{<<"key">> := <<"value">>,<<"value">> := V} | _] =
maps:get([<<"global">>,<<"sm_unique_sessions">>,<<"count">>], Map),
maps:get([<<"global">>, <<"sm_unique_sessions">>, <<"count">>], Map),
?assert(is_integer(V)),
HistObjects = maps:get([<<"global">>, <<"xmpp_element_size_in">>, <<"c2s">>, <<"byte_size">>], Map),
HistObjects = maps:get([Prefix, <<"xmpp_element_in">>, <<"c2s">>, <<"byte_size">>], Map),
check_histogram(kv_objects_to_map(HistObjects)).

check_histogram(Map) ->
Expand Down
82 changes: 41 additions & 41 deletions big_tests/tests/metrics_api_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ non_existent_metrics(_Config) ->
assert_status(404, request(<<"GET">>, "/metrics/global/badMetric")),
assert_status(404, request(<<"GET">>, "/metrics/host_type/badHostType")),
assert_status(404, request(<<"GET">>,
"/metrics/host_type/badHostType/c2s_element_out.stanza_count")),
"/metrics/host_type/badHostType/xmpp_element_out.c2s.stanza_count")),
assert_status(404, request(<<"GET">>, ["/metrics/", HostType, "/", GlobalMetricName])),
assert_status(404, request(<<"GET">>, ["/metrics/", HostType, "/badMetric"])).

Expand All @@ -122,14 +122,14 @@ one_client_just_logs_in(Config) ->
(Config, metrics_helper:userspec(1, Config),
fun(_User1) -> end_of_story end,
%% A list of metrics and their expected relative increase
[{'c2s_element_in.iq_count', 0 + user_alpha(2)},
{'c2s_element_out.iq_count', 0 + user_alpha(2)},
{'c2s_element_in.message_count', 0},
{'c2s_element_out.message_count', 0},
{'c2s_element_in.presence_count', 0 + user_alpha(1)},
{'c2s_element_out.presence_count', 0 + user_alpha(1)},
{'c2s_element_in.stanza_count', 0 + user_alpha(3)},
{'c2s_element_out.stanza_count', 0 + user_alpha(3)},
[{'xmpp_element_in.c2s.iq_count', 0 + user_alpha(2)},
{'xmpp_element_out.c2s.iq_count', 0 + user_alpha(2)},
{'xmpp_element_in.c2s.message_count', 0},
{'xmpp_element_out.c2s.message_count', 0},
{'xmpp_element_in.c2s.presence_count', 0 + user_alpha(1)},
{'xmpp_element_out.c2s.presence_count', 0 + user_alpha(1)},
{'xmpp_element_in.c2s.stanza_count', 0 + user_alpha(3)},
{'xmpp_element_out.c2s.stanza_count', 0 + user_alpha(3)},
{'sm_session.logins', 0 + user_alpha(1)},
{'sm_session.logouts', 0 + user_alpha(1)}
]).
Expand All @@ -138,14 +138,14 @@ two_clients_just_log_in(Config) ->
instrumented_story
(Config, metrics_helper:userspec(1, 1, Config),
fun(_User1, _User2) -> end_of_story end,
[{'c2s_element_in.iq_count', 0 + user_alpha(4)},
{'c2s_element_out.iq_count', 0 + user_alpha(4)},
{'c2s_element_in.message_count', 0},
{'c2s_element_out.message_count', 0},
{'c2s_element_in.presence_count', 0 + user_alpha(2)},
{'c2s_element_out.presence_count', 0 + user_alpha(2)},
{'c2s_element_in.stanza_count', 0 + user_alpha(6)},
{'c2s_element_out.stanza_count', 0 + user_alpha(6)},
[{'xmpp_element_in.c2s.iq_count', 0 + user_alpha(4)},
{'xmpp_element_out.c2s.iq_count', 0 + user_alpha(4)},
{'xmpp_element_in.c2s.message_count', 0},
{'xmpp_element_out.c2s.message_count', 0},
{'xmpp_element_in.c2s.presence_count', 0 + user_alpha(2)},
{'xmpp_element_out.c2s.presence_count', 0 + user_alpha(2)},
{'xmpp_element_in.c2s.stanza_count', 0 + user_alpha(6)},
{'xmpp_element_out.c2s.stanza_count', 0 + user_alpha(6)},
{'sm_session.logins', 0 + user_alpha(2)},
{'sm_session.logouts', 0 + user_alpha(2)}
]).
Expand All @@ -158,8 +158,8 @@ one_message_sent(Config) ->
escalus_client:send(User1, Chat),
escalus_client:wait_for_stanza(User2)
end,
[{'c2s_element_in.message_count', 1},
{'c2s_element_out.message_count', 1}]).
[{'xmpp_element_in.c2s.message_count', 1},
{'xmpp_element_out.c2s.message_count', 1}]).

one_direct_presence_sent(Config) ->
Userspec = metrics_helper:userspec(1, 1, Config),
Expand All @@ -170,10 +170,10 @@ one_direct_presence_sent(Config) ->
escalus:send(User1, Presence),
escalus:wait_for_stanza(User2)
end,
[{'c2s_element_in.presence_count', 1 + user_alpha(2)},
{'c2s_element_out.presence_count', 1 + user_alpha(2)},
{'c2s_element_in.stanza_count', 1 + user_alpha(6)},
{'c2s_element_out.stanza_count', 1 + user_alpha(6)}]).
[{'xmpp_element_in.c2s.presence_count', 1 + user_alpha(2)},
{'xmpp_element_out.c2s.presence_count', 1 + user_alpha(2)},
{'xmpp_element_in.c2s.stanza_count', 1 + user_alpha(6)},
{'xmpp_element_out.c2s.stanza_count', 1 + user_alpha(6)}]).

one_iq_sent(Config) ->
instrumented_story
Expand All @@ -183,11 +183,11 @@ one_iq_sent(Config) ->
escalus_client:send(User1, RosterIq),
escalus_client:wait_for_stanza(User1)
end,
[{'c2s_element_in.iq_count', 3},
{'c2s_element_out.iq_count', 3},
[{'xmpp_element_in.c2s.iq_count', 3},
{'xmpp_element_out.c2s.iq_count', 3},
{'mod_roster_get.count', 1},
{'c2s_element_in.stanza_count', 1 + user_alpha(3)},
{'c2s_element_out.stanza_count', 1 + user_alpha(3)}]).
{'xmpp_element_in.c2s.stanza_count', 1 + user_alpha(3)},
{'xmpp_element_out.c2s.stanza_count', 1 + user_alpha(3)}]).

one_message_error(Config) ->
instrumented_story
Expand All @@ -198,10 +198,10 @@ one_message_error(Config) ->
escalus_client:send(User1, Chat),
escalus_client:wait_for_stanza(User1)
end,
[{'c2s_element_out.error_count', 1},
{'c2s_element_out.iq_error_count', 0},
{'c2s_element_out.message_error_count', 1},
{'c2s_element_out.presence_error_count', 0}]).
[{'xmpp_element_out.c2s.error_count', 1},
{'xmpp_element_out.c2s.iq_error_count', 0},
{'xmpp_element_out.c2s.message_error_count', 1},
{'xmpp_element_out.c2s.presence_error_count', 0}]).

one_iq_error(Config) ->
instrumented_story
Expand All @@ -211,10 +211,10 @@ one_iq_error(Config) ->
escalus_client:send(User1, BadIQ),
escalus_client:wait_for_stanza(User1)
end,
[{'c2s_element_out.error_count', 1},
{'c2s_element_out.iq_error_count', 1},
{'c2s_element_out.message_error_count', 0},
{'c2s_element_out.presence_error_count', 0}]).
[{'xmpp_element_out.c2s.error_count', 1},
{'xmpp_element_out.c2s.iq_error_count', 1},
{'xmpp_element_out.c2s.message_error_count', 0},
{'xmpp_element_out.c2s.presence_error_count', 0}]).

one_presence_error(Config) ->
instrumented_story
Expand All @@ -225,10 +225,10 @@ one_presence_error(Config) ->
escalus_client:send(User1, BadPres),
escalus_client:wait_for_stanza(User1)
end,
[{'c2s_element_out.error_count', 1},
{'c2s_element_out.iq_error_count', 0},
{'c2s_element_out.message_error_count', 0},
{'c2s_element_out.presence_error_count', 1}]).
[{'xmpp_element_out.c2s.error_count', 1},
{'xmpp_element_out.c2s.iq_error_count', 0},
{'xmpp_element_out.c2s.message_error_count', 0},
{'xmpp_element_out.c2s.presence_error_count', 1}]).

session_counters(Config) ->
escalus:story
Expand Down Expand Up @@ -344,9 +344,9 @@ metrics_msg_flow(_Config) ->
user_alpha(NumberOfUsers) ->
%% This represents the overhead of logging in N users via escalus:story/3
%% For each user,
%% c2s_element_(in|out).stanza_count
%% xmpp_element_(in|out).c2s.stanza_count
%% and
%% c2s_element_(in|out).presence_count
%% xmpp_element_(in|out).c2s.presence_count
%% will be bumped by +1 at login.
NumberOfUsers.

Expand Down
Loading