Skip to content

Commit 84d7d06

Browse files
committed
Update exometer metric tests using c2s metrics
There are new metric names, and they are global now. API tests needed changes to support global and host-type metrics.
1 parent 0c7c676 commit 84d7d06

File tree

2 files changed

+66
-68
lines changed

2 files changed

+66
-68
lines changed

big_tests/tests/graphql_metric_SUITE.erl

+11-14
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,11 @@ get_all_metrics_as_dicts(Config) ->
209209
check_node_result_is_valid(ParsedResult, false).
210210

211211
get_by_name_metrics_as_dicts(Config) ->
212-
Name = [<<"c2s_element_in">>, <<"stanza_count">>],
212+
Name = [<<"xmpp_element_in">>, <<"c2s">>, <<"stanza_count">>],
213213
Result = get_metrics_as_dicts_by_name([<<"_">> | Name], Config),
214214
ParsedResult = get_ok_value([data, metric, getMetricsAsDicts], Result),
215215
[_|_] = ParsedResult,
216-
%% Only c2s_element_in type
216+
%% Only xmpp_element_in type
217217
lists:foreach(fun(#{<<"dict">> := Dict, <<"name">> := [_ | N]}) when N =:= Name ->
218218
check_spiral_dict(Dict)
219219
end, ParsedResult).
@@ -227,23 +227,23 @@ get_metrics_as_dicts_with_key_one(Config) ->
227227
Result = get_metrics_as_dicts_with_keys([<<"one">>], Config),
228228
ParsedResult = get_ok_value([data, metric, getMetricsAsDicts], Result),
229229
Map = dict_objects_to_map(ParsedResult),
230-
SentName = [metric_host_type(), <<"c2s_element_out">>, <<"stanza_count">>],
230+
SentName = [<<"global">>, <<"xmpp_element_out">>, <<"c2s">>, <<"stanza_count">>],
231231
[#{<<"key">> := <<"one">>, <<"value">> := One}] = maps:get(SentName, Map),
232232
?assert(is_integer(One)).
233233

234234
get_metrics_as_dicts_with_nonexistent_key(Config) ->
235235
Result = get_metrics_as_dicts_with_keys([<<"not_existing">>], Config),
236236
ParsedResult = get_ok_value([data, metric, getMetricsAsDicts], Result),
237237
Map = dict_objects_to_map(ParsedResult),
238-
RecvName = [<<"global">>, <<"xmpp_element_size_in">>, <<"c2s">>, <<"byte_size">>],
238+
RecvName = [<<"global">>, <<"xmpp_element_in">>, <<"c2s">>, <<"byte_size">>],
239239
[] = maps:get(RecvName, Map).
240240

241241
get_metrics_as_dicts_empty_args(Config) ->
242242
%% Empty name
243243
Result = get_metrics_as_dicts([], [<<"median">>], Config),
244244
ParsedResult = get_ok_value([data, metric, getMetricsAsDicts], Result),
245245
Map = dict_objects_to_map(ParsedResult),
246-
RecvName = [<<"global">>, <<"xmpp_element_size_in">>, <<"c2s">>, <<"byte_size">>],
246+
RecvName = [<<"global">>, <<"xmpp_element_in">>, <<"c2s">>, <<"byte_size">>],
247247
[#{<<"key">> := <<"median">>, <<"value">> := Median}] = maps:get(RecvName, Map),
248248
?assert(is_integer(Median)),
249249
%% Empty keys
@@ -272,13 +272,13 @@ get_cluster_metrics(Config) ->
272272
check_node_result_is_valid(Res2, true).
273273

274274
get_by_name_cluster_metrics_as_dicts(Config) ->
275-
Name = [<<"c2s_element_in">>, <<"stanza_count">>],
275+
Name = [<<"xmpp_element_in">>, <<"c2s">>, <<"stanza_count">>],
276276
Result = get_cluster_metrics_as_dicts_by_name([<<"_">> | Name], Config),
277277
NodeResult = get_ok_value([data, metric, getClusterMetricsAsDicts], Result),
278278
Map = node_objects_to_map(NodeResult),
279279
%% Contains data for at least two nodes
280280
?assert(maps:size(Map) > 1),
281-
%% Only c2s_element_in type
281+
%% Only xmpp_element_in type
282282
maps:map(fun(_Node, [_|_] = NodeRes) ->
283283
lists:foreach(fun(#{<<"dict">> := Dict, <<"name">> := [_ | N]}) when N =:= Name ->
284284
check_spiral_dict(Dict)
@@ -317,7 +317,7 @@ get_cluster_metrics_empty_args(Config) ->
317317
ParsedResult = get_ok_value([data, metric, getClusterMetricsAsDicts], Result),
318318
[#{<<"node">> := Node, <<"result">> := ResList}] = ParsedResult,
319319
Map = dict_objects_to_map(ResList),
320-
SentName = [<<"global">>, <<"c2s_element_in">>, <<"stanza_count">>],
320+
SentName = [<<"global">>, <<"xmpp_element_in">>, <<"c2s">>, <<"stanza_count">>],
321321
[#{<<"key">> := <<"one">>, <<"value">> := One}] = maps:get(SentName, Map),
322322
?assert(is_integer(One)),
323323
%% Empty keys
@@ -351,15 +351,12 @@ get_cluster_metrics_empty_strings(Config) ->
351351
check_node_result_is_valid(ResList, MetricsAreGlobal) ->
352352
%% Check that result contains something
353353
Map = dict_objects_to_map(ResList),
354-
SentName = case MetricsAreGlobal of
355-
true -> [<<"global">>, <<"c2s_element_in">>, <<"stanza_count">>];
356-
false -> [metric_host_type(), <<"c2s_element_in">>, <<"stanza_count">>]
357-
end,
354+
SentName = [<<"global">>, <<"xmpp_element_in">>, <<"c2s">>, <<"stanza_count">>],
358355
check_spiral_dict(maps:get(SentName, Map)),
359356
[#{<<"key">> := <<"value">>,<<"value">> := V} | _] =
360-
maps:get([<<"global">>,<<"sm_unique_sessions">>,<<"count">>], Map),
357+
maps:get([<<"global">>, <<"sm_unique_sessions">>, <<"count">>], Map),
361358
?assert(is_integer(V)),
362-
HistObjects = maps:get([<<"global">>, <<"xmpp_element_size_in">>, <<"c2s">>, <<"byte_size">>], Map),
359+
HistObjects = maps:get([<<"global">>, <<"xmpp_element_in">>, <<"c2s">>, <<"byte_size">>], Map),
363360
check_histogram(kv_objects_to_map(HistObjects)).
364361

365362
check_histogram(Map) ->

big_tests/tests/metrics_api_SUITE.erl

+55-54
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ non_existent_metrics(_Config) ->
107107
assert_status(404, request(<<"GET">>, "/metrics/global/badMetric")),
108108
assert_status(404, request(<<"GET">>, "/metrics/host_type/badHostType")),
109109
assert_status(404, request(<<"GET">>,
110-
"/metrics/host_type/badHostType/c2s_element_out.stanza_count")),
110+
"/metrics/host_type/badHostType/c2s_message_processed.count")),
111111
assert_status(404, request(<<"GET">>, ["/metrics/", HostType, "/", GlobalMetricName])),
112112
assert_status(404, request(<<"GET">>, ["/metrics/", HostType, "/badMetric"])).
113113

@@ -122,32 +122,32 @@ one_client_just_logs_in(Config) ->
122122
(Config, metrics_helper:userspec(1, Config),
123123
fun(_User1) -> end_of_story end,
124124
%% A list of metrics and their expected relative increase
125-
[{'c2s_element_in.iq_count', 0 + user_alpha(2)},
126-
{'c2s_element_out.iq_count', 0 + user_alpha(2)},
127-
{'c2s_element_in.message_count', 0},
128-
{'c2s_element_out.message_count', 0},
129-
{'c2s_element_in.presence_count', 0 + user_alpha(1)},
130-
{'c2s_element_out.presence_count', 0 + user_alpha(1)},
131-
{'c2s_element_in.stanza_count', 0 + user_alpha(3)},
132-
{'c2s_element_out.stanza_count', 0 + user_alpha(3)},
133-
{'sm_session.logins', 0 + user_alpha(1)},
134-
{'sm_session.logouts', 0 + user_alpha(1)}
125+
[{global, 'xmpp_element_in.c2s.iq_count', 0 + user_alpha(2)},
126+
{global, 'xmpp_element_out.c2s.iq_count', 0 + user_alpha(2)},
127+
{global, 'xmpp_element_in.c2s.message_count', 0},
128+
{global, 'xmpp_element_out.c2s.message_count', 0},
129+
{global, 'xmpp_element_in.c2s.presence_count', 0 + user_alpha(1)},
130+
{global, 'xmpp_element_out.c2s.presence_count', 0 + user_alpha(1)},
131+
{global, 'xmpp_element_in.c2s.stanza_count', 0 + user_alpha(3)},
132+
{global, 'xmpp_element_out.c2s.stanza_count', 0 + user_alpha(3)},
133+
{host_type(), 'sm_session.logins', 0 + user_alpha(1)},
134+
{host_type(), 'sm_session.logouts', 0 + user_alpha(1)}
135135
]).
136136

137137
two_clients_just_log_in(Config) ->
138138
instrumented_story
139139
(Config, metrics_helper:userspec(1, 1, Config),
140140
fun(_User1, _User2) -> end_of_story end,
141-
[{'c2s_element_in.iq_count', 0 + user_alpha(4)},
142-
{'c2s_element_out.iq_count', 0 + user_alpha(4)},
143-
{'c2s_element_in.message_count', 0},
144-
{'c2s_element_out.message_count', 0},
145-
{'c2s_element_in.presence_count', 0 + user_alpha(2)},
146-
{'c2s_element_out.presence_count', 0 + user_alpha(2)},
147-
{'c2s_element_in.stanza_count', 0 + user_alpha(6)},
148-
{'c2s_element_out.stanza_count', 0 + user_alpha(6)},
149-
{'sm_session.logins', 0 + user_alpha(2)},
150-
{'sm_session.logouts', 0 + user_alpha(2)}
141+
[{global, 'xmpp_element_in.c2s.iq_count', 0 + user_alpha(4)},
142+
{global, 'xmpp_element_out.c2s.iq_count', 0 + user_alpha(4)},
143+
{global, 'xmpp_element_in.c2s.message_count', 0},
144+
{global, 'xmpp_element_out.c2s.message_count', 0},
145+
{global, 'xmpp_element_in.c2s.presence_count', 0 + user_alpha(2)},
146+
{global, 'xmpp_element_out.c2s.presence_count', 0 + user_alpha(2)},
147+
{global, 'xmpp_element_in.c2s.stanza_count', 0 + user_alpha(6)},
148+
{global, 'xmpp_element_out.c2s.stanza_count', 0 + user_alpha(6)},
149+
{host_type(), 'sm_session.logins', 0 + user_alpha(2)},
150+
{host_type(), 'sm_session.logouts', 0 + user_alpha(2)}
151151
]).
152152

153153
one_message_sent(Config) ->
@@ -158,8 +158,8 @@ one_message_sent(Config) ->
158158
escalus_client:send(User1, Chat),
159159
escalus_client:wait_for_stanza(User2)
160160
end,
161-
[{'c2s_element_in.message_count', 1},
162-
{'c2s_element_out.message_count', 1}]).
161+
[{global, 'xmpp_element_in.c2s.message_count', 1},
162+
{global, 'xmpp_element_out.c2s.message_count', 1}]).
163163

164164
one_direct_presence_sent(Config) ->
165165
Userspec = metrics_helper:userspec(1, 1, Config),
@@ -170,10 +170,10 @@ one_direct_presence_sent(Config) ->
170170
escalus:send(User1, Presence),
171171
escalus:wait_for_stanza(User2)
172172
end,
173-
[{'c2s_element_in.presence_count', 1 + user_alpha(2)},
174-
{'c2s_element_out.presence_count', 1 + user_alpha(2)},
175-
{'c2s_element_in.stanza_count', 1 + user_alpha(6)},
176-
{'c2s_element_out.stanza_count', 1 + user_alpha(6)}]).
173+
[{global, 'xmpp_element_in.c2s.presence_count', 1 + user_alpha(2)},
174+
{global, 'xmpp_element_out.c2s.presence_count', 1 + user_alpha(2)},
175+
{global, 'xmpp_element_in.c2s.stanza_count', 1 + user_alpha(6)},
176+
{global, 'xmpp_element_out.c2s.stanza_count', 1 + user_alpha(6)}]).
177177

178178
one_iq_sent(Config) ->
179179
instrumented_story
@@ -183,11 +183,11 @@ one_iq_sent(Config) ->
183183
escalus_client:send(User1, RosterIq),
184184
escalus_client:wait_for_stanza(User1)
185185
end,
186-
[{'c2s_element_in.iq_count', 3},
187-
{'c2s_element_out.iq_count', 3},
188-
{'mod_roster_get.count', 1},
189-
{'c2s_element_in.stanza_count', 1 + user_alpha(3)},
190-
{'c2s_element_out.stanza_count', 1 + user_alpha(3)}]).
186+
[{global, 'xmpp_element_in.c2s.iq_count', 3},
187+
{global, 'xmpp_element_out.c2s.iq_count', 3},
188+
{host_type(), 'mod_roster_get.count', 1},
189+
{global, 'xmpp_element_in.c2s.stanza_count', 1 + user_alpha(3)},
190+
{global, 'xmpp_element_out.c2s.stanza_count', 1 + user_alpha(3)}]).
191191

192192
one_message_error(Config) ->
193193
instrumented_story
@@ -198,10 +198,10 @@ one_message_error(Config) ->
198198
escalus_client:send(User1, Chat),
199199
escalus_client:wait_for_stanza(User1)
200200
end,
201-
[{'c2s_element_out.error_count', 1},
202-
{'c2s_element_out.iq_error_count', 0},
203-
{'c2s_element_out.message_error_count', 1},
204-
{'c2s_element_out.presence_error_count', 0}]).
201+
[{global, 'xmpp_element_out.c2s.error_count', 1},
202+
{global, 'xmpp_element_out.c2s.iq_error_count', 0},
203+
{global, 'xmpp_element_out.c2s.message_error_count', 1},
204+
{global, 'xmpp_element_out.c2s.presence_error_count', 0}]).
205205

206206
one_iq_error(Config) ->
207207
instrumented_story
@@ -211,10 +211,10 @@ one_iq_error(Config) ->
211211
escalus_client:send(User1, BadIQ),
212212
escalus_client:wait_for_stanza(User1)
213213
end,
214-
[{'c2s_element_out.error_count', 1},
215-
{'c2s_element_out.iq_error_count', 1},
216-
{'c2s_element_out.message_error_count', 0},
217-
{'c2s_element_out.presence_error_count', 0}]).
214+
[{global, 'xmpp_element_out.c2s.error_count', 1},
215+
{global, 'xmpp_element_out.c2s.iq_error_count', 1},
216+
{global, 'xmpp_element_out.c2s.message_error_count', 0},
217+
{global, 'xmpp_element_out.c2s.presence_error_count', 0}]).
218218

