Skip to content

Commit

Permalink
Move & rename SM probes
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekwegr committed Jul 2, 2024
1 parent 4bb2ac6 commit bf2e07b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion big_tests/tests/metrics_api_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,4 @@ request(Method, Path, Server) ->

restart_sm_probes() ->
rpc_call(ejabberd_sm, stop_probes, []),
rpc_call(ejabberd_sm, start_probes, []).
rpc_call(ejabberd_sm, start_probes, []).
33 changes: 19 additions & 14 deletions src/ejabberd_sm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@
-export([do_route/4]).

-ignore_xref([do_filter/3, do_route/4, get_unique_sessions_number/0,
get_user_present_pids/2, start_link/0, user_resources/2, sm_backend/0]).
get_user_present_pids/2, start_link/0, user_resources/2, sm_backend/0,
start_probes/0, stop_probes/0]).

-include("mongoose.hrl").
-include("jlib.hrl").
Expand Down Expand Up @@ -475,13 +476,11 @@ init([]) ->
gen_hook:add_handlers(hooks(HostType)),
mongoose_instrument:set_up(instrumentation(HostType))
end,
?ALL_HOST_TYPES),
%% Create metrics after backend has started, otherwise probe could have null value
start_probes(),
[global | ?ALL_HOST_TYPES]),
{ok, #state{}}.

start_probes() ->
mongoose_instrument:set_up(instrumentation(global)).
mongoose_instrument:set_up(global_probes()).

Check warning on line 483 in src/ejabberd_sm.erl

View check run for this annotation

Codecov / codecov/patch

src/ejabberd_sm.erl#L483

Added line #L483 was not covered by tests

-spec hooks(binary()) -> [gen_hook:hook_tuple()].
hooks(HostType) ->
Expand Down Expand Up @@ -563,12 +562,12 @@ handle_info(_Info, State) ->
%%--------------------------------------------------------------------
-spec terminate(_, state()) -> 'ok'.
terminate(_Reason, _State) ->
[mongoose_instrument:tear_down(instrumentation(HostType)) || HostType <- ?ALL_HOST_TYPES],
stop_probes(),
[mongoose_instrument:tear_down(instrumentation(HostType))
|| HostType <- [global | ?ALL_HOST_TYPES]],
ok.

stop_probes() ->
mongoose_instrument:tear_down(instrumentation(global)).
mongoose_instrument:tear_down(global_probes()).

Check warning on line 570 in src/ejabberd_sm.erl

View check run for this annotation

Codecov / codecov/patch

src/ejabberd_sm.erl#L570

Added line #L570 was not covered by tests

%%--------------------------------------------------------------------
%% Func: code_change(OldVsn, State, Extra) -> {ok, NewState}
Expand Down Expand Up @@ -980,16 +979,22 @@ sm_backend() ->

-spec instrumentation(mongooseim:host_type_or_global()) -> [mongoose_instrument:spec()].
instrumentation(global) ->
[{sm_total_sessions, #{},
#{probe => #{module => mongoose_metrics_probe_total_sessions}, metrics => #{count => gauge}}},
{sm_unique_sessions, #{},
#{probe => #{module => mongoose_metrics_probe_unique_sessions}, metrics => #{count => gauge}}},
{sm_node_sessions, #{},
#{probe => #{module => mongoose_metrics_probe_node_sessions}, metrics => #{count => gauge}}}];
global_probes();
instrumentation(HostType) ->
[{sm_session, #{host_type => HostType},
#{metrics => #{logins => spiral, logouts => spiral, count => counter}}},
{sm_presence_subscription, #{host_type => HostType},
#{metrics => #{subscription_count => spiral, unsubscription_count => spiral}}},
{sm_message_bounced, #{host_type => HostType},
#{metrics => #{count => spiral}}}].

global_probes() ->
[{sm_total_sessions, #{},
#{probe => #{module => mongoose_instrument_probe_total_sessions},
metrics => #{count => gauge}}},
{sm_unique_sessions, #{},
#{probe => #{module => mongoose_instrument_probe_unique_sessions},
metrics => #{count => gauge}}},
{sm_node_sessions, #{},
#{probe => #{module => mongoose_instrument_probe_node_sessions},
metrics => #{count => gauge}}}].
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%==============================================================================
-module(mongoose_metrics_probe_node_sessions).
-module(mongoose_instrument_probe_node_sessions).
-behaviour(mongoose_instrument_probe).

-export([probe/2]).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%==============================================================================
-module(mongoose_metrics_probe_total_sessions).
-module(mongoose_instrument_probe_total_sessions).
-behaviour(mongoose_instrument_probe).

-export([probe/2]).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%==============================================================================
-module(mongoose_metrics_probe_unique_sessions).
-module(mongoose_instrument_probe_unique_sessions).
-behaviour(mongoose_instrument_probe).

-export([probe/2]).
Expand Down

0 comments on commit bf2e07b

Please sign in to comment.