Skip to content

Commit

Permalink
Merge pull request #140 from Feuerlabs/uw-function-metrics
Browse files Browse the repository at this point in the history
Fix bugs in exometer_core function metrics
  • Loading branch information
uwiger committed Nov 12, 2021
2 parents ae40904 + f445f92 commit 66c287e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/exometer_function.erl
Expand Up @@ -249,7 +249,12 @@ actual_datapoints(DPs, default, histogram) ->
actual_datapoints(DPs, exometer_histogram:datapoints(), histogram);
actual_datapoints(default, DPs, _) ->
DPs;
actual_datapoints(DPs0, {Exprs, DPs}, eval) ->
{Exprs, datapoints_subset(DPs0, DPs)};
actual_datapoints(DPs0, DPs, _) ->
datapoints_subset(DPs0, DPs).

datapoints_subset(DPs0, DPs) ->
[D || D <- datapoints(DPs0, DPs),
lists:member(D, DPs)].

Expand Down Expand Up @@ -543,11 +548,12 @@ eval_exprs([E|Es], _, Bs) ->
eval_({erl, Exprs}, Bs) ->
erl_eval:exprs(Exprs, Bs);
eval_({T, P, E}, Bs) when T==m; T==match ->
Val = e(E, Bs),
{value, Val, match(P, Val, Bs)};
{value, Val, Bs1} = eval_(E, Bs),
{value, Val, match(P, Val, Bs1)};
eval_({'case', Es, Cls}, Bs) ->
{value, V, _} = eval_exprs(Es, Bs),
case_clauses(Cls, V, Bs);
{value, V, Bs1} = eval_exprs(Es, Bs),
{value, Res, _} = case_clauses(Cls, V, Bs),
{value, Res, Bs1};
eval_(Expr, Bs) -> {value, e(Expr, Bs), Bs}.

e({T,V}, Bs) when T==v; T==var ->
Expand Down
25 changes: 25 additions & 0 deletions test/exometer_SUITE.erl
Expand Up @@ -24,6 +24,7 @@
test_gauge/1,
test_fast_counter/1,
test_crashing_function/1,
test_eval_script_match_case/1,
test_wrapping_counter/1,
test_update_or_create/1,
test_update_or_create2/1,
Expand Down Expand Up @@ -80,6 +81,7 @@ groups() ->
test_gauge,
test_fast_counter,
test_crashing_function,
test_eval_script_match_case,
test_wrapping_counter
]},
{test_defaults, [shuffle],
Expand Down Expand Up @@ -238,6 +240,29 @@ test_crashing_function(_Config) ->
{ok, {error, unavailable}} = exometer:get_value(C2, [value]),
ok.

%% Test running a script containing the pattern K = case X of ... end.
test_eval_script_match_case(_Config) ->
C = [?MODULE, eval, ?LINE],
ok = exometer:new(C,{function,erlang,memory,[],
eval,
{[{fold,'X','Y',
[{m,{v,'K'},
{'case',[{v,'X'}],
[{{a,bin},[],
[{a,binary}]},
{{v,'_'},[],
[{v,'X'}]}]}},
{cons,{t,[{v,'X'},{call,{proplists,get_value},
[{v,'K'},{v,'Value'}]}]},
{v,'Y'}}],nil,{v,'DPs'}}],
[bin,atom]}}),
{ok, Res1} = exometer:get_value(C),
[{atom,Va},{bin,Vb}] = lists:sort(Res1),
true = lists:all(fun is_integer/1, [Va, Vb]),
{ok, [{bin, _}]} = exometer:get_value(C, bin),
{ok, [{bin, _}]} = exometer:get_value(C, [bin]),
ok.

test_wrapping_counter(_Config) ->
C = [?MODULE, ctr, ?LINE],
ok = exometer:new(C, counter, []),
Expand Down

0 comments on commit 66c287e

Please sign in to comment.