fix: rename the rule metrics
This commit is contained in:
parent
d1ffba7ff4
commit
c98fd04f8f
|
@ -645,14 +645,14 @@ t_ingress_mqtt_bridge_with_rules(_) ->
|
|||
#{
|
||||
<<"id">> := RuleId,
|
||||
<<"metrics">> := #{
|
||||
<<"sql.matched">> := 1,
|
||||
<<"sql.passed">> := 1,
|
||||
<<"sql.failed">> := 0,
|
||||
<<"sql.failed.exception">> := 0,
|
||||
<<"sql.failed.no_result">> := 0,
|
||||
<<"sql.matched.rate">> := _,
|
||||
<<"sql.matched.rate.max">> := _,
|
||||
<<"sql.matched.rate.last5m">> := _,
|
||||
<<"matched">> := 1,
|
||||
<<"passed">> := 1,
|
||||
<<"failed">> := 0,
|
||||
<<"failed.exception">> := 0,
|
||||
<<"failed.no_result">> := 0,
|
||||
<<"matched.rate">> := _,
|
||||
<<"matched.rate.max">> := _,
|
||||
<<"matched.rate.last5m">> := _,
|
||||
<<"outputs.total">> := 1,
|
||||
<<"outputs.success">> := 1,
|
||||
<<"outputs.failed">> := 0,
|
||||
|
@ -752,14 +752,14 @@ t_egress_mqtt_bridge_with_rules(_) ->
|
|||
#{
|
||||
<<"id">> := RuleId,
|
||||
<<"metrics">> := #{
|
||||
<<"sql.matched">> := 1,
|
||||
<<"sql.passed">> := 1,
|
||||
<<"sql.failed">> := 0,
|
||||
<<"sql.failed.exception">> := 0,
|
||||
<<"sql.failed.no_result">> := 0,
|
||||
<<"sql.matched.rate">> := _,
|
||||
<<"sql.matched.rate.max">> := _,
|
||||
<<"sql.matched.rate.last5m">> := _,
|
||||
<<"matched">> := 1,
|
||||
<<"passed">> := 1,
|
||||
<<"failed">> := 0,
|
||||
<<"failed.exception">> := 0,
|
||||
<<"failed.no_result">> := 0,
|
||||
<<"matched.rate">> := _,
|
||||
<<"matched.rate.max">> := _,
|
||||
<<"matched.rate.last5m">> := _,
|
||||
<<"outputs.total">> := 1,
|
||||
<<"outputs.success">> := 1,
|
||||
<<"outputs.failed">> := 0,
|
||||
|
|
|
@ -453,7 +453,7 @@ emqx_rule_api_schema {
|
|||
|
||||
metrics_outputs_total {
|
||||
desc {
|
||||
en: "How much times the outputs are called by the rule. This value may several times of 'sql.matched', depending on the number of the outputs of the rule."
|
||||
en: "How much times the outputs are called by the rule. This value may several times of 'matched', depending on the number of the outputs of the rule."
|
||||
zh: "规则调用输出的次数。 该值可能是“sql.matched”的几倍,具体取决于规则输出的数量。"
|
||||
}
|
||||
label: {
|
||||
|
|
|
@ -103,24 +103,24 @@ fields("rule_test") ->
|
|||
];
|
||||
fields("metrics") ->
|
||||
[
|
||||
{"sql.matched",
|
||||
{"matched",
|
||||
sc(non_neg_integer(), #{
|
||||
desc => ?DESC("metrics_sql_matched")
|
||||
})},
|
||||
{"sql.matched.rate", sc(float(), #{desc => ?DESC("metrics_sql_matched_rate")})},
|
||||
{"sql.matched.rate.max", sc(float(), #{desc => ?DESC("metrics_sql_matched_rate_max")})},
|
||||
{"sql.matched.rate.last5m",
|
||||
{"matched.rate", sc(float(), #{desc => ?DESC("metrics_sql_matched_rate")})},
|
||||
{"matched.rate.max", sc(float(), #{desc => ?DESC("metrics_sql_matched_rate_max")})},
|
||||
{"matched.rate.last5m",
|
||||
sc(
|
||||
float(),
|
||||
#{desc => ?DESC("metrics_sql_matched_rate_last5m")}
|
||||
)},
|
||||
{"sql.passed", sc(non_neg_integer(), #{desc => ?DESC("metrics_sql_passed")})},
|
||||
{"sql.failed", sc(non_neg_integer(), #{desc => ?DESC("metrics_sql_failed")})},
|
||||
{"sql.failed.exception",
|
||||
{"passed", sc(non_neg_integer(), #{desc => ?DESC("metrics_sql_passed")})},
|
||||
{"failed", sc(non_neg_integer(), #{desc => ?DESC("metrics_sql_failed")})},
|
||||
{"failed.exception",
|
||||
sc(non_neg_integer(), #{
|
||||
desc => ?DESC("metrics_sql_failed_exception")
|
||||
})},
|
||||
{"sql.failed.unknown",
|
||||
{"failed.unknown",
|
||||
sc(non_neg_integer(), #{
|
||||
desc => ?DESC("metrics_sql_failed_unknown")
|
||||
})},
|
||||
|
|
|
@ -83,11 +83,11 @@
|
|||
%% NOTE: This order cannot be changed! This is to make the metric working during relup.
|
||||
%% Append elements to this list to add new metrics.
|
||||
-define(METRICS, [
|
||||
'sql.matched',
|
||||
'sql.passed',
|
||||
'sql.failed',
|
||||
'sql.failed.exception',
|
||||
'sql.failed.no_result',
|
||||
'matched',
|
||||
'passed',
|
||||
'failed',
|
||||
'failed.exception',
|
||||
'failed.no_result',
|
||||
'outputs.total',
|
||||
'outputs.success',
|
||||
'outputs.failed',
|
||||
|
@ -95,7 +95,7 @@
|
|||
'outputs.failed.unknown'
|
||||
]).
|
||||
|
||||
-define(RATE_METRICS, ['sql.matched']).
|
||||
-define(RATE_METRICS, ['matched']).
|
||||
|
||||
config_key_path() ->
|
||||
[rule_engine, rules].
|
||||
|
|
|
@ -60,19 +60,19 @@ end).
|
|||
RATE_5
|
||||
),
|
||||
#{
|
||||
'sql.matched' => MATCH,
|
||||
'sql.passed' => PASS,
|
||||
'sql.failed' => FAIL,
|
||||
'sql.failed.exception' => FAIL_EX,
|
||||
'sql.failed.no_result' => FAIL_NORES,
|
||||
'matched' => MATCH,
|
||||
'passed' => PASS,
|
||||
'failed' => FAIL,
|
||||
'failed.exception' => FAIL_EX,
|
||||
'failed.no_result' => FAIL_NORES,
|
||||
'outputs.total' => O_TOTAL,
|
||||
'outputs.failed' => O_FAIL,
|
||||
'outputs.failed.out_of_service' => O_FAIL_OOS,
|
||||
'outputs.failed.unknown' => O_FAIL_UNKNOWN,
|
||||
'outputs.success' => O_SUCC,
|
||||
'sql.matched.rate' => RATE,
|
||||
'sql.matched.rate.max' => RATE_MAX,
|
||||
'sql.matched.rate.last5m' => RATE_5
|
||||
'matched.rate' => RATE,
|
||||
'matched.rate.max' => RATE_MAX,
|
||||
'matched.rate.last5m' => RATE_5
|
||||
}
|
||||
).
|
||||
-define(metrics(
|
||||
|
@ -91,19 +91,19 @@ end).
|
|||
RATE_5
|
||||
),
|
||||
#{
|
||||
'sql.matched' := MATCH,
|
||||
'sql.passed' := PASS,
|
||||
'sql.failed' := FAIL,
|
||||
'sql.failed.exception' := FAIL_EX,
|
||||
'sql.failed.no_result' := FAIL_NORES,
|
||||
'matched' := MATCH,
|
||||
'passed' := PASS,
|
||||
'failed' := FAIL,
|
||||
'failed.exception' := FAIL_EX,
|
||||
'failed.no_result' := FAIL_NORES,
|
||||
'outputs.total' := O_TOTAL,
|
||||
'outputs.failed' := O_FAIL,
|
||||
'outputs.failed.out_of_service' := O_FAIL_OOS,
|
||||
'outputs.failed.unknown' := O_FAIL_UNKNOWN,
|
||||
'outputs.success' := O_SUCC,
|
||||
'sql.matched.rate' := RATE,
|
||||
'sql.matched.rate.max' := RATE_MAX,
|
||||
'sql.matched.rate.last5m' := RATE_5
|
||||
'matched.rate' := RATE,
|
||||
'matched.rate.max' := RATE_MAX,
|
||||
'matched.rate.last5m' := RATE_5
|
||||
}
|
||||
).
|
||||
|
||||
|
@ -406,11 +406,11 @@ get_rule_metrics(Id) ->
|
|||
#{
|
||||
counters :=
|
||||
#{
|
||||
'sql.matched' := Matched,
|
||||
'sql.passed' := Passed,
|
||||
'sql.failed' := Failed,
|
||||
'sql.failed.exception' := FailedEx,
|
||||
'sql.failed.no_result' := FailedNoRes,
|
||||
'matched' := Matched,
|
||||
'passed' := Passed,
|
||||
'failed' := Failed,
|
||||
'failed.exception' := FailedEx,
|
||||
'failed.no_result' := FailedNoRes,
|
||||
'outputs.total' := OTotal,
|
||||
'outputs.failed' := OFailed,
|
||||
'outputs.failed.out_of_service' := OFailedOOS,
|
||||
|
@ -419,7 +419,7 @@ get_rule_metrics(Id) ->
|
|||
},
|
||||
rate :=
|
||||
#{
|
||||
'sql.matched' :=
|
||||
'matched' :=
|
||||
#{current := Current, max := Max, last5m := Last5M}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,14 +64,14 @@ apply_rule_discard_result(Rule, Input) ->
|
|||
ok.
|
||||
|
||||
apply_rule(Rule = #{id := RuleID}, Input) ->
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleID, 'sql.matched'),
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleID, 'matched'),
|
||||
clear_rule_payload(),
|
||||
try
|
||||
do_apply_rule(Rule, add_metadata(Input, #{rule_id => RuleID}))
|
||||
catch
|
||||
%% ignore the errors if select or match failed
|
||||
_:Reason = {select_and_transform_error, Error} ->
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleID, 'sql.failed.exception'),
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleID, 'failed.exception'),
|
||||
?SLOG(warning, #{
|
||||
msg => "SELECT_clause_exception",
|
||||
rule_id => RuleID,
|
||||
|
@ -79,7 +79,7 @@ apply_rule(Rule = #{id := RuleID}, Input) ->
|
|||
}),
|
||||
{error, Reason};
|
||||
_:Reason = {match_conditions_error, Error} ->
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleID, 'sql.failed.exception'),
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleID, 'failed.exception'),
|
||||
?SLOG(warning, #{
|
||||
msg => "WHERE_clause_exception",
|
||||
rule_id => RuleID,
|
||||
|
@ -87,7 +87,7 @@ apply_rule(Rule = #{id := RuleID}, Input) ->
|
|||
}),
|
||||
{error, Reason};
|
||||
_:Reason = {select_and_collect_error, Error} ->
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleID, 'sql.failed.exception'),
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleID, 'failed.exception'),
|
||||
?SLOG(warning, #{
|
||||
msg => "FOREACH_clause_exception",
|
||||
rule_id => RuleID,
|
||||
|
@ -95,7 +95,7 @@ apply_rule(Rule = #{id := RuleID}, Input) ->
|
|||
}),
|
||||
{error, Reason};
|
||||
_:Reason = {match_incase_error, Error} ->
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleID, 'sql.failed.exception'),
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleID, 'failed.exception'),
|
||||
?SLOG(warning, #{
|
||||
msg => "INCASE_clause_exception",
|
||||
rule_id => RuleID,
|
||||
|
@ -103,7 +103,7 @@ apply_rule(Rule = #{id := RuleID}, Input) ->
|
|||
}),
|
||||
{error, Reason};
|
||||
Class:Error:StkTrace ->
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleID, 'sql.failed.exception'),
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleID, 'failed.exception'),
|
||||
?SLOG(error, #{
|
||||
msg => "apply_rule_failed",
|
||||
rule_id => RuleID,
|
||||
|
@ -141,13 +141,13 @@ do_apply_rule(
|
|||
Collection2 = filter_collection(Input, InCase, DoEach, Collection),
|
||||
case Collection2 of
|
||||
[] ->
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleId, 'sql.failed.no_result');
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleId, 'failed.no_result');
|
||||
_ ->
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleId, 'sql.passed')
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleId, 'passed')
|
||||
end,
|
||||
{ok, [handle_output_list(RuleId, Outputs, Coll, Input) || Coll <- Collection2]};
|
||||
false ->
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleId, 'sql.failed.no_result'),
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleId, 'failed.no_result'),
|
||||
{error, nomatch}
|
||||
end;
|
||||
do_apply_rule(
|
||||
|
@ -171,10 +171,10 @@ do_apply_rule(
|
|||
)
|
||||
of
|
||||
true ->
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleId, 'sql.passed'),
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleId, 'passed'),
|
||||
{ok, handle_output_list(RuleId, Outputs, Selected, Input)};
|
||||
false ->
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleId, 'sql.failed.no_result'),
|
||||
ok = emqx_metrics_worker:inc(rule_metrics, RuleId, 'failed.no_result'),
|
||||
{error, nomatch}
|
||||
end.
|
||||
|
||||
|
|
Loading…
Reference in New Issue