fix(redis trace): add separators in redis batch action trace
Logger will transform data that looks like IO data into a string which made redis batch traces look like the spaces had been removed from the strings. To prevent this, we render the batched commands into binary string separated by spaces and semicolon. The components of a single command is separated by spaces and the commands in a batch are separated by semicolons. Fixes: https://emqx.atlassian.net/browse/EMQX-12428
This commit is contained in:
parent
40080f5e7d
commit
cbdde7165e
|
@ -6,6 +6,7 @@
|
|||
-include_lib("emqx/include/logger.hrl").
|
||||
-include_lib("emqx_resource/include/emqx_resource.hrl").
|
||||
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||
-include_lib("emqx/include/emqx_trace.hrl").
|
||||
|
||||
-behaviour(emqx_resource).
|
||||
|
||||
|
@ -143,7 +144,13 @@ on_batch_query(
|
|||
[{ChannelID, _} | _] = BatchData,
|
||||
emqx_trace:rendered_action_template(
|
||||
ChannelID,
|
||||
#{commands => Cmds, batch => ture}
|
||||
#{
|
||||
commands => #emqx_trace_format_func_data{
|
||||
function = fun trace_format_commands/1,
|
||||
data = Cmds
|
||||
},
|
||||
batch => true
|
||||
}
|
||||
),
|
||||
Result = query(InstId, {cmds, Cmds}, RedisConnSt),
|
||||
?tp(
|
||||
|
@ -162,6 +169,11 @@ on_batch_query(
|
|||
Error
|
||||
end.
|
||||
|
||||
trace_format_commands(Commands0) ->
|
||||
Commands1 = [[unicode:characters_to_list(S) || S <- C] || C <- Commands0],
|
||||
Commands2 = [lists:join(" ", C) || C <- Commands1],
|
||||
unicode:characters_to_binary(lists:join("; ", Commands2)).
|
||||
|
||||
on_format_query_result({ok, Msg}) ->
|
||||
#{result => ok, message => Msg};
|
||||
on_format_query_result(Res) ->
|
||||
|
|
Loading…
Reference in New Issue