Skip to content

Commit

Permalink
Store tags in global parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonUnge committed Nov 6, 2024
1 parent 6fabb50 commit f79ecd0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
26 changes: 25 additions & 1 deletion deps/rabbit/src/rabbit.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

%%---------------------------------------------------------------------------
%% Boot steps.
-export([maybe_insert_default_data/0, boot_delegate/0, recover/0,
-export([maybe_set_cluster_tags/0, maybe_insert_default_data/0, boot_delegate/0, recover/0,
pg_local_amqp_session/0,
pg_local_amqp_connection/0]).

Expand Down Expand Up @@ -208,6 +208,12 @@
{requires, recovery},
{enables, routing_ready}]}).


-rabbit_boot_step({cluster_tags,
[{description, "Set cluster tags"},
{mfa, {?MODULE, maybe_set_cluster_tags, []}},
{requires, core_initialized}]}).

-rabbit_boot_step({routing_ready,
[{description, "message delivery logic ready"},
{requires, [core_initialized, recovery]}]}).
Expand Down Expand Up @@ -1138,6 +1144,24 @@ pg_local_amqp_connection() ->
pg_local_scope(Prefix) ->
list_to_atom(io_lib:format("~s_~s", [Prefix, node()])).


-spec maybe_set_cluster_tags() -> 'ok'.

maybe_set_cluster_tags() ->
maybe
not_found ?= rabbit_runtime_parameters:lookup_global(cluster_tags),
Tags = application:get_env(rabbit, cluster_tags, []),
false ?= Tags == [],
?LOG_INFO("Setting cluster tags...",
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
rabbit_runtime_parameters:set_global(cluster_tags, Tags, <<"internal_user">>)
else
_ ->
% Cluster tags are either already set (Other node, earlier start, CLI)
% Do nothing?
ok
end.

-spec maybe_insert_default_data() -> 'ok'.

maybe_insert_default_data() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,12 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ClusterStatusCommand do
defp cluster_tags(node, timeout) do
case :rabbit_misc.rpc_call(
node,
:application,
:get_env,
[:rabbit, :cluster_tags],
:rabbit_runtime_parameters,
:value_global,
[:cluster_tags],
timeout) do
{:ok, tags} -> tags
_ -> []
:not_found -> []
tags -> tags
end
end

Expand Down
6 changes: 5 additions & 1 deletion deps/rabbitmq_management/src/rabbit_mgmt_wm_overview.erl
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,8 @@ transform_retention_intervals([{MaxAgeInSeconds, _}|Rest], Acc) ->
transform_retention_intervals(Rest, [AccVal|Acc]).

cluster_tags() ->
application:get_env(rabbit, cluster_tags, []).
case rabbit_runtime_parameters:value_global(cluster_tags) of
not_found ->
[];
Tags -> Tags
end.
9 changes: 6 additions & 3 deletions deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,9 @@ init_per_testcase(Testcase = disabled_qq_replica_opers_test, Config) ->
rabbit_ct_helpers:testcase_started(Config, Testcase);
init_per_testcase(Testcase = cluster_tags_test, Config) ->
Tags = [{<<"az">>, <<"us-east-3">>}, {<<"region">>,<<"us-east">>}, {<<"environment">>,<<"production">>}],
rabbit_ct_broker_helpers:rpc_all(Config,
application, set_env, [rabbit, cluster_tags, Tags]),
rpc(
Config, rabbit_runtime_parameters, set_global,
[cluster_tags, Tags, none]),
rabbit_ct_helpers:testcase_started(Config, Testcase);
init_per_testcase(queues_detailed_test, Config) ->
IsEnabled = rabbit_ct_broker_helpers:is_feature_flag_enabled(
Expand Down Expand Up @@ -356,7 +357,9 @@ end_per_testcase0(disabled_qq_replica_opers_test, Config) ->
rpc(Config, application, unset_env, [rabbitmq_management, restrictions]),
Config;
end_per_testcase0(cluster_tags_test, Config) ->
rpc(Config, application, unset_env, [rabbit, cluster_tags]),
rpc(
Config, rabbit_runtime_parameters, clear_global,
[cluster_tags, none]),
Config;
end_per_testcase0(Testcase, Config)
when Testcase == list_deprecated_features_test;
Expand Down

0 comments on commit f79ecd0

Please sign in to comment.