Skip to content
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

Add service_mongoose_system_metrics_SUITE to dynamic_domains #3281

Merged
merged 3 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions big_tests/dynamic_domains.spec
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@

{suites, "tests", service_domain_db_SUITE}.

{suites, "tests", service_mongoose_system_metrics_SUITE}.
{skip_cases, "tests", service_mongoose_system_metrics_SUITE,
[xmpp_components_are_reported],
"at the moment external components doesn't support dynamic domains"}.

{suites, "tests", sic_SUITE}.

{suites, "tests", sm_SUITE}.
Expand Down
88 changes: 45 additions & 43 deletions big_tests/tests/service_mongoose_system_metrics_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
spec/2,
common/1]).

-import(domain_helper, [host_type/0]).

suite() ->
require_rpc_nodes([mim]).

Expand Down Expand Up @@ -288,13 +290,15 @@ outgoing_pools_are_reported(_Config) ->

xmpp_stanzas_counts_are_reported(Config) ->
escalus:story(Config, [{alice,1}, {bob,1}], fun(Alice, Bob) ->
escalus:send(Alice, escalus_stanza:chat_to(Bob, <<"COVID-19">>)),
escalus:assert(is_chat_message, [<<"COVID-19">>],
escalus:wait_for_stanza(Bob))

end),
mongoose_helper:wait_until(fun xmpp_messages_count_is_reported/0, true),
mongoose_helper:wait_until(fun xmpp_stanzas_counts_are_reported/0, true).
mongoose_helper:wait_until(fun message_count_is_reported/0, true),
mongoose_helper:wait_until(fun iq_count_is_reported/0, true),
Sent = get_metric_value(<<"xmppMessageSent">>),
Received = get_metric_value(<<"xmppMessageReceived">>),
escalus:send(Alice, escalus_stanza:chat_to(Bob, <<"Hi">>)),
escalus:assert(is_chat_message, [<<"Hi">>], escalus:wait_for_stanza(Bob)),
F = fun() -> assert_message_count_is_incremented(Sent, Received) end,
mongoose_helper:wait_until(F, ok)
end).

config_type_is_reported(_Config) ->
mongoose_helper:wait_until(fun config_type_is_reported/0, true).
Expand Down Expand Up @@ -356,31 +360,22 @@ in_config_with_explicit_reporting_goes_on_silently(_Config) ->

