Skip to content

Commit

Permalink
Merge pull request #12839 from rabbitmq/mergify/bp/v4.0.x/pr-12821
Browse files Browse the repository at this point in the history
Definition export: inject default queue type into virtual host metadata (backport #12821)
  • Loading branch information
michaelklishin authored Nov 27, 2024
2 parents 1468489 + 2c638e6 commit 6cb9737
Show file tree
Hide file tree
Showing 18 changed files with 385 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ jobs:
with:
ref: refs/heads/main
erlang_version: 26.2
elixir_version: 1.15
elixir_version: 1.17
project_version: 4.0.0

check-v4_0_x:
uses: ./.github/workflows/check-build-system-equivalence.yaml
with:
ref: refs/heads/main
erlang_version: 26.2
elixir_version: 1.15
elixir_version: 1.17
project_version: 4.0.0

check-v3_13_x:
uses: ./.github/workflows/check-build-system-equivalence.yaml
with:
ref: refs/heads/v3.13.x
erlang_version: 26.2
elixir_version: 1.15
elixir_version: 1.17
project_version: 3.13.0

check-v3_12_x:
uses: ./.github/workflows/check-build-system-equivalence.yaml
with:
ref: refs/heads/v3.12.x
erlang_version: 26.1
elixir_version: 1.15
elixir_version: 1.17
project_version: 3.12.0
2 changes: 1 addition & 1 deletion .github/workflows/check-build-system-equivalence.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:
elixir_version:
description: 'Elixir version to build with'
required: true
default: "1.15"
default: "1.17"
project_version:
description: 'PROJECT_VERSION used for make'
required: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-management-ui-for-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- chrome
include:
- erlang_version: "26.2"
elixir_version: 1.15.7
elixir_version: 1.17
env:
SELENIUM_DIR: selenium
DOCKER_NETWORK: rabbitmq_net
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-plugin-mixed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# - khepri
include:
- erlang_version: 26
elixir_version: 1.15
elixir_version: 1.17
timeout-minutes: 120
steps:
- name: LOAD REPO CACHE
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- khepri
include:
- erlang_version: 26
elixir_version: 1.15
elixir_version: 1.17
timeout-minutes: 120
steps:
- name: LOAD REPO CACHE
Expand Down
7 changes: 5 additions & 2 deletions deps/rabbit/src/rabbit_definitions.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1071,10 +1071,13 @@ list_vhosts() ->
[vhost_definition(V) || V <- rabbit_vhost:all()].

vhost_definition(VHost) ->
Name = vhost:get_name(VHost),
DQT = rabbit_queue_type:short_alias_of(rabbit_vhost:default_queue_type(Name)),
#{
<<"name">> => vhost:get_name(VHost),
<<"name">> => Name,
<<"limits">> => vhost:get_limits(VHost),
<<"metadata">> => vhost:get_metadata(VHost)
<<"metadata">> => vhost:get_metadata(VHost),
<<"default_queue_type">> => DQT
}.

list_users() ->
Expand Down
40 changes: 40 additions & 0 deletions deps/rabbit/src/rabbit_queue_type.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
-behaviour(rabbit_registry_class).

-include("amqqueue.hrl").
-include("vhost.hrl").
-include_lib("rabbit_common/include/rabbit.hrl").
-include_lib("amqp10_common/include/amqp10_types.hrl").

Expand All @@ -22,7 +23,10 @@
feature_flag_name/1,
to_binary/1,
default/0,
default_alias/0,
fallback/0,
inject_dqt/1,
vhosts_with_dqt/1,
is_enabled/1,
is_compatible/4,
declare/2,
Expand Down Expand Up @@ -317,6 +321,15 @@ short_alias_of(rabbit_stream_queue) ->
%% AMQP 1.0 management client
short_alias_of({utf8, <<"stream">>}) ->
<<"stream">>;
%% for cases where this function is used for
%% formatting of values that already might use these
%% short aliases
short_alias_of(<<"quorum">>) ->
<<"quorum">>;
short_alias_of(<<"classic">>) ->
<<"classic">>;
short_alias_of(<<"stream">>) ->
<<"stream">>;
short_alias_of(_Other) ->
undefined.

Expand All @@ -343,6 +356,10 @@ default() ->
fallback()),
rabbit_data_coercion:to_atom(V).

-spec default_alias() -> binary().
default_alias() ->
short_alias_of(default()).

-spec to_binary(module()) -> binary().
to_binary(rabbit_classic_queue) ->
<<"classic">>;
Expand Down Expand Up @@ -833,6 +850,29 @@ known_queue_type_names() ->
QTypeBins = lists:map(fun(X) -> atom_to_binary(X) end, QueueTypes),
?KNOWN_QUEUE_TYPES ++ QTypeBins.

