fix(emqx_rule_events): do not keep tuple-value message headers

the converted message is for JSON encoding, keeping the tuple-values
will lead to encoding error.
This commit is contained in:
Zaiming (Stone) Shi 2022-10-25 18:11:12 +02:00
parent 90ef9254fd
commit 81e6a40454
4 changed files with 32 additions and 8 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
- Improve the display of rule's 'Maximum Speed' counter to only reserve 2 decimal places. [#9185](https://github.com/emqx/emqx/pull/9185) - Improve the display of rule's 'Maximum Speed' counter to only reserve 2 decimal places. [#9185](https://github.com/emqx/emqx/pull/9185)
This is to avoid displaying floats like `0.30000000000000004` on the dashboard. This is to avoid displaying floats like `0.30000000000000004` on the dashboard.
@ -21,5 +23,10 @@
- Restore old `emqx_auth_jwt` module API, so the hook callback functions registered in older version will not be invalidated after hot-upgrade [#9144](https://github.com/emqx/emqx/pull/9144). - Restore old `emqx_auth_jwt` module API, so the hook callback functions registered in older version will not be invalidated after hot-upgrade [#9144](https://github.com/emqx/emqx/pull/9144).
- 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)。
### 修复 ## 修复
- 改进规则的 "最大执行速度" 的计数,只保留小数点之后 2 位 [#9185](https://github.com/emqx/emqx/pull/9185) - 改进规则的 "最大执行速度" 的计数,只保留小数点之后 2 位 [#9185](https://github.com/emqx/emqx/pull/9185)
避免在 dashboard 上展示类似这样的浮点数:`0.30000000000000004`。 避免在 dashboard 上展示类似这样的浮点数:`0.30000000000000004`。
@ -23,3 +25,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`