Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions deps/rabbit/priv/schema/rabbit.schema
Original file line number Diff line number Diff line change
Expand Up @@ -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
% ===============================
Expand Down
4 changes: 4 additions & 0 deletions deps/rabbit/src/rabbit.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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()}],
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" ->
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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 ->
Expand Down
4 changes: 4 additions & 0 deletions deps/rabbitmq_management/src/rabbit_mgmt_wm_overview.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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()},
Expand Down Expand Up @@ -190,3 +191,6 @@ cluster_tags() ->
[];
Tags -> Tags
end.

node_tags() ->
application:get_env(rabbit, node_tags, []).
18 changes: 12 additions & 6 deletions deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
].

%% -------------------------------------------------------------------
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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.

%% -------------------------------------------------------------------
Expand Down
Loading