fix(metrics): counters not created before incr 'rule.matched'
This commit is contained in:
parent
c3159420bb
commit
86d20b060c
|
@ -163,7 +163,18 @@ inc(Id, Metric) ->
|
||||||
|
|
||||||
-spec inc(rule_id(), atom(), pos_integer()) -> ok.
|
-spec inc(rule_id(), atom(), pos_integer()) -> ok.
|
||||||
inc(Id, Metric, Val) ->
|
inc(Id, Metric, Val) ->
|
||||||
counters:add(couters_ref(Id), metrics_idx(Metric), Val),
|
case couters_ref(Id) of
|
||||||
|
not_found ->
|
||||||
|
%% this may occur when increasing a counter for
|
||||||
|
%% a rule that was created from a remove node.
|
||||||
|
case atom_to_list(Metric) of
|
||||||
|
"rules." ++ _ -> create_rule_metrics(Id);
|
||||||
|
_ -> create_metrics(Id)
|
||||||
|
end,
|
||||||
|
counters:add(couters_ref(Id), metrics_idx(Metric), Val);
|
||||||
|
Ref ->
|
||||||
|
counters:add(Ref, metrics_idx(Metric), Val)
|
||||||
|
end,
|
||||||
inc_overall(Metric, Val).
|
inc_overall(Metric, Val).
|
||||||
|
|
||||||
-spec(inc_overall(atom(), pos_integer()) -> ok).
|
-spec(inc_overall(atom(), pos_integer()) -> ok).
|
||||||
|
|
|
@ -34,7 +34,8 @@ groups() ->
|
||||||
[ t_action
|
[ t_action
|
||||||
, t_rule
|
, t_rule
|
||||||
, t_clear
|
, t_clear
|
||||||
, t_no_creation
|
, t_no_creation_1
|
||||||
|
, t_no_creation_2
|
||||||
]},
|
]},
|
||||||
{speed, [sequence],
|
{speed, [sequence],
|
||||||
[ rule_speed
|
[ rule_speed
|
||||||
|
@ -60,8 +61,11 @@ init_per_testcase(_, Config) ->
|
||||||
end_per_testcase(_, _Config) ->
|
end_per_testcase(_, _Config) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
t_no_creation(_) ->
|
t_no_creation_1(_) ->
|
||||||
?assertError(_, emqx_rule_metrics:inc_actions_taken(<<"action:0">>)).
|
?assertEqual(ok, emqx_rule_metrics:inc_rules_matched(<<"rule1">>)).
|
||||||
|
|
||||||
|
t_no_creation_2(_) ->
|
||||||
|
?assertEqual(ok, emqx_rule_metrics:inc_actions_taken(<<"action:0">>)).
|
||||||
|
|
||||||
t_action(_) ->
|
t_action(_) ->
|
||||||
?assertEqual(0, emqx_rule_metrics:get_actions_taken(<<"action:1">>)),
|
?assertEqual(0, emqx_rule_metrics:get_actions_taken(<<"action:1">>)),
|
||||||
|
|
Loading…
Reference in New Issue