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).
|
||||
|
||||
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.
|
||||
|
||||
do_inc_action_metrics(
|
||||
|
|
|
@ -104,7 +104,6 @@ apply_rule_environment() -> #{}.
|
|||
|
||||
-spec test(#{sql := binary(), context := map()}) -> {ok, map() | list()} | {error, term()}.
|
||||
test(#{sql := Sql, context := Context}) ->
|
||||
x:show(context, Context),
|
||||
case emqx_rule_sqlparser:parse(Sql) of
|
||||
{ok, Select} ->
|
||||
InTopic = get_in_topic(Context),
|
||||
|
|
|
@ -419,13 +419,10 @@ t_apply_rule_test_format_action_failed(_Config) ->
|
|||
<<"name">> := _,
|
||||
<<"type">> := <<"rule_engine_test">>
|
||||
},
|
||||
<<"client_ids">> := [],
|
||||
<<"clientid">> := _,
|
||||
<<"reason">> := <<"MY REASON">>,
|
||||
<<"rule_id">> := _,
|
||||
<<"rule_ids">> := [],
|
||||
<<"rule_trigger_time">> := _,
|
||||
<<"rule_trigger_times">> := [],
|
||||
<<"stop_action_after_render">> := false,
|
||||
<<"trace_tag">> := <<"ACTION">>
|
||||
},
|
||||
|
@ -433,7 +430,11 @@ t_apply_rule_test_format_action_failed(_Config) ->
|
|||
<<"time">> := _
|
||||
},
|
||||
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,
|
||||
do_apply_rule_test_format_action_failed_test(1, CheckFun).
|
||||
|
||||
|
|
Loading…
Reference in New Issue