diff --git a/deps/rabbit/src/rabbit.erl b/deps/rabbit/src/rabbit.erl index f6f6fa36427..cc9787b5e11 100644 --- a/deps/rabbit/src/rabbit.erl +++ b/deps/rabbit/src/rabbit.erl @@ -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]). @@ -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]}]}). @@ -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() -> diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/cluster_status_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/cluster_status_command.ex index 95494883cbb..70bc8f3de5b 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/cluster_status_command.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/cluster_status_command.ex @@ -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 diff --git a/deps/rabbitmq_management/src/rabbit_mgmt_wm_overview.erl b/deps/rabbitmq_management/src/rabbit_mgmt_wm_overview.erl index 46d0e5299ea..817211200f7 100644 --- a/deps/rabbitmq_management/src/rabbit_mgmt_wm_overview.erl +++ b/deps/rabbitmq_management/src/rabbit_mgmt_wm_overview.erl @@ -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. diff --git a/deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl b/deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl index fb56edbcc82..c677d546c15 100644 --- a/deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl +++ b/deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl @@ -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( @@ -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;