219219
one_presence_error(Config) ->
220220
instrumented_story
@@ -225,10 +225,10 @@ one_presence_error(Config) ->
225225
escalus_client:send(User1, BadPres),
226226
escalus_client:wait_for_stanza(User1)
227227
end,
228-
[{'c2s_element_out.error_count', 1},
229-
{'c2s_element_out.iq_error_count', 0},
230-
{'c2s_element_out.message_error_count', 0},
231-
{'c2s_element_out.presence_error_count', 1}]).
228+
[{global, 'xmpp_element_out.c2s.error_count', 1},
229+
{global, 'xmpp_element_out.c2s.iq_error_count', 0},
230+
{global, 'xmpp_element_out.c2s.message_error_count', 0},
231+
{global, 'xmpp_element_out.c2s.presence_error_count', 1}]).
232232

233233
session_counters(Config) ->
234234
escalus:story
@@ -350,31 +350,32 @@ user_alpha(NumberOfUsers) ->
350350
%% will be bumped by +1 at login.
351351
NumberOfUsers.
352352

353-
instrumented_story(Config, UsersSpecs, StoryFun, CounterSpecs) ->
353+
instrumented_story(Config, UsersSpecs, StoryFun, CounterSpecs0) ->
354+
CounterSpecs = case metrics_helper:all_metrics_are_global(Config) of
355+
true -> [{global, Counter, N} || {_, Counter, N} <- CounterSpecs0];
356+
false -> CounterSpecs0
357+
end,
354358
Befores = fetch_all(Config, CounterSpecs),
355359
StoryResult = escalus:story(Config, UsersSpecs, StoryFun),
356360
Afters = fetch_all(Config, CounterSpecs),
357361
[ assert_counter_inc(Name, N, find(Name, Befores), find(Name, Afters))
358-
|| {Name, N} <- CounterSpecs ],
362+
|| {_, Name, N} <- CounterSpecs ],
359363
StoryResult.
360364

