Merge pull request #9280 from sstrigler/EMQX-7665-cannot-clear-alarms

fix(emqx_mgmt): call emqx_alarm:delete_all_deactivated_alarms for rem…
This commit is contained in:
Zaiming (Stone) Shi 2022-11-04 16:13:33 +01:00 committed by GitHub
commit e73657ac52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 3 deletions

View File

@ -499,7 +499,7 @@ delete_all_deactivated_alarms() ->
delete_all_deactivated_alarms(Node) when Node =:= node() -> delete_all_deactivated_alarms(Node) when Node =:= node() ->
emqx_alarm:delete_all_deactivated_alarms(); emqx_alarm:delete_all_deactivated_alarms();
delete_all_deactivated_alarms(Node) -> delete_all_deactivated_alarms(Node) ->
rpc_call(Node, delete_deactivated_alarms, [Node]). rpc_call(Node, emqx_alarm, delete_all_deactivated_alarms, []).
add_duration_field(Alarms) -> add_duration_field(Alarms) ->
Now = erlang:system_time(microsecond), Now = erlang:system_time(microsecond),
@ -574,7 +574,10 @@ item(route, {Topic, Node}) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
rpc_call(Node, Fun, Args) -> rpc_call(Node, Fun, Args) ->
case rpc:call(Node, ?MODULE, Fun, Args) of rpc_call(Node, ?MODULE, Fun, Args).
rpc_call(Node, Mod, Fun, Args) ->
case rpc:call(Node, Mod, Fun, Args) of
{badrpc, Reason} -> {error, Reason}; {badrpc, Reason} -> {error, Reason};
Res -> Res Res -> Res
end. end.

View File

@ -34,7 +34,8 @@ all() ->
groups() -> groups() ->
[{manage_apps, [sequence], [{manage_apps, [sequence],
[t_app [t_app,
t_alarms
]}, ]},
{check_cli, [sequence], {check_cli, [sequence],
[t_cli, [t_cli,
@ -64,6 +65,24 @@ init_per_suite(Config) ->
end_per_suite(_Config) -> end_per_suite(_Config) ->
emqx_ct_helpers:stop_apps(apps()). emqx_ct_helpers:stop_apps(apps()).
init_per_testcase(Case, Config) when Case =:= t_alarms ->
try
?MODULE:Case({'init', Config})
catch
error : function_clause ->
Config
end;
init_per_testcase(_, Config) -> Config.
end_per_testcase(Case, Config) when Case =:= t_alarms ->
try
?MODULE:Case({'end', Config})
catch
error : function_clause ->
ok
end;
end_per_testcase(_, Config) -> Config.
t_app(_Config) -> t_app(_Config) ->
{ok, AppSecret} = emqx_mgmt_auth:add_app(<<"app_id">>, <<"app_name">>), {ok, AppSecret} = emqx_mgmt_auth:add_app(<<"app_id">>, <<"app_name">>),
?assert(emqx_mgmt_auth:is_authorized(<<"app_id">>, AppSecret)), ?assert(emqx_mgmt_auth:is_authorized(<<"app_id">>, AppSecret)),
@ -95,6 +114,16 @@ t_app(_Config) ->
emqx_mgmt_auth:del_app(<<"app_id">>), emqx_mgmt_auth:del_app(<<"app_id">>),
ok. ok.
t_alarms({'init', Config}) ->
meck:new(rpc, [unstick]),
meck:expect(rpc, call, 4, ok),
Config;
t_alarms({'end', _}) ->
meck:unload(rpc);
t_alarms(_) ->
ok = emqx_mgmt:delete_all_deactivated_alarms(remote_node),
?assert(meck:called(rpc, call, [remote_node, emqx_alarm, delete_all_deactivated_alarms, []])).
t_log_cmd(_) -> t_log_cmd(_) ->
mock_print(), mock_print(),
lists:foreach(fun(Level) -> lists:foreach(fun(Level) ->

View File

@ -70,4 +70,8 @@
Note that the `id` in `POST /api/v4/rules` should be literals (not encoded) when creating a `rule` or `resource`. Note that the `id` in `POST /api/v4/rules` should be literals (not encoded) when creating a `rule` or `resource`.
See docs [Create Rule](https://www.emqx.io/docs/zh/v4.3/advanced/http-api.html#post-api-v4-rules) [Create Resource](https://www.emqx.io/docs/zh/v4.3/advanced/http-api.html#post-api-v4-resources). See docs [Create Rule](https://www.emqx.io/docs/zh/v4.3/advanced/http-api.html#post-api-v4-rules) [Create Resource](https://www.emqx.io/docs/zh/v4.3/advanced/http-api.html#post-api-v4-resources).
- Calling 'DELETE /alarms/deactivated' now deletes deactived alarms on all nodes, including remote nodes, not just the local node [#9280](https://github.com/emqx/emqx/pull/9280).
- When republishing messages or bridge messages to other brokers, check the validity of the topic and make sure it does not have topic wildcards [#9291](https://github.com/emqx/emqx/pull/9291). - When republishing messages or bridge messages to other brokers, check the validity of the topic and make sure it does not have topic wildcards [#9291](https://github.com/emqx/emqx/pull/9291).

View File

@ -64,4 +64,8 @@
注意在创建规则或资源时HTTP body 中的 `id` 字段仍为字面值,而不是编码之后的值。 注意在创建规则或资源时HTTP body 中的 `id` 字段仍为字面值,而不是编码之后的值。
详情请参考 [创建规则](https://www.emqx.io/docs/zh/v4.3/advanced/http-api.html#post-api-v4-rules) 和 [创建资源](https://www.emqx.io/docs/zh/v4.3/advanced/http-api.html#post-api-v4-resources)。 详情请参考 [创建规则](https://www.emqx.io/docs/zh/v4.3/advanced/http-api.html#post-api-v4-rules) 和 [创建资源](https://www.emqx.io/docs/zh/v4.3/advanced/http-api.html#post-api-v4-resources)。
- 修复调用 'DELETE /alarms/deactivated' 只在单个节点上生效的问题,现在将会删除所有节点上的非活跃警告 [#9280](https://github.com/emqx/emqx/pull/9280)。
- 在进行消息重发布或桥接消息到其他 mqtt broker 时,检查 topic 合法性,确定其不带有主题通配符 [#9291](https://github.com/emqx/emqx/pull/9291)。 - 在进行消息重发布或桥接消息到其他 mqtt broker 时,检查 topic 合法性,确定其不带有主题通配符 [#9291](https://github.com/emqx/emqx/pull/9291)。