diff --git a/deps/rabbit/priv/schema/rabbit.schema b/deps/rabbit/priv/schema/rabbit.schema index f6ccf7037bb2..756cf03ce676 100644 --- a/deps/rabbit/priv/schema/rabbit.schema +++ b/deps/rabbit/priv/schema/rabbit.schema @@ -2702,6 +2702,20 @@ fun(Conf) -> end end}. +{mapping, "node_tags.$tag", "rabbit.node_tags", [ + {datatype, [binary]} +]}. + +{translation, "rabbit.node_tags", +fun(Conf) -> + case cuttlefish:conf_get("node_tags", Conf, undefined) of + none -> []; + _ -> + Settings = cuttlefish_variable:filter_by_prefix("node_tags", Conf), + [ {list_to_binary(K), V} || {[_, K], V} <- Settings] + end +end}. + % =============================== % Validators % =============================== diff --git a/deps/rabbit/src/rabbit.erl b/deps/rabbit/src/rabbit.erl index 4a8c0b62d467..955282aba3e8 100644 --- a/deps/rabbit/src/rabbit.erl +++ b/deps/rabbit/src/rabbit.erl @@ -741,6 +741,7 @@ status() -> {erlang_version, erlang:system_info(system_version)}, {memory, rabbit_vm:memory()}, {alarms, alarms()}, + {tags, tags()}, {is_under_maintenance, rabbit_maintenance:is_being_drained_local_read(node())}, {listeners, listeners()}, {vm_memory_calculation_strategy, vm_memory_monitor:get_memory_calculation_strategy()}], @@ -800,6 +801,9 @@ alarms() -> %% [{{resource_limit,memory,rabbit@mercurio},[]}] [{resource_limit, Limit, Node} || {{resource_limit, Limit, Node}, _} <- Alarms, Node =:= N]. +tags() -> + application:get_env(rabbit, node_tags, []). + listeners() -> Listeners = try rabbit_networking:active_listeners() diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/status_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/status_command.ex index c37c0971ceee..64b1f81568c7 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/status_command.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/status_command.ex @@ -69,7 +69,6 @@ defmodule RabbitMQ.CLI.Ctl.Commands.StatusCommand do def output(result, %{node: node_name, unit: unit}) when is_list(result) do m = result_map(result) - product_name_section = case m do %{:product_name => product_name} when product_name != "" -> @@ -142,6 +141,17 @@ defmodule RabbitMQ.CLI.Ctl.Commands.StatusCommand do xs -> alarm_lines(xs, node_name) end + IO.inspect(m[:tags]) + tags_section = + [ + "\n#{bright("Tags")}\n" + ] ++ + case m[:tags] do + nil -> ["(none)"] + [] -> ["(none)"] + xs -> tag_lines(xs) + end + breakdown = compute_relative_values(m[:memory]) memory_calculation_strategy = to_atom(m[:vm_memory_calculation_strategy]) total_memory = get_in(m[:memory], [:total, memory_calculation_strategy]) @@ -198,6 +208,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.StatusCommand do config_section ++ log_section ++ alarms_section ++ + tags_section ++ memory_section ++ file_descriptors ++ disk_space_section ++ totals_section ++ listeners_section @@ -265,6 +276,7 @@ defmodule RabbitMQ.CLI.Ctl.Commands.StatusCommand do disk_free: Keyword.get(result, :disk_free), file_descriptors: Enum.into(Keyword.get(result, :file_descriptors), %{}), alarms: Keyword.get(result, :alarms), + tags: Keyword.get(result, :tags, []), listeners: listener_maps(Keyword.get(result, :listeners, [])), memory: Keyword.get(result, :memory) |> Enum.into(%{}), data_directory: Keyword.get(result, :data_directory) |> to_string, @@ -285,6 +297,12 @@ defmodule RabbitMQ.CLI.Ctl.Commands.StatusCommand do end end + defp tag_lines(mapping) do + Enum.map(mapping, fn {key, value} -> + "#{key}: #{value}" + end) + end + def space_as_iu_or_unknown(value, unit) do case value do :NaN -> diff --git a/deps/rabbitmq_management/src/rabbit_mgmt_wm_overview.erl b/deps/rabbitmq_management/src/rabbit_mgmt_wm_overview.erl index 817211200f70..1ec18f9262f5 100644 --- a/deps/rabbitmq_management/src/rabbit_mgmt_wm_overview.erl +++ b/deps/rabbitmq_management/src/rabbit_mgmt_wm_overview.erl @@ -48,6 +48,7 @@ to_json(ReqData, Context = #context{user = User = #user{tags = Tags}}) -> {rabbitmq_version, list_to_binary(rabbit:base_product_version())}, {cluster_name, rabbit_nodes:cluster_name()}, {cluster_tags, cluster_tags()}, + {node_tags, node_tags()}, {erlang_version, erlang_version()}, {erlang_full_version, erlang_full_version()}, {release_series_support_status, rabbit_release_series:readable_support_status()}, @@ -190,3 +191,6 @@ cluster_tags() -> []; Tags -> Tags end. + +node_tags() -> + application:get_env(rabbit, node_tags, []). diff --git a/deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl b/deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl index 3fa8a6e697c7..d7a1dadadadc 100644 --- a/deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl +++ b/deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl @@ -202,7 +202,7 @@ all_tests() -> [ qq_status_test, list_deprecated_features_test, list_used_deprecated_features_test, - cluster_tags_test + cluster_and_node_tags_test ]. %% ------------------------------------------------------------------- @@ -283,8 +283,10 @@ init_per_testcase(Testcase = disabled_qq_replica_opers_test, Config) -> rabbit_ct_broker_helpers:rpc_all(Config, application, set_env, [rabbitmq_management, restrictions, Restrictions]), rabbit_ct_helpers:testcase_started(Config, Testcase); -init_per_testcase(Testcase = cluster_tags_test, Config) -> +init_per_testcase(Testcase = cluster_and_node_tags_test, Config) -> Tags = [{<<"az">>, <<"us-east-3">>}, {<<"region">>,<<"us-east">>}, {<<"environment">>,<<"production">>}], + rpc(Config, + application, set_env, [rabbit, node_tags, Tags]), rpc( Config, rabbit_runtime_parameters, set_global, [cluster_tags, Tags, none]), @@ -355,7 +357,9 @@ end_per_testcase0(disabled_operator_policy_test, Config) -> 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) -> +end_per_testcase0(cluster_and_node_tags_test, Config) -> + rpc( + Config, application, unset_env, [rabbit, node_tags]), rpc( Config, rabbit_runtime_parameters, clear_global, [cluster_tags, none]), @@ -3948,12 +3952,14 @@ list_used_deprecated_features_test(Config) -> ?assertEqual(list_to_binary(Desc), maps:get(desc, Feature)), ?assertEqual(list_to_binary(DocUrl), maps:get(doc_url, Feature)). -cluster_tags_test(Config) -> +cluster_and_node_tags_test(Config) -> Overview = http_get(Config, "/overview"), - Tags = maps:get(cluster_tags, Overview), + ClusterTags = maps:get(cluster_tags, Overview), + NodeTags = maps:get(node_tags, Overview), ExpectedTags = #{az => <<"us-east-3">>,environment => <<"production">>, region => <<"us-east">>}, - ?assertEqual(ExpectedTags, Tags), + ?assertEqual(ExpectedTags, ClusterTags), + ?assertEqual(ExpectedTags, NodeTags), passed. %% -------------------------------------------------------------------