Skip to content

Commit 1601808

Browse files
committed
rabbit_feature_flags: Log a inventory matrix instead of dumping the map
[Why] The inventory map is huge and difficult to read when it is logged as is. [How] Logging a matrix is much more compact and to the point. Before: Feature flags: inventory of node `rabbit-1@giotto`: #{feature_flags => #{rabbit_exchange_type_local_random => #{name => rabbit_exchange_type_local_random, desc => "Local random exchange",stability => stable, provided_by => rabbit}, message_containers_deaths_v2 => #{name => message_containers_deaths_v2, desc => "Bug fix for dead letter cycle detection", ... After: Feature flags: inventory queried from node `rabbit-2@giotto`: ,-- rabbit-2@giotto | amqp_address_v1: classic_mirrored_queue_version: x classic_queue_mirroring: x classic_queue_type_delivery_support: x ...
1 parent 5370370 commit 1601808

File tree

1 file changed

+55
-9
lines changed

1 file changed

+55
-9
lines changed

deps/rabbit/src/rabbit_ff_controller.erl

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -440,17 +440,10 @@ check_node_compatibility_task1(NodeA, NodesA, NodeB, NodesB, NodeAAsVirigin)
440440
{ok, InventoryA0} ->
441441
InventoryA = virtually_reset_inventory(
442442
InventoryA0, NodeAAsVirigin),
443-
?LOG_DEBUG(
444-
"Feature flags: inventory of node `~ts`:~n~tp",
445-
[NodeA, InventoryA],
446-
#{domain => ?RMQLOG_DOMAIN_FEAT_FLAGS}),
443+
log_inventory(NodeA, InventoryA),
447444
case collect_inventory_on_nodes(NodesB) of
448445
{ok, InventoryB} ->
449-
?LOG_DEBUG(
450-
"Feature flags: inventory of node "
451-
"`~ts`:~n~tp",
452-
[NodeB, InventoryB],
453-
#{domain => ?RMQLOG_DOMAIN_FEAT_FLAGS}),
446+
log_inventory(NodeB, InventoryB),
454447
case are_compatible(InventoryA, InventoryB) of
455448
true ->
456449
?LOG_NOTICE(
@@ -485,6 +478,59 @@ check_node_compatibility_task1(NodeA, NodesA, NodeB, NodesB, NodeAAsVirigin)
485478
{error, {aborted_feature_flags_compat_check, Error}}
486479
end.
487480

481+
log_inventory(
482+
FromNode,
483+
#{feature_flags := FeatureFlags, states_per_node := StatesPerNode}) ->
484+
?LOG_DEBUG(
485+
begin
486+
AllFeatureNames = lists:sort(maps:keys(FeatureFlags)),
487+
Nodes = lists:sort(maps:keys(StatesPerNode)),
488+
LongestFeatureName = lists:foldl(
489+
fun(FeatureName, MaxLength) ->
490+
Length = length(
491+
atom_to_list(
492+
FeatureName)),
493+
if
494+
Length > MaxLength -> Length;
495+
true -> MaxLength
496+
end
497+
end, 0, AllFeatureNames),
498+
NodeInitialPrefix = lists:duplicate(LongestFeatureName + 1, $\s),
499+
{Header,
500+
HeaderTail} = lists:foldl(
501+
fun(Node, {String, Prefix}) ->
502+
String1 = io_lib:format(
503+
"~ts~ts ,-- ~ts~n",
504+
[String, Prefix, Node]),
505+
NextPrefix = Prefix ++ " |",
506+
{String1, NextPrefix}
507+
end, {"", NodeInitialPrefix}, Nodes),
508+
lists:flatten(
509+
io_lib:format(
510+
"Feature flags: inventory queried from node `~ts`:~n",
511+
[FromNode]) ++
512+
Header ++
513+
HeaderTail ++
514+
[io_lib:format("~n~*ts:", [LongestFeatureName, FeatureName]) ++
515+
[io_lib:format(
516+
" ~s",
517+
[begin
518+
State = maps:get(
519+
FeatureName,
520+
maps:get(Node, StatesPerNode),
521+
false),
522+
case State of
523+
true -> "x";
524+
state_changing -> "~";
525+
false -> " "
526+
end
527+
end])
528+
|| Node <- Nodes]
529+
|| FeatureName <- AllFeatureNames] ++
530+
[])
531+
end,
532+
#{domain_ => ?RMQLOG_DOMAIN_FEAT_FLAGS}).
533+
488534
-spec list_nodes_clustered_with(Node) -> Ret when
489535
Node :: node(),
490536
Ret :: Members | Error,

0 commit comments

Comments
 (0)