Skip to content

Commit

Permalink
Allow mod_global_distrib to be run for multiple hosts
Browse files Browse the repository at this point in the history
The issue was uncovered by the small tests. Additionally, the instrumentation
is started correctly in these tests.

The host_type is a misnomer, as global_distrib does not work for host types -
this issue may be revisited. The other issue is that other events in
global_distrib are without any labels, as they were run with `global`, or can
be differentiated by the host value in the measurements map.
  • Loading branch information
gustawlippa committed Jun 3, 2024
1 parent 0fee622 commit 3a98440
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion big_tests/tests/mod_global_distrib_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ test_muc_conversation_history(Config0) ->

% events are checked only on mim host, the other event was executed on Eve's reg ("asia_node") host
EveJid = escalus_client:full_jid(Eve),
instrument_helper:assert(mod_global_distrib_delivered_with_ttl, #{},
instrument_helper:assert(mod_global_distrib_delivered_with_ttl, #{host_type => domain_helper:host_type()},
fun(#{ttl := TTL, from := From}) ->
?assert(TTL > 0), jid:to_binary(From) =:= EveJid
end)
Expand Down
10 changes: 5 additions & 5 deletions src/global_distrib/mod_global_distrib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ stop(HostType) ->
end.

-spec instrumentation(mongooseim:host_type()) -> [mongoose_instrument:spec()].
instrumentation(_HostType) ->
[{?GLOBAL_DISTRIB_DELIVERED_WITH_TTL, #{}, #{metrics => #{ttl => histogram}}},
{?GLOBAL_DISTRIB_STOP_TTL_ZERO, #{}, #{metrics => #{count => spiral}}}].
instrumentation(HostType) ->
[{?GLOBAL_DISTRIB_DELIVERED_WITH_TTL, #{host_type => HostType}, #{metrics => #{ttl => histogram}}},
{?GLOBAL_DISTRIB_STOP_TTL_ZERO, #{host_type => HostType}, #{metrics => #{count => spiral}}}].

hooks() ->
[{filter_packet, global, fun ?MODULE:maybe_reroute/3, #{}, 99}].
Expand Down Expand Up @@ -252,7 +252,7 @@ maybe_reroute({From, To, _, Packet} = FPacket, _, _) ->
ResultFPacket = case lookup_recipients_host(TargetHostOverride, To, LocalHost, GlobalHost) of
{ok, LocalHost} ->
{ok, TTL} = find_metadata(Acc, ttl),
mongoose_instrument:execute(?GLOBAL_DISTRIB_DELIVERED_WITH_TTL, #{}, #{ttl => TTL, from => From}),
mongoose_instrument:execute(?GLOBAL_DISTRIB_DELIVERED_WITH_TTL, #{host_type => GlobalHost}, #{ttl => TTL, from => From}),

%% Continue routing with initialized metadata
mongoose_hooks:mod_global_distrib_known_recipient(GlobalHost,
Expand All @@ -271,7 +271,7 @@ maybe_reroute({From, To, _, Packet} = FPacket, _, _) ->
?LOG_INFO(#{what => gd_route_ttl_zero,
text => <<"Skip global distribution">>,
gd_id => ID, acc => Acc, target_host => TargetHost}),
mongoose_instrument:execute(?GLOBAL_DISTRIB_STOP_TTL_ZERO, #{}, #{count => 1}),
mongoose_instrument:execute(?GLOBAL_DISTRIB_STOP_TTL_ZERO, #{host_type => GlobalHost}, #{count => 1}),

Check warning on line 274 in src/global_distrib/mod_global_distrib.erl

View check run for this annotation

Codecov / codecov/patch

src/global_distrib/mod_global_distrib.erl#L274

Added line #L274 was not covered by tests
FPacket;
{ok, TTL} ->
?LOG_DEBUG(#{what => gd_reroute, ttl => TTL,
Expand Down
5 changes: 4 additions & 1 deletion test/mod_global_distrib_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,24 @@ init_per_testcase(_CaseName, Config) ->
set_meck(),
mongoose_config:set_opts(opts()),
mongoose_domain_sup:start_link(),
mongoose_instrument:start_link(),
mim_ct_sup:start_link(ejabberd_sup),
mongooseim_helper:start_link_loaded_hooks(),
mongoose_modules:start(),
Config.

end_per_testcase(_CaseName, Config) ->
mongoose_modules:stop(),
mongoose_instrument:terminate(normal, []),
mongoose_config:erase_opts(),
unset_meck(),
Config.

opts() ->
maps:from_list([{hosts, hosts()},
{host_types, []},
{all_metrics_are_global, false} |
{all_metrics_are_global, false},
{instrumentation, #{probe_interval => 100}} |
[{{modules, HostType}, modules(HostType)} || HostType <- hosts()]]).

hosts() ->
Expand Down

0 comments on commit 3a98440

Please sign in to comment.