feat: pass along peername down to transformation context

This commit is contained in:
Thales Macedo Garitezi 2024-06-10 14:48:24 -03:00
parent 6e0ef893f4
commit d93c8540c8
3 changed files with 21 additions and 5 deletions

View File

@ -684,7 +684,10 @@ process_publish(Packet = ?PUBLISH_PACKET(QoS, Topic, PacketId), Channel) ->
end. end.
packet_to_message(Packet, #channel{ packet_to_message(Packet, #channel{
conninfo = #{proto_ver := ProtoVer}, conninfo = #{
peername := PeerName,
proto_ver := ProtoVer
},
clientinfo = clientinfo =
#{ #{
protocol := Protocol, protocol := Protocol,
@ -702,6 +705,7 @@ packet_to_message(Packet, #channel{
ClientId, ClientId,
#{ #{
client_attrs => ClientAttrs, client_attrs => ClientAttrs,
peername => PeerName,
proto_ver => ProtoVer, proto_ver => ProtoVer,
protocol => Protocol, protocol => Protocol,
username => Username, username => Username,

View File

@ -1095,8 +1095,20 @@ t_multiple_transformations(_Config) ->
?assertMatch( ?assertMatch(
[ [
{_, #{data := #{transformation := Name1, event := 'message.transformation_failed'}}}, {_, #{
{_, #{data := #{transformation := Name2, event := 'message.transformation_failed'}}} data := #{
transformation := Name1,
event := 'message.transformation_failed',
peername := <<_/binary>>
}
}},
{_, #{
data := #{
transformation := Name2,
event := 'message.transformation_failed',
peername := <<_/binary>>
}
}}
], ],
get_traced_failures_from_rule_engine() get_traced_failures_from_rule_engine()
), ),

View File

@ -573,7 +573,7 @@ eventmsg_transformation_failed(
clientid => ClientId, clientid => ClientId,
username => emqx_message:get_header(username, Message, undefined), username => emqx_message:get_header(username, Message, undefined),
payload => Payload, payload => Payload,
peerhost => ntoa(emqx_message:get_header(peerhost, Message, undefined)), peername => ntoa(emqx_message:get_header(peername, Message, undefined)),
topic => Topic, topic => Topic,
qos => QoS, qos => QoS,
flags => Flags, flags => Flags,
@ -1064,7 +1064,7 @@ columns_with_exam('message.transformation_failed') ->
{<<"clientid">>, <<"c_emqx">>}, {<<"clientid">>, <<"c_emqx">>},
{<<"username">>, <<"u_emqx">>}, {<<"username">>, <<"u_emqx">>},
{<<"payload">>, <<"{\"msg\": \"hello\"}">>}, {<<"payload">>, <<"{\"msg\": \"hello\"}">>},
{<<"peerhost">>, <<"192.168.0.10">>}, {<<"peername">>, <<"192.168.0.10:56431">>},
{<<"topic">>, <<"t/a">>}, {<<"topic">>, <<"t/a">>},
{<<"qos">>, 1}, {<<"qos">>, 1},
{<<"flags">>, #{}}, {<<"flags">>, #{}},