From 88a0c77707a795df4c7b7285c5467a868f130712 Mon Sep 17 00:00:00 2001 From: firest Date: Tue, 11 Oct 2022 18:05:14 +0800 Subject: [PATCH 1/2] fix(limiter): add `limiter` back to the configs API --- .../emqx_limiter/src/emqx_limiter_manager.erl | 20 ++++++---- .../src/emqx_mgmt_api_configs.erl | 38 ------------------- 2 files changed, 13 insertions(+), 45 deletions(-) diff --git a/apps/emqx/src/emqx_limiter/src/emqx_limiter_manager.erl b/apps/emqx/src/emqx_limiter/src/emqx_limiter_manager.erl index aca27a6ff..a6ca9f2c8 100644 --- a/apps/emqx/src/emqx_limiter/src/emqx_limiter_manager.erl +++ b/apps/emqx/src/emqx_limiter/src/emqx_limiter_manager.erl @@ -107,14 +107,12 @@ insert_bucket(Id, Type, Bucket) -> delete_bucket(Type, Id) -> ets:delete(?TAB, ?UID(Id, Type)). +post_config_update([limiter], _Config, NewConf, _OldConf, _AppEnvs) -> + Types = lists:delete(client, maps:keys(NewConf)), + _ = [on_post_config_update(Type, NewConf) || Type <- Types], + ok; post_config_update([limiter, Type], _Config, NewConf, _OldConf, _AppEnvs) -> - Config = maps:get(Type, NewConf), - case emqx_limiter_server:whereis(Type) of - undefined -> - start_server(Type, Config); - _ -> - emqx_limiter_server:update_config(Type, Config) - end. + on_post_config_update(Type, NewConf). %%-------------------------------------------------------------------- %% @doc @@ -258,3 +256,11 @@ format_status(_Opt, Status) -> %%-------------------------------------------------------------------- %% Internal functions %%-------------------------------------------------------------------- +on_post_config_update(Type, NewConf) -> + Config = maps:get(Type, NewConf), + case emqx_limiter_server:whereis(Type) of + undefined -> + start_server(Type, Config); + _ -> + emqx_limiter_server:update_config(Type, Config) + end. diff --git a/apps/emqx_management/src/emqx_mgmt_api_configs.erl b/apps/emqx_management/src/emqx_mgmt_api_configs.erl index 648ab9568..7de5e05f6 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_configs.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_configs.erl @@ -63,7 +63,6 @@ <<"prometheus">>, <<"telemetry">>, <<"sys_topics">>, - <<"limiter">>, <<"listeners">> ] ++ global_zone_roots() ). @@ -78,7 +77,6 @@ paths() -> "/configs", "/configs_reset/:rootname", "/configs/global_zone" - %% "/configs/limiter/:limiter_type" ] ++ lists:map(fun({Name, _Type}) -> ?PREFIX ++ binary_to_list(Name) end, config_list()). @@ -168,42 +166,6 @@ schema("/configs/global_zone") -> } } }; -%% schema("/configs/limiter/:limiter_type") -> -%% Schema = hoconsc:ref(emqx_limiter_schema, limiter_opts), -%% Parameters = [ -%% {limiter_type, -%% hoconsc:mk( -%% hoconsc:enum(emqx_limiter_schema:types()), -%% #{ -%% in => path, -%% required => true, -%% example => <<"bytes_in">>, -%% desc => <<"The limiter type">> -%% } -%% )} -%% ], -%% #{ -%% 'operationId' => config, -%% get => #{ -%% tags => ?TAGS, -%% description => <<"Get config of this limiter">>, -%% parameters => Parameters, -%% responses => #{ -%% 200 => Schema, -%% 404 => emqx_dashboard_swagger:error_codes(['NOT_FOUND'], <<"config not found">>) -%% } -%% }, -%% put => #{ -%% tags => ?TAGS, -%% description => <<"Update config of this limiter">>, -%% parameters => Parameters, -%% 'requestBody' => Schema, -%% responses => #{ -%% 200 => Schema, -%% 400 => emqx_dashboard_swagger:error_codes(['UPDATE_FAILED']) -%% } -%% } -%% }; schema(Path) -> {RootKey, {_Root, Schema}} = find_schema(Path), #{ From f396dc7de9e938f7e750992ceb25b31c1344d5f1 Mon Sep 17 00:00:00 2001 From: firest Date: Thu, 1 Dec 2022 15:09:39 +0800 Subject: [PATCH 2/2] chore: update changes --- changes/v5.0.12-en.md | 2 ++ changes/v5.0.12-zh.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/changes/v5.0.12-en.md b/changes/v5.0.12-en.md index da20798a5..d811bf042 100644 --- a/changes/v5.0.12-en.md +++ b/changes/v5.0.12-en.md @@ -11,6 +11,8 @@ - Remove support for setting shared subscriptions using the non-standard `$queue` feature [#9412](https://github.com/emqx/emqx/pull/9412). Shared subscriptions are now part of the MQTT spec. Use `$share` instead. +- Add `limiter` update API [#9133](https://github.com/emqx/emqx/pull/9133). + ## Bug fixes - Fix that the obsolete SSL files aren't deleted after the ExHook config update [#9432](https://github.com/emqx/emqx/pull/9432). diff --git a/changes/v5.0.12-zh.md b/changes/v5.0.12-zh.md index 45acfd751..5129821cd 100644 --- a/changes/v5.0.12-zh.md +++ b/changes/v5.0.12-zh.md @@ -11,6 +11,8 @@ - 支持在 Apple Silicon 架构下编译苹果系统的发行版本 [#9423](https://github.com/emqx/emqx/pull/9423)。 +- 添加 `limiter` 更新 API [#9133](https://github.com/emqx/emqx/pull/9133)。 + ## 修复 - 修复 ExHook 更新 SSL 相关配置后,过时的 SSL 文件没有被删除的问题 [#9432](https://github.com/emqx/emqx/pull/9432)。