Skip to content

Commit 05716ad

Browse files
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. (cherry picked from commit 3be5483)
1 parent c45b4d7 commit 05716ad

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

src/rabbit_definitions.erl

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -224,29 +224,19 @@ apply_defs(Map, ActingUser, VHost) when is_binary(VHost) ->
224224
apply_defs(Map, ActingUser, SuccessFun) when is_function(SuccessFun) ->
225225
Version = maps:get(rabbitmq_version, Map, maps:get(rabbit_version, Map, undefined)),
226226
try
227-
rabbit_log:info("Importing users..."),
228227
for_all(users, ActingUser, Map,
229228
fun(User, _Username) ->
230229
rabbit_auth_backend_internal:put_user(User, Version, ActingUser)
231230
end),
232-
rabbit_log:info("Importing vhosts..."),
233231
for_all(vhosts, ActingUser, Map, fun add_vhost/2),
234232
validate_limits(Map),
235-
rabbit_log:info("Importing user permissions..."),
236233
for_all(permissions, ActingUser, Map, fun add_permission/2),
237-
rabbit_log:info("Importing topic permissions..."),
238234
for_all(topic_permissions, ActingUser, Map, fun add_topic_permission/2),
239-
rabbit_log:info("Importing parameters..."),
240235
for_all(parameters, ActingUser, Map, fun add_parameter/2),
241-
rabbit_log:info("Importing global parameters..."),
242236
for_all(global_parameters, ActingUser, Map, fun add_global_parameter/2),
243-
rabbit_log:info("Importing policies..."),
244237
for_all(policies, ActingUser, Map, fun add_policy/2),
245-
rabbit_log:info("Importing queues..."),
246238
for_all(queues, ActingUser, Map, fun add_queue/2),
247-
rabbit_log:info("Importing exchanges..."),
248239
for_all(exchanges, ActingUser, Map, fun add_exchange/2),
249-
rabbit_log:info("Importing bindings..."),
250240
for_all(bindings, ActingUser, Map, fun add_binding/2),
251241
SuccessFun(),
252242
ok
@@ -264,15 +254,10 @@ apply_defs(Map, ActingUser, SuccessFun, VHost) when is_binary(VHost) ->
264254
[VHost, ActingUser]),
265255
try
266256
validate_limits(Map, VHost),
267-
rabbit_log:info("Importing parameters..."),
268257
for_all(parameters, ActingUser, Map, VHost, fun add_parameter/3),
269-
rabbit_log:info("Importing policies..."),
270258
for_all(policies, ActingUser, Map, VHost, fun add_policy/3),
271-
rabbit_log:info("Importing queues..."),
272259
for_all(queues, ActingUser, Map, VHost, fun add_queue/3),
273-
rabbit_log:info("Importing exchanges..."),
274260
for_all(exchanges, ActingUser, Map, VHost, fun add_exchange/3),
275-
rabbit_log:info("Importing bindings..."),
276261
for_all(bindings, ActingUser, Map, VHost, fun add_binding/3),
277262
SuccessFun()
278263
catch {error, E} -> {error, format(E)};
@@ -290,27 +275,31 @@ apply_defs(Map, ActingUser, SuccessFun, ErrorFun, VHost) ->
290275
[VHost, ActingUser]),
291276
try
292277
validate_limits(Map, VHost),
293-
rabbit_log:info("Importing parameters..."),
294278
for_all(parameters, ActingUser, Map, VHost, fun add_parameter/3),
295-
rabbit_log:info("Importing policies..."),
296279
for_all(policies, ActingUser, Map, VHost, fun add_policy/3),
297-
rabbit_log:info("Importing queues..."),
298280
for_all(queues, ActingUser, Map, VHost, fun add_queue/3),
299-
rabbit_log:info("Importing exchanges..."),
300281
for_all(exchanges, ActingUser, Map, VHost, fun add_exchange/3),
301-
rabbit_log:info("Importing bindings..."),
302282
for_all(bindings, ActingUser, Map, VHost, fun add_binding/3),
303283
SuccessFun()
304284
catch {error, E} -> ErrorFun(format(E));
305285
exit:E -> ErrorFun(format(E))
306286
end.
307287

308-
for_all(Name, ActingUser, Definitions, Fun) ->
309-
case maps:get(rabbit_data_coercion:to_atom(Name), Definitions, undefined) of
288+
for_all(Category, ActingUser, Definitions, Fun) ->
289+
case maps:get(rabbit_data_coercion:to_atom(Category), Definitions, undefined) of
310290
undefined -> ok;
311-
List -> [Fun(maps:from_list([{atomise_name(K), V} || {K, V} <- maps:to_list(M)]),
312-
ActingUser) ||
313-
M <- List, is_map(M)]
291+
List ->
292+
case length(List) of
293+
0 -> ok;
294+
N -> rabbit_log:info("Importing ~p ~s...", [N, human_readable_category_name(Category)])
295+
end,
296+
[begin
297+
%% keys are expected to be atoms
298+
Atomized = maps:fold(fun (K, V, Acc) ->
299+
maps:put(rabbit_data_coercion:to_atom(K), V, Acc)
300+
end, #{}, M),
301+
Fun(Atomized, ActingUser)
302+
end || M <- List, is_map(M)]
314303
end.
315304

316305
for_all(Name, ActingUser, Definitions, VHost, Fun) ->
@@ -322,6 +311,14 @@ for_all(Name, ActingUser, Definitions, VHost, Fun) ->
322311
M <- List, is_map(M)]
323312
end.
324313

314+
-spec human_readable_category_name(definition_category()) -> string().
315+
316+
human_readable_category_name(topic_permissions) -> "topic permissions";
317+
human_readable_category_name(parameters) -> "runtime parameters";
318+
human_readable_category_name(global_parameters) -> "global runtime parameters";
319+
human_readable_category_name(Other) -> rabbit_data_coercion:to_list(Other).
320+
321+
325322
format(#amqp_error{name = Name, explanation = Explanation}) ->
326323
rabbit_data_coercion:to_binary(rabbit_misc:format("~s: ~s", [Name, Explanation]));
327324
format({no_such_vhost, undefined}) ->

0 commit comments

Comments
 (0)