Skip to content

Commit 4f9f994

Browse files
committed
fix: automatically sanitize metric names
This allows user to define metrics in exporter-independent way and let exporter handle name unification.
1 parent e3db176 commit 4f9f994

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/oc_stat_exporter_datadog.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ build_tags(Tags) ->
5959
["|#", lists:join($,, List)].
6060

6161
to_key(Atom) when is_atom(Atom) ->
62-
erlang:atom_to_binary(Atom, utf8);
63-
to_key(Value) -> Value.
62+
sanitize(erlang:atom_to_list(Atom));
63+
to_key(Value) -> sanitize(Value).
64+
65+
sanitize(Name) ->
66+
re:replace(Name, "[^[:alpha:][:digit:]_]+", ".", [global]).
6467

6568
build_rows(Name, Type, CTags, Tags, #{tags := TagsV, value := Value}) ->
6669
TagList = build_tags(Tags, TagsV, CTags),

0 commit comments

Comments
 (0)