361365
fetch_all(Config, CounterSpecs) ->
362-
FetchCounterFun = case metrics_helper:all_metrics_are_global(Config) of
363-
true -> fun fetch_global_spiral_values/2;
364-
_ -> fun fetch_counter_value/2
365-
end,
366-
[ {Counter, FetchCounterFun(Counter, Config)}
367-
|| {Counter, _} <- CounterSpecs ].
366+
[ {Counter, fetch_counter_value(Scope, Counter, Config)}
367+
|| {Scope, Counter, _} <- CounterSpecs ].
368368

369369
find(CounterName, CounterList) ->
370370
case lists:keyfind(CounterName, 1, CounterList) of
371371
false -> error(counter_defined_incorrectly);
372372
{CounterName, Val} -> Val end.
373373

374-
fetch_counter_value(Counter, _Config) ->
374+
fetch_counter_value(global, Counter, Config) ->
375+
fetch_global_spiral_values(Counter, Config);
376+
fetch_counter_value(HostType, Counter, Config) ->
375377
Metric = atom_to_binary(Counter, utf8),
376378

377-
HostType = host_type(),
378379
HostTypeName = metrics_helper:make_host_type_name(HostType),
379380

380381
Result = request(<<"GET">>, ["/metrics/host_type/", HostTypeName, "/", Metric]),

0 commit comments

Comments
 (0)