Merge pull request #9674 from thalesmg/reset-rule-metrics-on-disable-v50

chore(rule_engine): reset metrics when disabling a rule
This commit is contained in:
Thales Macedo Garitezi 2023-01-04 13:30:39 -03:00 committed by GitHub
commit 86a4ac87a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 2 deletions

View File

@ -2,7 +2,7 @@
{application, emqx_rule_engine, [
{description, "EMQX Rule Engine"},
% strict semver, bump manually!
{vsn, "5.0.6"},
{vsn, "5.0.7"},
{modules, []},
{registered, [emqx_rule_engine_sup, emqx_rule_engine]},
{applications, [kernel, stdlib, rulesql, getopt]},

View File

@ -268,7 +268,7 @@ load_hooks_for_rule(#{from := Topics}) ->
maybe_add_metrics_for_rule(Id) ->
case emqx_metrics_worker:has_metrics(rule_metrics, Id) of
true ->
ok;
ok = reset_metrics_for_rule(Id);
false ->
ok = emqx_metrics_worker:create_metrics(rule_metrics, Id, ?METRICS, ?RATE_METRICS)
end.

View File

@ -189,6 +189,38 @@ t_list_rule_api(_Config) ->
?assertEqual(maps:get(data, Result1), maps:get(data, Result6)),
ok.
t_reset_metrics_on_disable(_Config) ->
Params = #{
<<"description">> => <<"A simple rule">>,
<<"enable">> => true,
<<"actions">> => [#{<<"function">> => <<"console">>}],
<<"sql">> => <<"SELECT * from \"t/1\"">>,
<<"name">> => atom_to_binary(?FUNCTION_NAME)
},
{201, #{id := RuleId}} = emqx_rule_engine_api:'/rules'(post, #{body => Params}),
%% generate some fake metrics
emqx_metrics_worker:inc(rule_metrics, RuleId, 'matched', 10),
emqx_metrics_worker:inc(rule_metrics, RuleId, 'passed', 10),
{200, #{metrics := Metrics0}} = emqx_rule_engine_api:'/rules/:id/metrics'(
get,
#{bindings => #{id => RuleId}}
),
?assertMatch(#{passed := 10, matched := 10}, Metrics0),
%% disable the rule; metrics should be reset
{200, _Rule2} = emqx_rule_engine_api:'/rules/:id'(put, #{
bindings => #{id => RuleId},
body => Params#{<<"enable">> := false}
}),
{200, #{metrics := Metrics1}} = emqx_rule_engine_api:'/rules/:id/metrics'(
get,
#{bindings => #{id => RuleId}}
),
?assertMatch(#{passed := 0, matched := 0}, Metrics1),
ok.
test_rule_params() ->
#{
body => #{

View File

@ -9,6 +9,8 @@
- Obfuscated sensitive data in the response when querying `bridges` information by API [#9593](https://github.com/emqx/emqx/pull/9593/).
- Made rule engine behavior more consistent with bridge behavior regarding metrics: if a rule engine is disabled, its metrics are now reset []().
## Bug Fixes
- Fix an issue where testing the GCP PubSub could leak memory, and an issue where its JWT token would fail to refresh a second time. [#9641](https://github.com/emqx/emqx/pull/9641)

View File

@ -9,6 +9,8 @@
- 通过 API 查询 `bridges` 信息时将混淆响应中的敏感数据 [#9593](https://github.com/emqx/emqx/pull/9593/)。
- 使得规则引擎的行为与桥梁的指标行为更加一致:如果一个规则引擎被禁用,其指标现在会被重置 []()。
## 修复
- 修复了测试GCP PubSub可能泄露内存的问题以及其JWT令牌第二次刷新失败的问题。 [#9640](https://github.com/emqx/emqx/pull/9640)