Skip to content

Commit 59df71b

Browse files
committed
getting rid of http connection_type for tcp/tls data in/out metrics
1 parent 505d0ff commit 59df71b

9 files changed

+41
-78
lines changed

big_tests/tests/bosh_SUITE.erl

+2-12
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ acks_test_cases() ->
107107
%%--------------------------------------------------------------------
108108

109109
init_per_suite(Config) ->
110-
instrument_helper:start(instrumentation_events(), negative_instrumentation_events()),
110+
instrument_helper:start(instrumentation_events()),
111111
Config1 = dynamic_modules:save_modules(host_type(), Config),
112112
escalus:init_per_suite([{escalus_user_db, {module, escalus_ejabberd}} | Config1]).
113113

@@ -195,9 +195,6 @@ create_and_terminate_session(Config) ->
195195
[instrument_helper:assert(Event, Label, fun(#{byte_size := BS}) -> BS > 0 end)
196196
|| {Event, Label} <- instrumentation_events(), Event =/= c2s_message_processed],
197197

198-
%% Verify C2S listener is not used
199-
instrument_helper:assert_not_emitted(negative_instrumentation_events()),
200-
201198
%% Assert the session was terminated.
202199
wait_for_zero_bosh_sessions().
203200

@@ -954,11 +951,4 @@ instrumentation_events() ->
954951
instrument_helper:declared_events(mod_bosh, [])
955952
++ [{c2s_message_processed, #{host_type => domain_helper:host_type()}},
956953
{xmpp_element_size_out, #{connection_type => c2s}, #{metrics => #{byte_size => histogram}}},
957-
{xmpp_element_size_in, #{connection_type => c2s}, #{metrics => #{byte_size => histogram}}}]
958-
-- negative_instrumentation_events().
959-
960-
negative_instrumentation_events() ->
961-
[{tcp_data_out, #{connection_type => c2s}},
962-
{tcp_data_in, #{connection_type => c2s}},
963-
{tls_data_out, #{connection_type => c2s}},
964-
{tls_data_in, #{connection_type => c2s}}].
954+
{xmpp_element_size_in, #{connection_type => c2s}, #{metrics => #{byte_size => histogram}}}].

big_tests/tests/websockets_SUITE.erl

+2-11
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ suite() ->
5454
%%--------------------------------------------------------------------
5555

5656
init_per_suite(Config) ->
57-
instrument_helper:start(instrumentation_events(), negative_instrumentation_events()),
57+
instrument_helper:start(instrumentation_events()),
5858
Config1 = escalus:init_per_suite(Config),
5959
Config2 = setup_listeners(Config1),
6060
escalus:create_users(Config2, escalus:get_users([alice, geralt, geralt_s, carol])).
@@ -116,8 +116,6 @@ metrics_test(Config) ->
116116
(#{time := Time}) -> Time > 0 end)
117117
|| {Event, Label} <- instrumentation_events()],
118118

119-
%% Verify C2S listener is not used
120-
instrument_helper:assert_not_emitted(negative_instrumentation_events()),
121119
ok
122120
end).
123121

@@ -172,11 +170,4 @@ instrumentation_events() ->
172170
instrument_helper:declared_events(mod_websockets, [])
173171
++ [{c2s_message_processed, #{host_type => domain_helper:host_type()}},
174172
{xmpp_element_size_out, #{connection_type => c2s}, #{metrics => #{byte_size => histogram}}},
175-
{xmpp_element_size_in, #{connection_type => c2s}, #{metrics => #{byte_size => histogram}}}]
176-
-- negative_instrumentation_events().
177-
178-
negative_instrumentation_events() ->
179-
[{tcp_data_out, #{connection_type => c2s}},
180-
{tcp_data_in, #{connection_type => c2s}},
181-
{tls_data_out, #{connection_type => c2s}},
182-
{tls_data_in, #{connection_type => c2s}}].
173+
{xmpp_element_size_in, #{connection_type => c2s}, #{metrics => #{byte_size => histogram}}}].

src/c2s/mongoose_c2s.erl

+27
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,33 @@
6565

6666
-export_type([packet/0, data/0, state/0, state/1, fsm_res/0, fsm_res/1, retries/0]).
6767

68+
-export([instrumentation/0]).
69+
-ignore_xref([instrumentation/0]).
70+
71+
-spec instrumentation() -> [mongoose_instrument:spec()].
72+
instrumentation() ->
73+
Acc = [
74+
{tcp_data_in, #{connection_type => c2s}, #{metrics => #{byte_size => spiral}}},
75+
{tcp_data_out, #{connection_type => c2s}, #{metrics => #{byte_size => spiral}}},
76+
{tls_data_in, #{connection_type => c2s}, #{metrics => #{byte_size => spiral}}},
77+
{tls_data_out, #{connection_type => c2s}, #{metrics => #{byte_size => spiral}}},
78+
{xmpp_element_size_out, #{connection_type => c2s}, #{metrics => #{byte_size => histogram}}},
79+
{xmpp_element_size_in, #{connection_type => c2s}, #{metrics => #{byte_size => histogram}}}
80+
],
81+
lists:foldl(fun instrumentation/2, Acc, ?ALL_HOST_TYPES).
82+
83+
-spec instrumentation(mongooseim:host_type(), [mongoose_instrument:spec()]) ->
84+
[mongoose_instrument:spec()].
85+
instrumentation(HostType, Acc) when is_binary(HostType) ->
86+
[{c2s_message_processed, #{host_type => HostType},
87+
#{metrics => #{time => histogram}}},
88+
{c2s_auth_failed, #{host_type => HostType},
89+
#{metrics => #{count => spiral}}},
90+
{c2s_element_in, #{host_type => HostType},
91+
#{metrics => maps:from_list([{Metric, spiral} || Metric <- mongoose_listener:element_spirals()])}},
92+
{c2s_element_out, #{host_type => HostType},
93+
#{metrics => maps:from_list([{Metric, spiral} || Metric <- mongoose_listener:element_spirals()])}} | Acc].
94+
6895
%%%----------------------------------------------------------------------
6996
%%% gen_statem
7097
%%%----------------------------------------------------------------------

src/c2s/mongoose_c2s_listener.erl

+1-28
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,14 @@
33
-include("mongoose.hrl").
44

55
-behaviour(mongoose_listener).
6-
-export([listener_spec/1, instrumentation/1]).
6+
-export([listener_spec/1]).
77

88
-behaviour(ranch_protocol).
99
-export([start_link/3]).
1010

1111
%% Hook handlers
1212
-export([handle_user_open_session/3]).
1313

14-
-export([instrumentation/0]).
15-
-ignore_xref([instrumentation/0]).
16-
17-
-spec instrumentation(_) -> [mongoose_instrument:spec()].
18-
instrumentation(_) ->
19-
lists:foldl(fun instrumentation/2, instrumentation(), ?ALL_HOST_TYPES).
20-
21-
-spec instrumentation() -> [mongoose_instrument:spec()].
22-
instrumentation() ->
23-
[{tcp_data_in, #{connection_type => c2s}, #{metrics => #{byte_size => spiral}}},
24-
{tcp_data_out, #{connection_type => c2s}, #{metrics => #{byte_size => spiral}}},
25-
{tls_data_in, #{connection_type => c2s}, #{metrics => #{byte_size => spiral}}},
26-
{tls_data_out, #{connection_type => c2s}, #{metrics => #{byte_size => spiral}}},
27-
{xmpp_element_size_out, #{connection_type => c2s}, #{metrics => #{byte_size => histogram}}},
28-
{xmpp_element_size_in, #{connection_type => c2s}, #{metrics => #{byte_size => histogram}}}].
29-
30-
-spec instrumentation(_, _) -> [mongoose_instrument:spec()].
31-
instrumentation(HostType, Acc) when is_binary(HostType) ->
32-
[{c2s_message_processed, #{host_type => HostType},
33-
#{metrics => #{time => histogram}}},
34-
{c2s_auth_failed, #{host_type => HostType},
35-
#{metrics => #{count => spiral}}},
36-
{c2s_element_in, #{host_type => HostType},
37-
#{metrics => maps:from_list([{Metric, spiral} || Metric <- mongoose_listener:element_spirals()])}},
38-
{c2s_element_out, #{host_type => HostType},
39-
#{metrics => maps:from_list([{Metric, spiral} || Metric <- mongoose_listener:element_spirals()])}} | Acc].
40-
4114
%% mongoose_listener
4215
-spec listener_spec(mongoose_listener:options()) -> supervisor:child_spec().
4316
listener_spec(Opts) ->

src/ejabberd_cowboy.erl

+2-7
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,8 @@
5252

5353
-spec instrumentation(mongoose_listener:options()) -> [mongoose_instrument:spec()].
5454
instrumentation(#{handlers := Handlers}) ->
55-
PerModule = [Spec || #{module := Module} <- Handlers,
56-
Spec <- mongoose_http_handler:instrumentation(Module)],
57-
[{tcp_data_in, #{connection_type => http}, #{metrics => #{byte_size => spiral}}},
58-
{tcp_data_out, #{connection_type => http}, #{metrics => #{byte_size => spiral}}},
59-
{tls_data_in, #{connection_type => http}, #{metrics => #{byte_size => spiral}}},
60-
{tls_data_out, #{connection_type => http}, #{metrics => #{byte_size => spiral}}}
61-
| PerModule].
55+
[Spec || #{module := Module} <- Handlers,
56+
Spec <- mongoose_http_handler:instrumentation(Module)].
6257

6358
-spec listener_spec(mongoose_listener:options()) -> supervisor:child_spec().
6459
listener_spec(Opts) ->

src/listeners/mongoose_listener.erl

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ stop_listener(Opts) ->
110110
%% Each listener module could be started more than once on different ports.
111111
-spec instrumentation([options()]) -> [mongoose_instrument:spec()].
112112
instrumentation(Listeners) ->
113-
lists:usort([Spec || Listener <- Listeners, Spec <- listener_instrumentation(Listener)]).
113+
%% c2s instrumentation is shared between Bosh, Websockets and TCP listeners
114+
lists:usort([Spec || Listener <- Listeners, Spec <- listener_instrumentation(Listener)])
115+
++ mongoose_c2s:instrumentation().
114116

115117
-spec listener_instrumentation(options()) -> [mongoose_instrument:spec()].
116118
listener_instrumentation(Opts = #{module := Module}) ->

src/listeners/mongoose_xmpp_socket.erl

+2-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
get_transport/1,
2424
get_conn_type/1]).
2525

26-
-callback new(ranch:ref(), mongoose_listener:connection_type(), mongoose_listener:options()) ->
27-
{state(), mongoose_listener:connection_type()}.
2826
-callback peername(state()) -> mongoose_transport:peer().
2927
-callback tcp_to_tls(state(), mongoose_listener:options(), side()) ->
3028
{ok, state()} | {error, term()}.
@@ -97,11 +95,10 @@ accept(ranch_ssl, Type, Ref, LOpts) ->
9795
ranch_ref = Ref, ip = {PeerIp, PeerPort}},
9896
activate(SocketState),
9997
SocketState;
100-
accept(Module, Type, Ref, LOpts) ->
101-
{State, NewType} = Module:new(Ref, Type, LOpts),
98+
accept(Module, Type, State, _LOpts) ->
10299
PeerIp = Module:peername(State),
103100
SocketState = #xmpp_socket{module = Module, state = State,
104-
connection_type = NewType, ip = PeerIp},
101+
connection_type = Type, ip = PeerIp},
105102
activate(SocketState),
106103
SocketState.
107104

src/mod_bosh_socket.erl

+1-7
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
get_cached_responses/1]).
2121

2222
%% mongoose_xmpp_socket callbacks
23-
-export([new/3,
24-
peername/1,
23+
-export([peername/1,
2524
tcp_to_tls/3,
2625
handle_data/2,
2726
activate/1,
@@ -1051,11 +1050,6 @@ ignore_undefined(Map) ->
10511050

10521051
%% mongoose_xmpp_socket callbacks
10531052

1054-
-spec new(mod_bosh:socket(), mongoose_listener:connection_type(), mongoose_listener:options()) ->
1055-
{mod_bosh:socket(), mongoose_listener:connection_type()}.
1056-
new(Socket, _, _LOpts) ->
1057-
{Socket, http}.
1058-
10591053
-spec peername(mod_bosh:socket()) -> mongoose_transport:peer().
10601054
peername(#bosh_socket{peer = Peer}) ->
10611055
Peer.

src/mod_websockets.erl

+1-7
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
terminate/3]).
2222

2323
%% mongoose_xmpp_socket callbacks
24-
-export([new/3,
25-
peername/1,
24+
-export([peername/1,
2625
tcp_to_tls/3,
2726
handle_data/2,
2827
activate/1,
@@ -367,11 +366,6 @@ case_insensitive_match(_, []) ->
367366

368367
%% mongoose_xmpp_socket callbacks
369368

370-
-spec new(socket(), mongoose_listener:connection_type(), mongoose_listener:options()) ->
371-
{socket(), mongoose_listener:connection_type()}.
372-
new(Socket, _, _LOpts) ->
373-
{Socket, http}.
374-
375369
-spec peername(socket()) -> mongoose_transport:peer().
376370
peername(#websocket{peername = PeerName}) ->
377371
PeerName.

0 commit comments

Comments
 (0)