Skip to content

Commit

Permalink
rabbit_feature_flags: Log a inventory matrix instead of dumping the map
Browse files Browse the repository at this point in the history
[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
    ...
  • Loading branch information
dumbbell committed Oct 3, 2024
1 parent 5370370 commit 1601808
Showing 1 changed file with 55 additions and 9 deletions.
64 changes: 55 additions & 9 deletions deps/rabbit/src/rabbit_ff_controller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -440,17 +440,10 @@ check_node_compatibility_task1(NodeA, NodesA, NodeB, NodesB, NodeAAsVirigin)
{ok, InventoryA0} ->
InventoryA = virtually_reset_inventory(
InventoryA0, NodeAAsVirigin),
?LOG_DEBUG(
"Feature flags: inventory of node `~ts`:~n~tp",
[NodeA, InventoryA],
#{domain => ?RMQLOG_DOMAIN_FEAT_FLAGS}),
log_inventory(NodeA, InventoryA),
case collect_inventory_on_nodes(NodesB) of
{ok, InventoryB} ->
?LOG_DEBUG(
"Feature flags: inventory of node "
"`~ts`:~n~tp",
[NodeB, InventoryB],
#{domain => ?RMQLOG_DOMAIN_FEAT_FLAGS}),
log_inventory(NodeB, InventoryB),
case are_compatible(InventoryA, InventoryB) of
true ->
?LOG_NOTICE(
Expand Down Expand Up @@ -485,6 +478,59 @@ check_node_compatibility_task1(NodeA, NodesA, NodeB, NodesB, NodeAAsVirigin)
{error, {aborted_feature_flags_compat_check, Error}}
end.

log_inventory(
FromNode,
#{feature_flags := FeatureFlags, states_per_node := StatesPerNode}) ->
?LOG_DEBUG(
begin
AllFeatureNames = lists:sort(maps:keys(FeatureFlags)),
Nodes = lists:sort(maps:keys(StatesPerNode)),
LongestFeatureName = lists:foldl(
fun(FeatureName, MaxLength) ->
Length = length(
atom_to_list(
FeatureName)),
if
Length > MaxLength -> Length;
true -> MaxLength
end
end, 0, AllFeatureNames),
NodeInitialPrefix = lists:duplicate(LongestFeatureName + 1, $\s),
{Header,
HeaderTail} = lists:foldl(
fun(Node, {String, Prefix}) ->
String1 = io_lib:format(
"~ts~ts ,-- ~ts~n",
[String, Prefix, Node]),
NextPrefix = Prefix ++ " |",
{String1, NextPrefix}
end, {"", NodeInitialPrefix}, Nodes),
lists:flatten(
io_lib:format(
"Feature flags: inventory queried from node `~ts`:~n",
[FromNode]) ++
Header ++
HeaderTail ++
[io_lib:format("~n~*ts:", [LongestFeatureName, FeatureName]) ++
[io_lib:format(
" ~s",
[begin
State = maps:get(
FeatureName,
maps:get(Node, StatesPerNode),
false),
case State of
true -> "x";
state_changing -> "~";
false -> " "
end
end])
|| Node <- Nodes]
|| FeatureName <- AllFeatureNames] ++
[])
end,
#{domain_ => ?RMQLOG_DOMAIN_FEAT_FLAGS}).
-spec list_nodes_clustered_with(Node) -> Ret when
Node :: node(),
Ret :: Members | Error,
Expand Down

0 comments on commit 1601808

Please # to comment.