Skip to content

Commit 7da5aab

Browse files
committed
WIP2
1 parent 262ddac commit 7da5aab

File tree

5 files changed

+41
-31
lines changed

5 files changed

+41
-31
lines changed

Diff for: big_tests/tests/component_SUITE.erl

+20-12
Original file line numberDiff line numberDiff line change
@@ -113,26 +113,26 @@ register_one_component(Config) ->
113113
CheckServer = fun(#{lserver := S}) -> S =:= ComponentAddr end,
114114

115115
%% Expect events for handshake, but not for 'start stream'.
116-
instrument_helper:assert(xmpp_element_out, #{connection_type => component}, FullCheckF,
116+
instrument_helper:assert(xmpp_element_out, ht_labels(), FullCheckF,
117117
#{expected_count => 1, min_timestamp => TS}),
118-
instrument_helper:assert(xmpp_element_in, #{connection_type => component}, FullCheckF,
118+
instrument_helper:assert(xmpp_element_in, ht_labels(), FullCheckF,
119119
#{expected_count => 1, min_timestamp => TS}),
120120

121121
instrument_helper:assert(component_auth_failed, #{}, FullCheckF,
122122
#{expected_count => 0, min_timestamp => TS}),
123-
instrument_helper:assert(tcp_data_in, #{connection_type => component}, CheckBytes,
123+
instrument_helper:assert(tcp_data_in, labels(), CheckBytes,
124124
#{min_timestamp => TS}),
125-
instrument_helper:assert(tcp_data_out, #{connection_type => component}, CheckBytes,
125+
instrument_helper:assert(tcp_data_out, labels(), CheckBytes,
126126
#{min_timestamp => TS}),
127127

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

131131
% Message from Alice
132-
instrument_helper:assert(xmpp_element_out, #{connection_type => component}, FullCheckF,
132+
instrument_helper:assert(xmpp_element_out, ht_labels(), FullCheckF,
133133
#{expected_count => 1, min_timestamp => TS1}),
134134
% Reply to Alice
135-
instrument_helper:assert(xmpp_element_in, #{connection_type => component}, FullCheckF,
135+
instrument_helper:assert(xmpp_element_in, ht_labels(), FullCheckF,
136136
#{expected_count => 1, min_timestamp => TS1}),
137137

138138
component_helper:disconnect_component(Component, ComponentAddr).
@@ -147,9 +147,9 @@ register_one_component_tls(Config) ->
147147
end,
148148
CheckBytes = fun(#{byte_size := S}) -> S > 0 end,
149149
CheckServer = fun(#{lserver := S}) -> S =:= ComponentAddr end,
150-
instrument_helper:assert(tls_data_in, #{connection_type => component}, CheckBytes,
150+
instrument_helper:assert(tls_data_in, labels(), CheckBytes,
151151
#{min_timestamp => TS}),
152-
instrument_helper:assert(tls_data_out, #{connection_type => component}, CheckBytes,
152+
instrument_helper:assert(tls_data_out, labels(), CheckBytes,
153153
#{min_timestamp => TS}),
154154

155155
TS1 = instrument_helper:timestamp(),
@@ -183,9 +183,9 @@ intercomponent_communication(Config) ->
183183
FullCheckF = fun(#{byte_size := S, lserver := LServer}) ->
184184
S > 0 andalso LServer =:= CompAddr1 orelse LServer =:= CompAddr2
185185
end,
186-
instrument_helper:assert(xmpp_element_out, #{connection_type => component}, FullCheckF,
186+
instrument_helper:assert(xmpp_element_out, ht_labels(), FullCheckF,
187187
#{expected_count => 1, min_timestamp => TS}),
188-
instrument_helper:assert(xmpp_element_in, #{connection_type => component}, FullCheckF,
188+
instrument_helper:assert(xmpp_element_in, ht_labels(), FullCheckF,
189189
#{expected_count => 1, min_timestamp => TS}),
190190

191191
component_helper:disconnect_component(Comp1, CompAddr1),
@@ -237,10 +237,10 @@ register_two_components(Config) ->
237237
S > 0 andalso LServer =:= CompAddr1 orelse LServer =:= CompAddr2
238238
end,
239239
% Msg to Alice, msg to Bob
240-
instrument_helper:assert(xmpp_element_in, #{connection_type => component}, FullCheckF,
240+
instrument_helper:assert(xmpp_element_in, ht_labels(), FullCheckF,
241241
#{expected_count => 2, min_timestamp => TS}),
242242
% Msg from Bob, msg from Alice
243-
instrument_helper:assert(xmpp_element_out, #{connection_type => component}, FullCheckF,
243+
instrument_helper:assert(xmpp_element_out, ht_labels(), FullCheckF,
244244
#{expected_count => 2, min_timestamp => TS}),
245245

246246
component_helper:disconnect_component(Comp1, CompAddr1),
@@ -587,6 +587,14 @@ restore_domain(Config) ->
587587
events() ->
588588
instrument_helper:declared_events(mongoose_component_listener, [#{}]).
589589

590+
%% Data metrics have only the connection_type label
591+
labels() ->
592+
#{connection_type => component}.
593+
594+
%% XMPP element metric labels include host_type, but components don't have host types
595+
ht_labels() ->
596+
(labels())#{host_type => <<>>}.
597+
590598
%%--------------------------------------------------------------------
591599
%% Stanzas
592600
%%--------------------------------------------------------------------

Diff for: big_tests/tests/s2s_SUITE.erl

+10-10
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ suite() ->
108108
%%%===================================================================
109109

110110
init_per_suite(Config0) ->
111+
ct:pal("Tested events: ~p~n", [tested_events()]),
111112
instrument_helper:start(tested_events()),
112113
mongoose_helper:inject_module(?MODULE, reload),
113114
Config1 = escalus:init_per_suite(Config0),
@@ -590,7 +591,7 @@ shared_secret(mim2) -> <<"9e438f25e81cf347100b">>.
590591
assert_events(TS, Config) ->
591592
TLS = proplists:get_value(requires_tls, Config, false),
592593
{DataInEvent, DataOutEvent} = data_events(TLS),
593-
Labels = #{connection_type => s2s, host_type => host_type()},
594+
Labels = #{connection_type => s2s},
594595
Opts = #{min_timestamp => TS},
595596

596597
SizeFilter = fun(#{byte_size := S}) -> S > 0 end,
@@ -601,8 +602,9 @@ assert_events(TS, Config) ->
601602
MimDomain = domain_helper:domain(),
602603
DomainFilter = fun(#{lserver := LServer}) -> LServer =:= MimDomain end,
603604
CombinedFilter = fun(M) -> DomainFilter(M) andalso SizeFilter(M) end,
604-
instrument_helper:assert(xmpp_element_in, Labels, CombinedFilter, Opts2),
605-
instrument_helper:assert(xmpp_element_out, Labels, CombinedFilter, Opts2).
605+
Labels2 = Labels#{host_type => host_type()},
606+
instrument_helper:assert(xmpp_element_in, Labels2, CombinedFilter, Opts2),
607+
instrument_helper:assert(xmpp_element_out, Labels2, CombinedFilter, Opts2).
606608

607609
data_events(true) -> {tls_data_in, tls_data_out};
608610
data_events(false) -> {tcp_data_in, tcp_data_out}.
@@ -666,10 +668,8 @@ group_with_tls(node1_tls_optional_node2_tls_required_trusted_with_cachain) -> tr
666668
group_with_tls(_GN) -> false.
667669

668670
tested_events() ->
669-
[{xmpp_element_in, #{connection_type => s2s, host_type => host_type()}},
670-
{xmpp_element_out, #{connection_type => s2s, host_type => host_type()}},
671-
{tls_data_in, #{connection_type => s2s}},
672-
{tls_data_out, #{connection_type => s2s}},
673-
{tcp_data_in, #{connection_type => s2s}},
674-
{tcp_data_out, #{connection_type => s2s}},
675-
{s2s_auth_failed, #{}}].
671+
lists:filter(fun is_event_tested/1,
672+
instrument_helper:declared_events(mongoose_s2s_listener, [#{}])).
673+
674+
is_event_tested({_Event, #{host_type := HostType}}) -> HostType =:= host_type();
675+
is_event_tested({_Event, _Labels}) -> true.

Diff for: src/instrument/mongoose_instrument_xmpp.erl

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@ measure_element(_Name, _Type) ->
5252
element_instrumentation(ConnectionType) ->
5353
Config = #{metrics => element_metrics()},
5454
[{Event, element_labels(ConnectionType, HostType), Config}
55-
|| HostType <- [undefined | ?ALL_HOST_TYPES],
55+
|| HostType <- [undefined | host_types(ConnectionType)],
5656
Event <- [xmpp_element_in, xmpp_element_out]].
5757

58+
-spec host_types(connection_type()) -> [mongooseim:host_type()].
59+
host_types(component) -> []; % components don't belong to host types
60+
host_types(_) -> ?ALL_HOST_TYPES.
61+
5862
-spec data_instrumentation(connection_type()) -> [mongoose_instrument:spec()].
5963
data_instrumentation(ConnectionType) ->
6064
Config = #{metrics => #{byte_size => spiral}},

Diff for: src/s2s/mongoose_s2s_out.erl

-2
Original file line numberDiff line numberDiff line change
@@ -593,5 +593,3 @@ starttls() ->
593593
execute_element_event(Element, #s2s_data{host_type = HostType, myname = LServer}, EventName) ->
594594
Metadata = #{lserver => LServer, pid => self(), module => ?MODULE},
595595
mongoose_instrument_xmpp:execute_element_event(EventName, s2s, HostType, Element, Metadata).
596-
597-

Diff for: src/system_metrics/mongoose_system_metrics_collector.erl

+6-6
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ count_stanzas(StanzaType) ->
198198
0, ExometerResults),
199199
{StanzaType, StanzaCount}.
200200

201-
metric_name(xmppMessageSent) -> [c2s_element_in, message_count];
202-
metric_name(xmppIqSent) -> [c2s_element_in, iq_count];
203-
metric_name(xmppPresenceSent) -> [c2s_element_in, presence_count];
204-
metric_name(xmppMessageReceived) -> [c2s_element_out, message_count];
205-
metric_name(xmppIqReceived) -> [c2s_element_out, iq_count];
206-
metric_name(xmppPresenceReceived) -> [c2s_element_out, presence_count].
201+
metric_name(xmppMessageSent) -> [xmpp_element_in, '_', message_count];
202+
metric_name(xmppIqSent) -> [xmpp_element_in, '_', iq_count];
203+
metric_name(xmppPresenceSent) -> [xmpp_element_in, '_', presence_count];
204+
metric_name(xmppMessageReceived) -> [xmpp_element_out, '_', message_count];
205+
metric_name(xmppIqReceived) -> [xmpp_element_out, '_', iq_count];
206+
metric_name(xmppPresenceReceived) -> [xmpp_element_out, '_', presence_count].
207207

208208
calculate_stanza_rate([], NewCount) ->
209209
[{Type, Count, Count} || {Type, Count} <- NewCount];

0 commit comments

Comments
 (0)