all_event_have_the_same_client_id() ->
Tab = ets:tab2list(?ETS_TABLE),
UniqueSortedTab = lists:usort([Cid ||#event{cid = Cid} <- Tab]),
UniqueSortedTab = lists:usort([Cid || #event{cid = Cid} <- Tab]),
1 = length(UniqueSortedTab).

hosts_count_is_reported() ->
is_in_table(<<"hosts">>).

hosts_count_is_not_reported() ->
is_not_in_table(<<"hosts">>).

modules_are_reported() ->
is_in_table(<<"module">>).

modules_are_not_reported() ->
is_not_in_table(<<"module">>).

is_in_table(EventCategory) ->
Tab = ets:tab2list(?ETS_TABLE),
lists:any(
fun(#event{ec = EC}) ->
verify_category(EC, EventCategory)
end, Tab).

is_not_in_table(EventCategory) ->
not is_in_table(EventCategory).

verify_category(EC, <<"module">>) ->
Result = re:run(EC, "^mod_.*"),
case Result of
Expand All @@ -393,7 +388,7 @@ verify_category(_EC, _EventCategory) ->
false.

get_events_collection_size() ->
length(ets:tab2list(?ETS_TABLE)).
ets:info(?ETS_TABLE, size).

enable_system_metrics(Node) ->
enable_system_metrics(Node, [{initial_report, 100}, {periodic_report, 100}]).
Expand Down Expand Up @@ -446,7 +441,7 @@ remove_service_from_config(Service) ->

events_are_reported_to_additional_tracking_id() ->
Tab = ets:tab2list(?ETS_TABLE),
SetTab = sets:from_list([Tid ||#event{tid = Tid} <- Tab]),
SetTab = sets:from_list([Tid || #event{tid = Tid} <- Tab]),
2 >= sets:size(SetTab).

events_are_reported_to_configurable_tracking_id() ->
Expand All @@ -458,23 +453,14 @@ events_are_reported_to_configurable_tracking_id() ->
end, Tab).

maybe_start_module(Module) ->
Host = <<"localhost">>,
Options = [],
distributed_helper:rpc(mim(), gen_mod, start_module, [Host, Module, Options]).
distributed_helper:rpc(mim(), gen_mod, start_module, [host_type(), Module, Options]).

feature_is_reported(EventCategory, EventAction) ->
Tab = ets:tab2list(?ETS_TABLE),
lists:any(
fun(#event{ec = EC, ea = EA}) ->
EC == EventCategory andalso EA == EventAction
end, Tab).
length(match_events(EventCategory, EventAction)) > 0.

feature_is_reported(EventCategory, EventAction, EventLabel) ->
Tab = ets:tab2list(?ETS_TABLE),
lists:any(
fun(#event{ec = EC, ea = EA, el = EL}) ->
EC == EventCategory andalso EA == EventAction andalso EL == EventLabel
end, Tab).
length(match_events(EventCategory, EventAction, EventLabel)) > 0.

mod_vcard_backend_is_reported() ->
feature_is_reported(<<"mod_vcard">>, <<"backend">>).
Expand Down Expand Up @@ -502,22 +488,38 @@ transport_mechanisms_are_reported() ->
outgoing_pools_are_reported() ->
is_in_table(<<"outgoing_pools">>).

xmpp_stanzas_counts_are_reported() ->
iq_count_is_reported() ->
is_in_table(<<"xmppIqSent">>).

xmpp_messages_count_is_reported() ->
BoolMessageSent = feature_is_reported(<<"xmppMessageSent">>, <<"1">>),
BoolMessageReceived = feature_is_reported(<<"xmppMessageReceived">>, <<"1">>),
BoolMessageSent and BoolMessageReceived.
message_count_is_reported() ->
is_in_table(<<"xmppMessageSent">>) andalso is_in_table(<<"xmppMessageReceived">>).

assert_message_count_is_incremented(Sent, Received) ->
assert_increment(<<"xmppMessageSent">>, Sent),
assert_increment(<<"xmppMessageReceived">>, Received).

assert_increment(EventCategory, InitialValue) ->
Events = match_events(EventCategory, integer_to_binary(InitialValue + 1), <<$1>>),
?assertMatch([_], Events). % expect exactly one event with an increment of 1

get_metric_value(EventCategory) ->
[#event{ea = Value} | _] = match_events(EventCategory),
binary_to_integer(Value).

more_than_one_component_is_reported() ->
Tab = ets:tab2list(?ETS_TABLE),
EventCategory = <<"cluster">>,
EventAction = <<"number_of_components">>,
lists:any(
fun(#event{ec = EC, ea = EA, el = EL}) ->
EC == EventCategory andalso EA == EventAction andalso EL > <<"0">>
end, Tab).
Events = match_events(<<"cluster">>, <<"number_of_components">>),
lists:any(fun(#event{el = EL}) ->
binary_to_integer(EL) > 0
end, Events).

match_events(EC) ->
ets:match_object(?ETS_TABLE, #event{ec = EC, _ = '_'}).

match_events(EC, EA) ->
ets:match_object(?ETS_TABLE, #event{ec = EC, ea = EA, _ = '_'}).

match_events(EC, EA, EL) ->
ets:match_object(?ETS_TABLE, #event{ec = EC, ea = EA, el = EL, _ = '_'}).

%%--------------------------------------------------------------------
%% Cowboy handlers
Expand Down