From cbdde7165ece1c2d11acd9a291ea310b3117a0de Mon Sep 17 00:00:00 2001 From: Kjell Winblad Date: Mon, 27 May 2024 15:36:20 +0200 Subject: [PATCH] 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 --- .../src/emqx_bridge_redis_connector.erl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/emqx_bridge_redis/src/emqx_bridge_redis_connector.erl b/apps/emqx_bridge_redis/src/emqx_bridge_redis_connector.erl index 535d6e13c..c98863f33 100644 --- a/apps/emqx_bridge_redis/src/emqx_bridge_redis_connector.erl +++ b/apps/emqx_bridge_redis/src/emqx_bridge_redis_connector.erl @@ -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) ->