diff options
| author | Michael Klishin <michael@clojurewerkz.org> | 2020-02-02 18:17:59 +0300 |
|---|---|---|
| committer | Michael Klishin <michael@clojurewerkz.org> | 2020-02-02 18:17:59 +0300 |
| commit | 3be5483ec22feca1460e09aaf21b629c9c72ec3e (patch) | |
| tree | b317fbfcf6c160be84e8868bf9fb19efad0dd72d /src | |
| parent | 4216b2a644019bd22354461c4a716203bf2bee30 (diff) | |
| download | rabbitmq-server-git-3be5483ec22feca1460e09aaf21b629c9c72ec3e.tar.gz | |
Refactor definition import functions to log less
* Only log the intent to import for categories that are not empty/missing
* Log how many entities will be imported
Current logging frequency is reasonable for occasional manual
or automated imports but with continuous automated imports
(say, a hot standby) it is too excessive.
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_definitions.erl | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/src/rabbit_definitions.erl b/src/rabbit_definitions.erl index 1923e2947e..4d666b88fc 100644 --- a/src/rabbit_definitions.erl +++ b/src/rabbit_definitions.erl @@ -224,29 +224,19 @@ apply_defs(Map, ActingUser, VHost) when is_binary(VHost) -> apply_defs(Map, ActingUser, SuccessFun) when is_function(SuccessFun) -> Version = maps:get(rabbitmq_version, Map, maps:get(rabbit_version, Map, undefined)), try - rabbit_log:info("Importing users..."), for_all(users, ActingUser, Map, fun(User, _Username) -> rabbit_auth_backend_internal:put_user(User, Version, ActingUser) end), - rabbit_log:info("Importing vhosts..."), for_all(vhosts, ActingUser, Map, fun add_vhost/2), validate_limits(Map), - rabbit_log:info("Importing user permissions..."), for_all(permissions, ActingUser, Map, fun add_permission/2), - rabbit_log:info("Importing topic permissions..."), for_all(topic_permissions, ActingUser, Map, fun add_topic_permission/2), - rabbit_log:info("Importing parameters..."), for_all(parameters, ActingUser, Map, fun add_parameter/2), - rabbit_log:info("Importing global parameters..."), for_all(global_parameters, ActingUser, Map, fun add_global_parameter/2), - rabbit_log:info("Importing policies..."), for_all(policies, ActingUser, Map, fun add_policy/2), - rabbit_log:info("Importing queues..."), for_all(queues, ActingUser, Map, fun add_queue/2), - rabbit_log:info("Importing exchanges..."), for_all(exchanges, ActingUser, Map, fun add_exchange/2), - rabbit_log:info("Importing bindings..."), for_all(bindings, ActingUser, Map, fun add_binding/2), SuccessFun(), ok @@ -264,15 +254,10 @@ apply_defs(Map, ActingUser, SuccessFun, VHost) when is_binary(VHost) -> [VHost, ActingUser]), try validate_limits(Map, VHost), - rabbit_log:info("Importing parameters..."), for_all(parameters, ActingUser, Map, VHost, fun add_parameter/3), - rabbit_log:info("Importing policies..."), for_all(policies, ActingUser, Map, VHost, fun add_policy/3), - rabbit_log:info("Importing queues..."), for_all(queues, ActingUser, Map, VHost, fun add_queue/3), - rabbit_log:info("Importing exchanges..."), for_all(exchanges, ActingUser, Map, VHost, fun add_exchange/3), - rabbit_log:info("Importing bindings..."), for_all(bindings, ActingUser, Map, VHost, fun add_binding/3), SuccessFun() catch {error, E} -> {error, format(E)}; @@ -290,27 +275,31 @@ apply_defs(Map, ActingUser, SuccessFun, ErrorFun, VHost) -> [VHost, ActingUser]), try validate_limits(Map, VHost), - rabbit_log:info("Importing parameters..."), for_all(parameters, ActingUser, Map, VHost, fun add_parameter/3), - rabbit_log:info("Importing policies..."), for_all(policies, ActingUser, Map, VHost, fun add_policy/3), - rabbit_log:info("Importing queues..."), for_all(queues, ActingUser, Map, VHost, fun add_queue/3), - rabbit_log:info("Importing exchanges..."), for_all(exchanges, ActingUser, Map, VHost, fun add_exchange/3), - rabbit_log:info("Importing bindings..."), for_all(bindings, ActingUser, Map, VHost, fun add_binding/3), SuccessFun() catch {error, E} -> ErrorFun(format(E)); exit:E -> ErrorFun(format(E)) end. -for_all(Name, ActingUser, Definitions, Fun) -> - case maps:get(rabbit_data_coercion:to_atom(Name), Definitions, undefined) of +for_all(Category, ActingUser, Definitions, Fun) -> + case maps:get(rabbit_data_coercion:to_atom(Category), Definitions, undefined) of undefined -> ok; - List -> [Fun(maps:from_list([{atomise_name(K), V} || {K, V} <- maps:to_list(M)]), - ActingUser) || - M <- List, is_map(M)] + List -> + case length(List) of + 0 -> ok; + N -> rabbit_log:info("Importing ~p ~s...", [N, human_readable_category_name(Category)]) + end, + [begin + %% keys are expected to be atoms + Atomized = maps:fold(fun (K, V, Acc) -> + maps:put(rabbit_data_coercion:to_atom(K), V, Acc) + end, #{}, M), + Fun(Atomized, ActingUser) + end || M <- List, is_map(M)] end. for_all(Name, ActingUser, Definitions, VHost, Fun) -> @@ -322,6 +311,14 @@ for_all(Name, ActingUser, Definitions, VHost, Fun) -> M <- List, is_map(M)] end. +-spec human_readable_category_name(definition_category()) -> string(). + +human_readable_category_name(topic_permissions) -> "topic permissions"; +human_readable_category_name(parameters) -> "runtime parameters"; +human_readable_category_name(global_parameters) -> "global runtime parameters"; +human_readable_category_name(Other) -> rabbit_data_coercion:to_list(Other). + + format(#amqp_error{name = Name, explanation = Explanation}) -> rabbit_data_coercion:to_binary(rabbit_misc:format("~s: ~s", [Name, Explanation])); format({no_such_vhost, undefined}) -> |
