Skip to content

Commit aafbc75

Browse files
Merge pull request #4226 from esl/feature/instrument
Feature/instrument
2 parents 1680efa + a66c1b8 commit aafbc75

File tree

233 files changed

+8421
-4741
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

233 files changed

+8421
-4741
lines changed

Diff for: .circleci/template.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ jobs:
442442
- run:
443443
name: Build GraphQL static docs
444444
command: |
445-
npm install --prefix=$HOME/.local --global spectaql
445+
npm install --global [email protected] spectaql
446446
npx spectaql -t doc/graphql-api -f admin-graphql-doc.html doc/graphql-api/Admin-GraphQL_spectaql.yml
447447
npx spectaql -C -J -t doc/graphql-api -f user-graphql-doc.html doc/graphql-api/User-GraphQL_spectaql.yml
448448
- run:

Diff for: big_tests/default.spec

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
{suites, "tests", mam_send_message_SUITE}.
6262
{suites, "tests", metrics_api_SUITE}.
6363
{suites, "tests", metrics_c2s_SUITE}.
64-
{suites, "tests", metrics_register_SUITE}.
6564
{suites, "tests", metrics_roster_SUITE}.
6665
{suites, "tests", metrics_session_SUITE}.
6766
{suites, "tests", mod_blocking_SUITE}.
@@ -108,6 +107,7 @@
108107
{suites, "tests", sic_SUITE}.
109108
{suites, "tests", smart_markers_SUITE}.
110109
{suites, "tests", sm_SUITE}.
110+
{suites, "tests", system_probes_SUITE}.
111111
{suites, "tests", vcard_SUITE}.
112112
{suites, "tests", vcard_simple_SUITE}.
113113
{suites, "tests", websockets_SUITE}.

