Merge pull request #10685 from lafirest/fix/limiter_server

fix(limiter): fix that update node-level limiter config will not working
This commit is contained in:
lafirest 2023-05-12 17:55:27 +08:00 committed by GitHub
commit 134ea0615d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 8 deletions

View File

@ -131,11 +131,9 @@ delete_root(Type) ->
delete_bucket(?ROOT_ID, Type). delete_bucket(?ROOT_ID, Type).
post_config_update([limiter], _Config, NewConf, _OldConf, _AppEnvs) -> post_config_update([limiter], _Config, NewConf, _OldConf, _AppEnvs) ->
Types = lists:delete(client, maps:keys(NewConf)), Conf = emqx_limiter_schema:convert_node_opts(NewConf),
_ = [on_post_config_update(Type, NewConf) || Type <- Types], _ = [on_post_config_update(Type, Cfg) || {Type, Cfg} <- maps:to_list(Conf)],
ok; ok.
post_config_update([limiter, Type], _Config, NewConf, _OldConf, _AppEnvs) ->
on_post_config_update(Type, NewConf).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
@ -279,8 +277,7 @@ format_status(_Opt, Status) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Internal functions %% Internal functions
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
on_post_config_update(Type, NewConf) -> on_post_config_update(Type, Config) ->
Config = maps:get(Type, NewConf),
case emqx_limiter_server:whereis(Type) of case emqx_limiter_server:whereis(Type) of
undefined -> undefined ->
start_server(Type, Config); start_server(Type, Config);

View File

@ -38,7 +38,8 @@
default_client_config/0, default_client_config/0,
short_paths_fields/1, short_paths_fields/1,
get_listener_opts/1, get_listener_opts/1,
get_node_opts/1 get_node_opts/1,
convert_node_opts/1
]). ]).
-define(KILOBYTE, 1024). -define(KILOBYTE, 1024).
@ -309,6 +310,24 @@ get_node_opts(Type) ->
end end
end. end.
convert_node_opts(Conf) ->
DefBucket = default_bucket_config(),
ShorPaths = short_paths(),
Fun = fun
%% The `client` in the node options was deprecated
(client, _Value, Acc) ->
Acc;
(Name, Value, Acc) ->
case lists:member(Name, ShorPaths) of
true ->
Type = short_path_name_to_type(Name),
Acc#{Type => DefBucket#{rate => Value}};
_ ->
Acc#{Name => Value}
end
end,
maps:fold(Fun, #{}, Conf).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Internal functions %% Internal functions
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------