Merge pull request #9226 from zmstone/1025-fix-drop-tuple-value-message-headers

fix(emqx_rule_events): do not keep tuple-value message headers
This commit is contained in:
Zaiming (Stone) Shi 2022-10-26 09:59:12 +02:00 committed by GitHub
commit f5c0ef3e56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 7 deletions

View File

@ -693,5 +693,9 @@ printable_maps(Headers) ->
value => Value value => Value
} || {Key, Value} <- V0] } || {Key, Value} <- V0]
}; };
(K, V0, AccIn) -> AccIn#{K => V0} (_K, V, AccIn) when is_tuple(V) ->
%% internal header
AccIn;
(K, V, AccIn) ->
AccIn#{K => V}
end, #{}, Headers). end, #{}, Headers).

View File

@ -22,10 +22,16 @@ t_mod_hook_fun(_) ->
t_printable_maps(_) -> t_printable_maps(_) ->
Headers = #{peerhost => {127,0,0,1}, Headers = #{peerhost => {127,0,0,1},
peername => {{127,0,0,1}, 9980}, peername => {{127,0,0,1}, 9980},
sockname => {{127,0,0,1}, 1883} sockname => {{127,0,0,1}, 1883},
redispatch_to => {<<"group">>, <<"sub/topic/+">>},
shared_dispatch_ack => {self(), ref}
}, },
Converted = emqx_rule_events:printable_maps(Headers),
?assertMatch( ?assertMatch(
#{peerhost := <<"127.0.0.1">>, #{peerhost := <<"127.0.0.1">>,
peername := <<"127.0.0.1:9980">>, peername := <<"127.0.0.1:9980">>,
sockname := <<"127.0.0.1:1883">> sockname := <<"127.0.0.1:1883">>
}, emqx_rule_events:printable_maps(Headers)). }, Converted),
?assertNot(maps:is_key(redispatch_to, Converted)),
?assertNot(maps:is_key(shared_dispatch_ack, Converted)),
ok.

View File

@ -1,4 +1,6 @@
### Enhancements # v4.3.22
## Enhancements
- Asynchronously refresh the resources and rules during emqx boot-up [#9199](https://github.com/emqx/emqx/pull/9199). - Asynchronously refresh the resources and rules during emqx boot-up [#9199](https://github.com/emqx/emqx/pull/9199).
This is to avoid slowing down the boot if some resources spend long time establishing the connection. This is to avoid slowing down the boot if some resources spend long time establishing the connection.
@ -8,7 +10,7 @@
- JWT ACL claim supports `all` action to imply the rules applie to both `pub` and `sub` [#9044](https://github.com/emqx/emqx/pull/9044). - JWT ACL claim supports `all` action to imply the rules applie to both `pub` and `sub` [#9044](https://github.com/emqx/emqx/pull/9044).
### Bug fixes ## Bug fixes
- Fix that after uploading a backup file with an UTF8 filename, HTTP API `GET /data/export` fails with status code 500 [#9224](https://github.com/emqx/emqx/pull/9224). - Fix that after uploading a backup file with an UTF8 filename, HTTP API `GET /data/export` fails with status code 500 [#9224](https://github.com/emqx/emqx/pull/9224).
@ -25,3 +27,8 @@
- Fixed the response status code for the `/status` endpoint [#9210](https://github.com/emqx/emqx/pull/9210). - Fixed the response status code for the `/status` endpoint [#9210](https://github.com/emqx/emqx/pull/9210).
Before the fix, it always returned `200` even if the EMQX application was not running. Now it returns `503` in that case. Before the fix, it always returned `200` even if the EMQX application was not running. Now it returns `503` in that case.
- Fix message delivery related event encoding [#9226](https://github.com/emqx/emqx/pull/9226)
For rule-engine's input events like `$events/message_delivered`, and `$events/message_dropped`,
if the message was delivered to a shared-subscription, the encoding (to JSON) of the event will fail.
Affected versions: `v4.3.21`, `v4.4.10`, `e4.3.16` and `e4.4.10`.

View File

@ -1,4 +1,6 @@
### 增强 # v4.3.22
## 增强
- 在 emqx 启动时,异步地刷新资源和规则 [#9199](https://github.com/emqx/emqx/pull/9199)。 - 在 emqx 启动时,异步地刷新资源和规则 [#9199](https://github.com/emqx/emqx/pull/9199)。
这个改动是为了避免因为一些资源连接建立过慢,而导致启动时间过长。 这个改动是为了避免因为一些资源连接建立过慢,而导致启动时间过长。
@ -8,7 +10,7 @@
- 基于 JWT 的 ACL 支持 `all` 动作,指定同时适用于 `pub``sub` 两个动作的规则列表 [#9044](https://github.com/emqx/emqx/pull/9044)。 - 基于 JWT 的 ACL 支持 `all` 动作,指定同时适用于 `pub``sub` 两个动作的规则列表 [#9044](https://github.com/emqx/emqx/pull/9044)。
### 修复 ## 修复
- 修复若上传的备份文件名中包含 UTF8 字符,`GET /data/export` HTTP 接口返回 500 错误 [#9224](https://github.com/emqx/emqx/pull/9224)。 - 修复若上传的备份文件名中包含 UTF8 字符,`GET /data/export` HTTP 接口返回 500 错误 [#9224](https://github.com/emqx/emqx/pull/9224)。
@ -25,3 +27,8 @@
- 修正了 `/status` API 的响应状态代码 [#9210](https://github.com/emqx/emqx/pull/9210)。 - 修正了 `/status` API 的响应状态代码 [#9210](https://github.com/emqx/emqx/pull/9210)。
在修复之前,它总是返回 `200`,即使 EMQX 应用程序没有运行。 现在它在这种情况下返回 `503` 在修复之前,它总是返回 `200`,即使 EMQX 应用程序没有运行。 现在它在这种情况下返回 `503`
- 修复规则引擎的消息事件编码失败 [#9226](https://github.com/emqx/emqx/pull/9226)。
带消息的规则引擎事件,例如 `$events/message_delivered``$events/message_dropped`,
如果消息事件是共享订阅产生的,在编码(到 JSON 格式)过程中会失败。
影响到的版本:`v4.3.21`, `v4.4.10`, `e4.3.16``e4.4.10`