fix(rule trace): do not leak trace meta data when tracing action result
Fixes: https://emqx.atlassian.net/browse/EMQX-12391
This commit is contained in:
parent
ed16e678be
commit
2209b26fa5
|
@ -740,7 +740,20 @@ nested_put(Alias, Val, Columns0) ->
|
||||||
emqx_rule_maps:nested_put(Alias, Val, Columns).
|
emqx_rule_maps:nested_put(Alias, Val, Columns).
|
||||||
|
|
||||||
inc_action_metrics(TraceCtx, Result) ->
|
inc_action_metrics(TraceCtx, Result) ->
|
||||||
_ = do_inc_action_metrics(TraceCtx, Result),
|
SavedMetaData = logger:get_process_metadata(),
|
||||||
|
try
|
||||||
|
%% To not pollute the trace we temporary remove the process meta data
|
||||||
|
logger:unset_process_metadata(),
|
||||||
|
_ = do_inc_action_metrics(TraceCtx, Result)
|
||||||
|
after
|
||||||
|
%% Setting process metadata to undefined yields an error
|
||||||
|
case SavedMetaData of
|
||||||
|
undefined ->
|
||||||
|
ok;
|
||||||
|
_ ->
|
||||||
|
logger:set_process_metadata(SavedMetaData)
|
||||||
|
end
|
||||||
|
end,
|
||||||
Result.
|
Result.
|
||||||
|
|
||||||
do_inc_action_metrics(
|
do_inc_action_metrics(
|
||||||
|
|
|
@ -104,7 +104,6 @@ apply_rule_environment() -> #{}.
|
||||||
|
|
||||||
-spec test(#{sql := binary(), context := map()}) -> {ok, map() | list()} | {error, term()}.
|
-spec test(#{sql := binary(), context := map()}) -> {ok, map() | list()} | {error, term()}.
|
||||||
test(#{sql := Sql, context := Context}) ->
|
test(#{sql := Sql, context := Context}) ->
|
||||||
x:show(context, Context),
|
|
||||||
case emqx_rule_sqlparser:parse(Sql) of
|
case emqx_rule_sqlparser:parse(Sql) of
|
||||||
{ok, Select} ->
|
{ok, Select} ->
|
||||||
InTopic = get_in_topic(Context),
|
InTopic = get_in_topic(Context),
|
||||||
|
|
|
@ -419,13 +419,10 @@ t_apply_rule_test_format_action_failed(_Config) ->
|
||||||
<<"name">> := _,
|
<<"name">> := _,
|
||||||
<<"type">> := <<"rule_engine_test">>
|
<<"type">> := <<"rule_engine_test">>
|
||||||
},
|
},
|
||||||
<<"client_ids">> := [],
|
|
||||||
<<"clientid">> := _,
|
<<"clientid">> := _,
|
||||||
<<"reason">> := <<"MY REASON">>,
|
<<"reason">> := <<"MY REASON">>,
|
||||||
<<"rule_id">> := _,
|
<<"rule_id">> := _,
|
||||||
<<"rule_ids">> := [],
|
|
||||||
<<"rule_trigger_time">> := _,
|
<<"rule_trigger_time">> := _,
|
||||||
<<"rule_trigger_times">> := [],
|
|
||||||
<<"stop_action_after_render">> := false,
|
<<"stop_action_after_render">> := false,
|
||||||
<<"trace_tag">> := <<"ACTION">>
|
<<"trace_tag">> := <<"ACTION">>
|
||||||
},
|
},
|
||||||
|
@ -433,7 +430,11 @@ t_apply_rule_test_format_action_failed(_Config) ->
|
||||||
<<"time">> := _
|
<<"time">> := _
|
||||||
},
|
},
|
||||||
LastEntryJSON
|
LastEntryJSON
|
||||||
)
|
),
|
||||||
|
MetaMap = maps:get(<<"meta">>, LastEntryJSON),
|
||||||
|
?assert(not maps:is_key(<<"client_ids">>, MetaMap)),
|
||||||
|
?assert(not maps:is_key(<<"rule_ids">>, MetaMap)),
|
||||||
|
?assert(not maps:is_key(<<"rule_trigger_times">>, MetaMap))
|
||||||
end,
|
end,
|
||||||
do_apply_rule_test_format_action_failed_test(1, CheckFun).
|
do_apply_rule_test_format_action_failed_test(1, CheckFun).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue