From 65820eb943a04b3e63edc7817d746f10a89c2087 Mon Sep 17 00:00:00 2001 From: Zhongwen Deng Date: Fri, 18 Nov 2022 15:07:23 +0800 Subject: [PATCH 1/2] fix: can't get default raw config --- apps/emqx_management/src/emqx_mgmt_api_configs.erl | 4 ++-- .../test/emqx_mgmt_api_configs_SUITE.erl | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/emqx_management/src/emqx_mgmt_api_configs.erl b/apps/emqx_management/src/emqx_mgmt_api_configs.erl index db582c612..648ab9568 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_configs.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_configs.erl @@ -268,7 +268,7 @@ config(put, #{body := Body}, Req) -> global_zone_configs(get, _Params, _Req) -> Paths = global_zone_roots(), Zones = lists:foldl( - fun(Path, Acc) -> Acc#{Path => get_config_with_default([Path])} end, + fun(Path, Acc) -> maps:merge(Acc, get_config_with_default(Path)) end, #{}, Paths ), @@ -343,7 +343,7 @@ get_full_config() -> ). get_config_with_default(Path) -> - emqx_config:fill_defaults(emqx:get_raw_config(Path)). + emqx_config:fill_defaults(#{Path => emqx:get_raw_config([Path])}). conf_path_from_querystr(Req) -> case proplists:get_value(<<"conf_path">>, cowboy_req:parse_qs(Req)) of diff --git a/apps/emqx_management/test/emqx_mgmt_api_configs_SUITE.erl b/apps/emqx_management/test/emqx_mgmt_api_configs_SUITE.erl index 83f68c5fe..adea70af6 100644 --- a/apps/emqx_management/test/emqx_mgmt_api_configs_SUITE.erl +++ b/apps/emqx_management/test/emqx_mgmt_api_configs_SUITE.erl @@ -133,6 +133,18 @@ t_global_zone(_Config) -> BadZones = emqx_map_lib:deep_put([<<"mqtt">>, <<"max_qos_allowed">>], Zones, 3), ?assertMatch({error, {"HTTP/1.1", 400, _}}, update_global_zone(BadZones)), + + %% Remove max_qos_allowed from raw config, but we still get default value(2). + Mqtt0 = emqx_conf:get_raw([<<"mqtt">>]), + ?assertEqual(1, emqx_map_lib:deep_get([<<"max_qos_allowed">>], Mqtt0)), + Mqtt1 = maps:remove(<<"max_qos_allowed">>, Mqtt0), + ok = emqx_config:put_raw([<<"mqtt">>], Mqtt1), + Mqtt2 = emqx_conf:get_raw([<<"mqtt">>]), + ?assertNot(maps:is_key(<<"max_qos_allowed">>, Mqtt2), Mqtt2), + {ok, #{<<"mqtt">> := Mqtt3}} = get_global_zone(), + %% the default value is 2 + ?assertEqual(2, emqx_map_lib:deep_get([<<"max_qos_allowed">>], Mqtt3)), + ok = emqx_config:put_raw([<<"mqtt">>], Mqtt0), ok. get_global_zone() -> From b2db34708e07e9b57677aaa831720a397b56b9f6 Mon Sep 17 00:00:00 2001 From: Zhongwen Deng Date: Fri, 18 Nov 2022 15:24:10 +0800 Subject: [PATCH 2/2] chore: add changelog for fix global_zone api --- changes/v5.0.11-en.md | 2 ++ changes/v5.0.11-zh.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/changes/v5.0.11-en.md b/changes/v5.0.11-en.md index 15188d97e..6ce0091f8 100644 --- a/changes/v5.0.11-en.md +++ b/changes/v5.0.11-en.md @@ -20,3 +20,5 @@ - Return 404 for status of unknown authenticator in `/authenticator/{id}/status` [#9328](https://github.com/emqx/emqx/pull/9328). - Fix that JWT ACL rules are only applied if an `exp` claim is set [#9368](https://github.com/emqx/emqx/pull/9368). + +- Fix that `/configs/global_zone` API cannot get the default value of the configuration [#9392](https://github.com/emqx/emqx/pull/9392). diff --git a/changes/v5.0.11-zh.md b/changes/v5.0.11-zh.md index 4c74a7081..8072179e3 100644 --- a/changes/v5.0.11-zh.md +++ b/changes/v5.0.11-zh.md @@ -18,3 +18,5 @@ - 通过 `/authenticator/{id}/status` 请求未知认证器的状态时,将会返回 404。 - 修复 JWT ACL 规则只在设置了超期时间时才生效的问题 [#9368](https://github.com/emqx/emqx/pull/9368)。 + +- 修复 `/configs/global_zone` API 无法正确获取配置的默认值问题 [#9392](https://github.com/emqx/emqx/pull/9392)。