浏览代码

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
Kjell Winblad 1 年之前
父节点
当前提交
cbdde7165e
共有 1 个文件被更改,包括 13 次插入1 次删除
  1. 13 1
      apps/emqx_bridge_redis/src/emqx_bridge_redis_connector.erl

+ 13 - 1
apps/emqx_bridge_redis/src/emqx_bridge_redis_connector.erl

@@ -6,6 +6,7 @@
 -include_lib("emqx/include/logger.hrl").
 -include_lib("emqx/include/logger.hrl").
 -include_lib("emqx_resource/include/emqx_resource.hrl").
 -include_lib("emqx_resource/include/emqx_resource.hrl").
 -include_lib("snabbkaffe/include/snabbkaffe.hrl").
 -include_lib("snabbkaffe/include/snabbkaffe.hrl").
+-include_lib("emqx/include/emqx_trace.hrl").
 
 
 -behaviour(emqx_resource).
 -behaviour(emqx_resource).
 
 
@@ -143,7 +144,13 @@ on_batch_query(
             [{ChannelID, _} | _] = BatchData,
             [{ChannelID, _} | _] = BatchData,
             emqx_trace:rendered_action_template(
             emqx_trace:rendered_action_template(
                 ChannelID,
                 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),
             Result = query(InstId, {cmds, Cmds}, RedisConnSt),
             ?tp(
             ?tp(
@@ -162,6 +169,11 @@ on_batch_query(
             Error
             Error
     end.
     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}) ->
 on_format_query_result({ok, Msg}) ->
     #{result => ok, message => Msg};
     #{result => ok, message => Msg};
 on_format_query_result(Res) ->
 on_format_query_result(Res) ->