inject_dqt(VHost) when ?is_vhost(VHost) ->
inject_dqt(vhost:to_map(VHost));
inject_dqt(VHost) when is_list(VHost) ->
inject_dqt(rabbit_data_coercion:to_map(VHost));
inject_dqt(M = #{default_queue_type := undefined}) ->
NQT = short_alias_of(default()),
Meta0 = maps:get(metadata, M, #{}),
Meta = Meta0#{default_queue_type => NQT},

M#{default_queue_type => NQT, metadata => Meta};
inject_dqt(M = #{default_queue_type := DQT}) ->
NQT = short_alias_of(DQT),
Meta0 = maps:get(metadata, M, #{}),
Meta = Meta0#{default_queue_type => NQT},

M#{default_queue_type => NQT, metadata => Meta}.

-spec vhosts_with_dqt([any()]) -> [map()].
vhosts_with_dqt(List) when is_list(List) ->
%% inject DQT (default queue type) at the top level and
%% its metadata
lists:map(fun inject_dqt/1, List).

-spec check_queue_limits(amqqueue:amqqueue()) ->
ok |
{error, queue_limit_exceeded, Reason :: string(), Args :: term()}.
Expand Down
22 changes: 17 additions & 5 deletions deps/rabbit/src/rabbit_vhost.erl
Original file line number Diff line number Diff line change
Expand Up @@ -511,13 +511,14 @@ default_queue_type(VirtualHost) ->
default_queue_type(VirtualHost, rabbit_queue_type:fallback()).
-spec default_queue_type(VirtualHost :: vhost:name(), Fallback :: rabbit_queue_type:queue_type()) -> rabbit_queue_type:queue_type().
default_queue_type(VirtualHost, FallbackQueueType) ->
NodeDefault = application:get_env(rabbit, default_queue_type, FallbackQueueType),
case exists(VirtualHost) of
false -> FallbackQueueType;
false -> NodeDefault;
true ->
Record = lookup(VirtualHost),
case vhost:get_default_queue_type(Record) of
undefined -> FallbackQueueType;
<<"undefined">> -> FallbackQueueType;
undefined -> NodeDefault;
<<"undefined">> -> NodeDefault;
Type -> Type
end
end.
Expand Down Expand Up @@ -622,8 +623,19 @@ i(tracing, VHost) -> rabbit_trace:enabled(vhost:get_name(VHost));
i(cluster_state, VHost) -> vhost_cluster_state(vhost:get_name(VHost));
i(description, VHost) -> vhost:get_description(VHost);
i(tags, VHost) -> vhost:get_tags(VHost);
i(default_queue_type, VHost) -> vhost:get_default_queue_type(VHost);
i(metadata, VHost) -> vhost:get_metadata(VHost);
i(default_queue_type, VHost) -> rabbit_queue_type:short_alias_of(default_queue_type(vhost:get_name(VHost)));
i(metadata, VHost) ->
DQT = rabbit_queue_type:short_alias_of(default_queue_type(vhost:get_name(VHost))),
case vhost:get_metadata(VHost) of
undefined ->
#{default_queue_type => DQT};
M = #{default_queue_type := undefined} ->
M#{default_queue_type => DQT};
M = #{default_queue_type := QT} ->
M#{default_queue_type => rabbit_queue_type:short_alias_of(QT)};
M when is_map(M) ->
M#{default_queue_type => DQT}
end;
i(Item, VHost) ->
rabbit_log:error("Don't know how to compute a virtual host info item '~ts' for virtual host '~tp'", [Item, VHost]),
throw({bad_argument, Item}).
Expand Down
15 changes: 14 additions & 1 deletion deps/rabbit/src/vhost.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
get_description/1,
get_tags/1,
get_default_queue_type/1,

set_limits/2,
set_metadata/2,
merge_metadata/2,
new_metadata/3,
is_tagged_with/2
is_tagged_with/2,

to_map/1
]).

-define(record_version, vhost_v2).
Expand Down Expand Up @@ -196,3 +199,13 @@ new_metadata(Description, Tags, DefaultQueueType) ->
-spec is_tagged_with(vhost(), tag()) -> boolean().
is_tagged_with(VHost, Tag) ->
lists:member(Tag, get_tags(VHost)).

-spec to_map(vhost()) -> map().
to_map(VHost) ->
#{
name => get_name(VHost),
description => get_description(VHost),
tags => get_tags(VHost),
default_queue_type => get_default_queue_type(VHost),
metadata => get_metadata(VHost)
}.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## License, v. 2.0. If a copy of the MPL was not distributed with this
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
##
## Copyright (c) 2007-2023 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
## Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.

defmodule RabbitMQ.CLI.Ctl.Commands.ExportDefinitionsCommand do
alias RabbitMQ.CLI.Core.{DocGuide, ExitCodes, Helpers}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ListVhostsCommand do
use RabbitMQ.CLI.Core.AcceptsDefaultSwitchesAndTimeout

def merge_defaults([], opts) do
# this default historically benefits those who script using 'rabbitmqctl list_vhosts',
# adding more fields here would break scripts but be more useful to a human reader. MK.
merge_defaults(["name"], opts)
end

Expand Down
4 changes: 4 additions & 0 deletions deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
add_vhost/2,
add_vhost/3,
add_vhost/4,
update_vhost_metadata/3,
delete_vhost/2,
delete_vhost/3,
delete_vhost/4,
Expand Down Expand Up @@ -1541,6 +1542,9 @@ add_vhost(Config, Node, VHost) ->
add_vhost(Config, Node, VHost, Username) ->
catch rpc(Config, Node, rabbit_vhost, add, [VHost, Username]).

update_vhost_metadata(Config, VHost, Meta) ->
catch rpc(Config, 0, rabbit_vhost, update_metadata, [VHost, Meta, <<"acting-user">>]).

delete_vhost(Config, VHost) ->
delete_vhost(Config, 0, VHost).

Expand Down
2 changes: 1 addition & 1 deletion deps/rabbitmq_management/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ rabbitmq_integration_suite(
additional_beam = [
"test/rabbit_mgmt_runtime_parameters_util.beam",
],
shard_count = 6,
shard_count = 7,
runtime_deps = [
"//deps/amqp10_client:erlang_app",
],
Expand Down
Loading

0 comments on commit 6cb9737

Please sign in to comment.