Skip to content

Commit

Permalink
Merge pull request #146 from erisata/fix_name_tuples
Browse files Browse the repository at this point in the history
Metric names might be tuples, they have to be escaped in match specs.
  • Loading branch information
uwiger authored Jul 4, 2024
2 parents 0c21b16 + 52ac740 commit f65ec52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/exometer_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ find_auto_template(Name) ->
make_patterns(Type, Name) when is_list(Name) ->
Prefixes = prefixes(Name),
[{ #exometer_entry{name = {default,Type,[V || {_,V} <- Pfx]}, _ = '_'},
[{'or',{'=:=',V,X},{'=:=',V,''}} || {X,V} <- Pfx], ['$_'] }
[{'or',{'=:=',V,{const,X}},{'=:=',V,''}} || {X,V} <- Pfx], ['$_'] }
|| Pfx <- Prefixes].

prefixes(L) ->
Expand Down
14 changes: 14 additions & 0 deletions test/exometer_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
test_eval_script_match_case/1,
test_wrapping_counter/1,
test_update_or_create/1,
test_update_or_create_w_tuple_name/1,
test_update_or_create2/1,
test_default_override/1,
test_std_histogram/1,
Expand Down Expand Up @@ -84,6 +85,7 @@ groups() ->
{test_defaults, [shuffle],
[
test_update_or_create,
test_update_or_create_w_tuple_name,
test_update_or_create2,
test_default_override
]},
Expand Down Expand Up @@ -270,6 +272,18 @@ test_update_or_create(_Config) ->
counter = exometer:info(exometer_admin:find_auto_template([a,b,c]), type),
ok.

test_update_or_create_w_tuple_name(_Config) ->
N = [a,b,{c,1}],
{error, not_found} = exometer:update(N, 2),
{error, no_template} = exometer:update_or_create(N, 10),
exometer_admin:set_default(N, counter, []),
ok = exometer:update_or_create(N, 3),
{ok, [{value, 3}]} = exometer:get_value(N, [value]),
exometer_admin:set_default([a,'_',d], histogram, []),
histogram = exometer:info(exometer_admin:find_auto_template([a,{b,1},d]), type),
counter = exometer:info(exometer_admin:find_auto_template(N), type),
ok.

test_default_override(_Config) ->
E = [d,e,f],
E1 = [d,e,f,1],
Expand Down

0 comments on commit f65ec52

Please sign in to comment.