Diff for: big_tests/dynamic_domains.config

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{host_type, <<"test type">>},
77
{secondary_domain, <<"domain.example.org">>},
88
{secondary_host_type, <<"test type">>},
9+
{anonymous_host_type, <<"anonymous">>},
910
{dynamic_domains, [{<<"test type">>, [<<"domain.example.com">>, <<"domain.example.org">>]},
1011
{<<"anonymous">>, [<<"anonymous.example.com">>]}]},
1112
{muc_service, <<"groupchats.domain.example.com">>},
@@ -119,7 +120,8 @@
119120
{wspath, <<"/ws-xmpp">>}]},
120121
{admin, [
121122
{username, <<"admin">>},
122-
{server, <<"localhost">>},
123+
{server, <<"domain.example.com">>},
124+
{host, <<"localhost">>},
123125
{password, <<"bruce_almighty">>}]},
124126
{secure_joe, [
125127
{username, <<"secure_joe">>},

Diff for: big_tests/dynamic_domains.spec

+1-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@
8383

8484
{suites, "tests", metrics_c2s_SUITE}.
8585

86-
{suites, "tests", metrics_register_SUITE}.
87-
8886
{suites, "tests", metrics_roster_SUITE}.
8987

9088
{suites, "tests", metrics_session_SUITE}.
@@ -154,6 +152,7 @@
154152

155153
{suites, "tests", smart_markers_SUITE}.
156154
{suites, "tests", sm_SUITE}.
155+
{suites, "tests", system_probes_SUITE}.
157156
{suites, "tests", vcard_SUITE}.
158157
{suites, "tests", vcard_simple_SUITE}.
159158
{suites, "tests", websockets_SUITE}.

Diff for: big_tests/test.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
{vars, "mim1"},
2323
{cluster, mim},
2424
{secondary_domain, <<"localhost.bis">>},
25-
{reloaded_domain, <<"sogndal">>},
2625
{secondary_host_type, <<"localhost.bis">>},
26+
{anonymous_host_type, <<"anonymous.localhost">>},
2727
{muc_service, <<"muc.localhost">>},
2828
{muc_service_pattern, <<"muc.@HOST@">>},
2929
{muc_light_service, <<"muclight.localhost">>},

Diff for: big_tests/tests/accounts_SUITE.erl

+30-19
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
-module(accounts_SUITE).
22
-compile([export_all, nowarn_export_all]).
33

4-
-include_lib("escalus/include/escalus.hrl").
54
-include_lib("escalus/include/escalus_xmlns.hrl").
6-
7-
-include_lib("common_test/include/ct.hrl").
85
-include_lib("eunit/include/eunit.hrl").
9-
106
-include_lib("exml/include/exml.hrl").
117

12-
-import(distributed_helper, [mim/0,
13-
require_rpc_nodes/1,
14-
rpc/4]).
15-
8+
-import(distributed_helper, [mim/0, require_rpc_nodes/1, rpc/4]).
169
-import(mongoose_helper, [wait_for_user/3]).
17-
10+
-import(auth_helper, [assert_event/2]).
1811
-import(domain_helper, [domain/0, host_type/0]).
1912

2013
%%--------------------------------------------------------------------
@@ -37,6 +30,7 @@ all() ->
3730

3831
groups() ->
3932
[{register, [parallel], [register,
33+
unregister,
4034
already_registered,
4135
registration_conflict,
4236
check_unregistered]},
@@ -68,13 +62,15 @@ change_password_tests() ->
6862
%%--------------------------------------------------------------------
6963

7064
init_per_suite(Config1) ->
65+
instrument_helper:start(instrument_helper:declared_events(ejabberd_auth)),
7166
ok = dynamic_modules:ensure_modules(host_type(), required_modules()),
7267
Config2 = [{mod_register_options, mod_register_options()} | Config1],
7368
escalus:init_per_suite([{escalus_user_db, xmpp} | Config2]).
7469

7570
end_per_suite(Config) ->
7671
escalus_fresh:clean(),
77-
escalus:end_per_suite(Config).
72+
escalus:end_per_suite(Config),
73+
instrument_helper:stop().
7874

7975
required_modules() ->
8076
[{mod_register, mod_register_options()}].
@@ -178,23 +174,37 @@ end_per_testcase(CaseName, Config) ->
178174

179175
register(Config) ->
180176
[{Name1, _UserSpec1}, {Name2, _UserSpec2}] = escalus_users:get_users([alice, bob]),
181-
escalus_fresh:create_users(Config, escalus:get_users([Name1, Name2])).
177+
Config1 = escalus_fresh:create_users(Config, escalus:get_users([Name1, Name2])),
178+
assert_event(auth_register_user, escalus_users:get_jid(Config1, Name1)),
179+
assert_event(auth_register_user, escalus_users:get_jid(Config1, Name2)),
180+
assert_event(auth_try_register, escalus_users:get_jid(Config1, Name1)),
181+
assert_event(auth_try_register, escalus_users:get_jid(Config1, Name2)),
182+
assert_event(auth_does_user_exist, escalus_users:get_jid(Config1, Name1)),
183+
assert_event(auth_does_user_exist, escalus_users:get_jid(Config1, Name2)).
184+
185+
unregister(Config) ->
186+
UserSpec = escalus_fresh:freshen_spec(Config, alice),
187+
escalus_users:create_user(Config, {alice, UserSpec}),
188+
escalus_users:delete_user(Config, {alice, UserSpec}),
189+
assert_event(auth_unregister_user, escalus_users:get_jid(Config, UserSpec)).
182190

183191
already_registered(Config) ->
184-
escalus_fresh:story(Config, [{alice, 1}], fun(Alice) ->
185-
escalus:send(Alice, escalus_stanza:get_registration_fields()),
186-
Stanza = escalus:wait_for_stanza(Alice),
187-
escalus:assert(is_iq_result, Stanza),
188-
true = has_registered_element(Stanza)
192+
escalus_fresh:story(Config, [{alice, 1}], fun already_registered_story/1).
193+
194+
already_registered_story(Alice) ->
195+
AliceJid = escalus_utils:get_short_jid(Alice),
196+
assert_event(auth_register_user, AliceJid), % one event expected
197+
escalus:send(Alice, escalus_stanza:get_registration_fields()),
198+
Stanza = escalus:wait_for_stanza(Alice),
199+
escalus:assert(is_iq_result, Stanza),
200+
true = has_registered_element(Stanza),
201+
assert_event(auth_register_user, AliceJid). % still one event - nothing new
189202

190-
end).
191203
registration_conflict(Config) ->
192204
[Alice] = escalus_users:get_users([alice]),
193205
{ok, result, _Stanza} = escalus_users:create_user(Config, Alice),
194206
{ok, conflict, _Raw} = escalus_users:create_user(Config, Alice).
195207

196-
197-
198208
admin_notify(Config) ->
199209
[{Name1, UserSpec1}, {Name2, UserSpec2}] = escalus_users:get_users([alice, bob]),
200210
[{_, AdminSpec}] = escalus_users:get_users([admin]),
@@ -204,6 +214,7 @@ admin_notify(Config) ->
204214

205215
rpc(mim(), ejabberd_auth, try_register, [mongoose_helper:make_jid(AdminU, AdminS), AdminP]),
206216
escalus:story(Config, [{admin, 1}], fun(Admin) ->
217+
assert_event(auth_authorize, escalus_utils:get_jid(Admin)),
207218
escalus:create_users(Config, escalus:get_users([Name1, Name2])),
208219

209220
Predicates = [

Diff for: big_tests/tests/amp_big_SUITE.erl

+9-1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ init_per_suite(Config) ->
118118
{Mod, Code} = dynamic_compile:from_string(amp_test_helper_code()),
119119
rpc(mim(), code, load_binary, [Mod, "amp_test_helper.erl", Code]),
120120
setup_meck(suite),
121+
instrument_helper:start(declared_events()),
121122
escalus:init_per_suite(ConfigWithHooks).
122123

123124
amp_test_helper_code() ->
@@ -131,10 +132,17 @@ amp_test_helper_code() ->
131132
" _ -> meck:passthrough([Socket, Data])\n"
132133
" end.\n".
133134

135+
declared_events() ->
136+
[ % tested by privacy helpers
137+
{mod_privacy_set, #{host_type => host_type()}},
138+
{mod_privacy_get, #{host_type => host_type()}}
139+
].
140+
134141
end_per_suite(C) ->
135142
teardown_meck(suite),
136143
escalus_fresh:clean(),
137-
escalus:end_per_suite(C).
144+
escalus:end_per_suite(C),
145+
instrument_helper:stop().
138146

139147
init_per_group(GroupName, Config) ->
140148
Config1 = case lists:member(GroupName, main_group_names()) of

Diff for: big_tests/tests/anonymous_SUITE.erl

+22-3
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ suite() ->
4545
%% Init & teardown
4646
%%--------------------------------------------------------------------
4747
init_per_suite(Config) ->
48+
instrument_helper:start(declared_events()),
4849
escalus:init_per_suite(Config).
4950

5051
end_per_suite(Config) ->
51-
escalus:end_per_suite(Config).
52+
escalus:end_per_suite(Config),
53+
instrument_helper:stop().
5254

5355
init_per_testcase(CaseName, Config0) ->
5456
NewUsers = escalus_ct:get_config(escalus_anon_users),
@@ -67,23 +69,27 @@ end_per_testcase(CaseName, Config) ->
6769
connection_is_registered_with_sasl_anon(Config) ->
6870
escalus:story(Config, [{jon, 1}], fun(Jon) ->
6971
JID = jid:from_binary(escalus_client:short_jid(Jon)),
72+
assert_event(auth_anonymous_register_user, JID),
7073
OrigName = escalus_users:get_username(Config, jon),
7174
?assertNotEqual(OrigName, JID#jid.luser),
7275
F = fun() -> rpc(mim(), ejabberd_auth, does_user_exist, [JID]) end,
7376
true = F(),
7477
escalus_connection:kill(Jon),
75-
mongoose_helper:wait_until(F, false)
78+
mongoose_helper:wait_until(F, false),
79+
assert_event(auth_anonymous_unregister_user, JID)
7680
end).
7781

7882
connection_is_registered_with_login(Config) ->
7983
escalus:story(Config, [{anna, 1}], fun(Anna) ->
8084
JID = jid:from_binary(escalus_client:short_jid(Anna)),
85+
assert_event(auth_anonymous_register_user, JID),
8186
OrigName = escalus_users:get_username(Config, anna),
8287
?assertEqual(OrigName, JID#jid.luser),
8388
F = fun() -> rpc(mim(), ejabberd_auth, does_user_exist, [JID]) end,
8489
true = F(),
8590
escalus_connection:kill(Anna),
86-
mongoose_helper:wait_until(F, false)
91+
mongoose_helper:wait_until(F, false),
92+
assert_event(auth_anonymous_unregister_user, JID)
8793
end).
8894

8995
messages_story(Config) ->
@@ -94,3 +100,16 @@ messages_story(Config) ->
94100
%% Below's dirty, but there is no other easy way...
95101
escalus_assert:is_chat_message(<<"Hi!">>, Stanza)
96102
end).
103+
104+
%% Helpers
105+
106+
declared_events() ->
107+
instrument_helper:declared_events(ejabberd_auth_anonymous, [host_type()]).
108+
109+
host_type() ->
110+
domain_helper:anonymous_host_type().
111+
112+
assert_event(EventName, #jid{luser = LUser, lserver = LServer}) ->
113+
instrument_helper:assert_one(
114+
EventName, #{host_type => host_type()},
115+
fun(M) -> M =:= #{count => 1, user => LUser, server => LServer} end).

Diff for: big_tests/tests/auth_helper.erl

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-module(auth_helper).
2+
-export([assert_event/2]).
3+
4+
-include_lib("jid/include/jid.hrl").
5+
-import(domain_helper, [host_type/0]).
6+
7+
assert_event(EventName, BinJid)
8+
when EventName =:= auth_unregister_user; EventName =:= auth_register_user ->
9+
#jid{luser = LUser, lserver = LServer} = jid:from_binary(BinJid),
10+
F = fun(M) ->
11+
M =:= #{count => 1, user => LUser, server => LServer}
12+
end,
13+
instrument_helper:assert_one(EventName, #{host_type => host_type()}, F);
14+
assert_event(EventName, BinJid)
15+
when EventName =:= auth_authorize ->
16+
#jid{lserver = LServer} = jid:from_binary(BinJid),
17+
F = fun(#{time := Time, count := 1, server := Server}) ->
18+
(Time > 0) and (Server =:= LServer)
19+
end,
20+
%% Note: this could match events from other tests because there is no user name
21+
instrument_helper:assert(EventName, #{host_type => host_type()}, F);
22+
assert_event(EventName, BinJid) ->
23+
#jid{luser = LUser, lserver = LServer} = jid:from_binary(BinJid),
24+
F = fun(#{time := Time, count := 1, user := User, server := Server}) ->
25+
(Time > 0) and (User =:= LUser) and (Server =:= LServer)
26+
end,
27+
instrument_helper:assert_one(EventName, #{host_type => host_type()}, F).

Diff for: big_tests/tests/auth_methods_for_c2s_SUITE.erl

+26-15
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
-include_lib("exml/include/exml.hrl").
66

77
-import(distributed_helper, [mim/0, rpc/4]).
8+
-import(auth_helper, [assert_event/2]).
89

910
all() ->
1011
[
1112
{group, two_methods_enabled},
12-
{group, metrics}
13+
{group, instrumentation}
1314
].
1415

1516
groups() ->
@@ -20,29 +21,37 @@ groups() ->
2021
cannot_login_with_not_allowed_method,
2122
can_login_to_another_listener
2223
]},
23-
{metrics, [],
24+
{instrumentation, [],
2425
[
25-
metrics_incremented_on_user_connect
26+
instrumentation_incremented_on_user_connect
2627
]}
2728
].
2829

30+
suite() ->
31+
distributed_helper:require_rpc_nodes([mim]) ++ escalus:suite().
32+
2933
init_per_suite(Config) ->
3034
escalus:init_per_suite(Config).
3135

3236
end_per_suite(Config) ->
3337
escalus:end_per_suite(Config).
3438

35-
init_per_group(metrics, Config) ->
36-
set_auth_mod(Config);
39+
init_per_group(instrumentation, Config) ->
40+
Config2 = set_auth_mod(Config),
41+
instrument_helper:start(events()),
42+
Config2;
3743
init_per_group(_, Config0) ->
3844
Config1 = ejabberd_node_utils:init(Config0),
3945
ejabberd_node_utils:backup_config_file(Config1),
4046
Config2 = modify_config_and_restart(Config1),
47+
instrument_helper:start(events()),
4148
escalus_cleaner:start(Config2).
4249

43-
end_per_group(metrics, _Config) ->
50+
end_per_group(instrumentation, _Config) ->
51+
instrument_helper:stop(),
4452
escalus_fresh:clean();
4553
end_per_group(_, Config) ->
54+
instrument_helper:stop(),
4655
ejabberd_node_utils:restore_config_file(Config),
4756
ejabberd_node_utils:restart_application(mongooseim),
4857
escalus_fresh:clean().
@@ -93,24 +102,24 @@ can_login_to_another_listener(Config) ->
93102
TlsPort = ct:get_config({hosts, mim, c2s_tls_port}),
94103
Spec2 = [{port, TlsPort}, {ssl, true}, {ssl_opts, [{verify, verify_none}]},
95104
{password, <<"wrong">>} | Spec],
96-
{ok, _, _} = escalus_connection:start(Spec2).
105+
{ok, Conn, _} = escalus_connection:start(Spec2),
106+
assert_event(auth_authorize, escalus_utils:get_jid(Conn)).
97107

98-
metrics_incremented_on_user_connect(ConfigIn) ->
108+
instrumentation_incremented_on_user_connect(Config) ->
99109
F = fun(Alice, Bob) ->
100110
Body = <<"Hello Bob">>,
101111
escalus:send(Alice, escalus_stanza:chat_to(Bob, Body)),
102-
escalus:assert(is_chat_message, [Body], escalus:wait_for_stanza(Bob))
112+
escalus:assert(is_chat_message, [Body], escalus:wait_for_stanza(Bob)),
113+
assert_event(auth_authorize, escalus_utils:get_jid(Alice)),
114+
assert_event(auth_authorize, escalus_utils:get_jid(Bob))
103115
end,
104-
HostType = domain_helper:host_type(),
105-
HostTypePrefix = domain_helper:make_metrics_prefix(HostType),
106-
MongooseMetrics = [{[HostTypePrefix, backends, auth, authorize], changed}],
107-
Config = [{mongoose_metrics, MongooseMetrics} | ConfigIn],
108116
escalus_fresh:story(Config, [{alice, 1}, {bob, 1}], F).
109117

110118
%% Helpers
111119
%% If dummy backend is enabled, it is not possible to create new users
112120
%% (we check if an user does exist before registering the user).
113121
register_user(Config, Spec) ->
122+
%% Calls backend module directly, so instrumentation is not called in this case.
114123
Mod = proplists:get_value(auth_mod, Config),
115124
#{username := User, server := Server,
116125
password := Password} = maps:from_list(Spec),
@@ -119,5 +128,7 @@ register_user(Config, Spec) ->
119128
HostType = domain_helper:host_type(),
120129
ok = rpc(mim(), Mod, try_register,
121130
[HostType, LUser, LServer, Password]),
122-
fun() -> rpc(mim(), Mod, remove_user,
123-
[HostType, LUser, LServer]) end.
131+
fun() -> rpc(mim(), Mod, remove_user, [HostType, LUser, LServer]) end.
132+
133+
events() ->
134+
[{auth_authorize, #{host_type => domain_helper:host_type()}}].

0 commit comments

Comments
 (0)