Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace dots in "host" part of metric name with underscores. #2025

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Replace dots in "host" part of metric name with underscores.
Underscores are not a valid part of a domain name, so they
are safe to replace dots to in the metric name (i.e. this can't lead
to a collision with an existing host name).

Replacing dots with underscores prevents hosts from being treated
as multiple separate metrics nodes e.g. by Graphite and Grafana.
kzemek committed Aug 8, 2018
commit fdf98fd93b4995183c898d52ec9779a7971ff6d4
4 changes: 3 additions & 1 deletion src/mongoose_metrics.erl
Original file line number Diff line number Diff line change
@@ -174,7 +174,9 @@ pick_by_all_metrics_are_global(WhenGlobal, WhenNot) ->

-spec name_by_all_metrics_are_global(Host :: jid:lserver() | global,
Name :: list()) -> FinalName :: list().
name_by_all_metrics_are_global(Host, Name) ->
name_by_all_metrics_are_global(global, Name) -> [global | Name];
name_by_all_metrics_are_global(Host0, Name) ->
Host = binary:replace(Host0, <<$.>>, <<$_>>, [global]),
pick_by_all_metrics_are_global([global | Name], [Host | Name]).

get_report_interval() ->
9 changes: 8 additions & 1 deletion test/mongooseim_metrics_SUITE.erl
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ all() ->

groups() ->
[
{ordinary_mode, [], ?ALL_CASES},
{ordinary_mode, [], [dots_in_host_are_turned_to_underscore | ?ALL_CASES]},
{all_metrics_are_global, [], ?ALL_CASES}
].

@@ -83,6 +83,13 @@ subscriptions_initialised(_C) ->
mongoose_metrics:init(),
true = wait_for_update(exometer:get_value([carbon, packets], count), 60).

dots_in_host_are_turned_to_underscore(_C) ->
mongoose_metrics:init(),
mongoose_metrics:ensure_metric(<<"host.with.dots">>, [a, metric, value], histogram),
mongoose_metrics:update(<<"host.with.dots">>, [a, metric, value], 10),
{ok, _} = exometer:get_value([<<"host_with_dots">>, a, metric, value]).


wait_for_update({ok, [{count,X}]}, 0) ->
X > 0;
wait_for_update({ok, [{count,X}]}, _N) when X > 0 ->