fix(json trace format): format client_ids and rule_ids as lists
This commit is contained in:
parent
10957e7d79
commit
aa388adba9
|
@ -53,7 +53,7 @@ prepare_key_value(payload = K, V, PEncode) ->
|
|||
try
|
||||
format_payload(V, PEncode)
|
||||
catch
|
||||
_:_:_ ->
|
||||
_:_ ->
|
||||
V
|
||||
end,
|
||||
{K, NewV};
|
||||
|
@ -62,7 +62,25 @@ prepare_key_value(packet = K, V, PEncode) ->
|
|||
try
|
||||
format_packet(V, PEncode)
|
||||
catch
|
||||
_:_:_ ->
|
||||
_:_ ->
|
||||
V
|
||||
end,
|
||||
{K, NewV};
|
||||
prepare_key_value(rule_ids = K, V, _PEncode) ->
|
||||
NewV =
|
||||
try
|
||||
format_map_set_to_list(V)
|
||||
catch
|
||||
_:_ ->
|
||||
V
|
||||
end,
|
||||
{K, NewV};
|
||||
prepare_key_value(client_ids = K, V, _PEncode) ->
|
||||
NewV =
|
||||
try
|
||||
format_map_set_to_list(V)
|
||||
catch
|
||||
_:_ ->
|
||||
V
|
||||
end,
|
||||
{K, NewV};
|
||||
|
@ -83,3 +101,16 @@ format_payload(Payload, text) when ?MAX_PAYLOAD_FORMAT_LIMIT(Payload) ->
|
|||
format_payload(Payload, hex) when ?MAX_PAYLOAD_FORMAT_LIMIT(Payload) -> binary:encode_hex(Payload);
|
||||
format_payload(<<Part:?TRUNCATED_PAYLOAD_SIZE/binary, _/binary>> = Payload, Type) ->
|
||||
emqx_packet:format_truncated_payload(Part, byte_size(Payload), Type).
|
||||
|
||||
format_map_set_to_list(Map) ->
|
||||
Items = [
|
||||
begin
|
||||
%% Assert that it is really a map set
|
||||
true = V,
|
||||
%% Assert that the keys have the expected type
|
||||
true = is_binary(K),
|
||||
K
|
||||
end
|
||||
|| {K, V} <- maps:to_list(Map)
|
||||
],
|
||||
lists:sort(Items).
|
||||
|
|
|
@ -254,6 +254,15 @@ t_http_test_json_formatter(_Config) ->
|
|||
{<<"key2">>, <<"value2">>}
|
||||
]
|
||||
}),
|
||||
%% We do special formatting for client_ids and rule_ids
|
||||
?TRACE("CUSTOM", "my_log_msg", #{
|
||||
topic => Topic,
|
||||
client_ids => maps:from_keys([<<"a">>, <<"b">>, <<"c">>], true)
|
||||
}),
|
||||
?TRACE("CUSTOM", "my_log_msg", #{
|
||||
topic => Topic,
|
||||
rule_ids => maps:from_keys([<<"a">>, <<"b">>, <<"c">>], true)
|
||||
}),
|
||||
ok = emqx_trace_handler_SUITE:filesync(Name, topic),
|
||||
{ok, _Detail2} = request_api(get, api_path("trace/" ++ binary_to_list(Name) ++ "/log_detail")),
|
||||
{ok, Bin} = request_api(get, api_path("trace/" ++ binary_to_list(Name) ++ "/download")),
|
||||
|
@ -301,6 +310,16 @@ t_http_test_json_formatter(_Config) ->
|
|||
<<"key2">> := <<"value2">>
|
||||
}
|
||||
}
|
||||
},
|
||||
#{
|
||||
<<"meta">> := #{
|
||||
<<"client_ids">> := [<<"a">>, <<"b">>, <<"c">>]
|
||||
}
|
||||
},
|
||||
#{
|
||||
<<"meta">> := #{
|
||||
<<"rule_ids">> := [<<"a">>, <<"b">>, <<"c">>]
|
||||
}
|
||||
}
|
||||
| _
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue