Skip to content

Commit 6cb9737

Browse files
Merge pull request #12839 from rabbitmq/mergify/bp/v4.0.x/pr-12821
Definition export: inject default queue type into virtual host metadata (backport #12821)
2 parents 1468489 + 2c638e6 commit 6cb9737

18 files changed

+385
-80
lines changed

.github/workflows/check-build-system-equivalence-release-branches.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@ jobs:
99
with:
1010
ref: refs/heads/main
1111
erlang_version: 26.2
12-
elixir_version: 1.15
12+
elixir_version: 1.17
1313
project_version: 4.0.0
1414

1515
check-v4_0_x:
1616
uses: ./.github/workflows/check-build-system-equivalence.yaml
1717
with:
1818
ref: refs/heads/main
1919
erlang_version: 26.2
20-
elixir_version: 1.15
20+
elixir_version: 1.17
2121
project_version: 4.0.0
2222

2323
check-v3_13_x:
2424
uses: ./.github/workflows/check-build-system-equivalence.yaml
2525
with:
2626
ref: refs/heads/v3.13.x
2727
erlang_version: 26.2
28-
elixir_version: 1.15
28+
elixir_version: 1.17
2929
project_version: 3.13.0
3030

3131
check-v3_12_x:
3232
uses: ./.github/workflows/check-build-system-equivalence.yaml
3333
with:
3434
ref: refs/heads/v3.12.x
3535
erlang_version: 26.1
36-
elixir_version: 1.15
36+
elixir_version: 1.17
3737
project_version: 3.12.0

.github/workflows/check-build-system-equivalence.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ on:
2323
elixir_version:
2424
description: 'Elixir version to build with'
2525
required: true
26-
default: "1.15"
26+
default: "1.17"
2727
project_version:
2828
description: 'PROJECT_VERSION used for make'
2929
required: true

.github/workflows/test-management-ui-for-pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- chrome
2121
include:
2222
- erlang_version: "26.2"
23-
elixir_version: 1.15.7
23+
elixir_version: 1.17
2424
env:
2525
SELENIUM_DIR: selenium
2626
DOCKER_NETWORK: rabbitmq_net

.github/workflows/test-plugin-mixed.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
# - khepri
3636
include:
3737
- erlang_version: 26
38-
elixir_version: 1.15
38+
elixir_version: 1.17
3939
timeout-minutes: 120
4040
steps:
4141
- name: LOAD REPO CACHE

.github/workflows/test-plugin.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- khepri
3333
include:
3434
- erlang_version: 26
35-
elixir_version: 1.15
35+
elixir_version: 1.17
3636
timeout-minutes: 120
3737
steps:
3838
- name: LOAD REPO CACHE

deps/rabbit/src/rabbit_definitions.erl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,10 +1071,13 @@ list_vhosts() ->
10711071
[vhost_definition(V) || V <- rabbit_vhost:all()].
10721072

10731073
vhost_definition(VHost) ->
1074+
Name = vhost:get_name(VHost),
1075+
DQT = rabbit_queue_type:short_alias_of(rabbit_vhost:default_queue_type(Name)),
10741076
#{
1075-
<<"name">> => vhost:get_name(VHost),
1077+
<<"name">> => Name,
10761078
<<"limits">> => vhost:get_limits(VHost),
1077-
<<"metadata">> => vhost:get_metadata(VHost)
1079+
<<"metadata">> => vhost:get_metadata(VHost),
1080+
<<"default_queue_type">> => DQT
10781081
}.
10791082

10801083
list_users() ->

deps/rabbit/src/rabbit_queue_type.erl

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
-behaviour(rabbit_registry_class).
1212

1313
-include("amqqueue.hrl").
14+
-include("vhost.hrl").
1415
-include_lib("rabbit_common/include/rabbit.hrl").
1516
-include_lib("amqp10_common/include/amqp10_types.hrl").
1617

@@ -22,7 +23,10 @@
2223
feature_flag_name/1,
2324
to_binary/1,
2425
default/0,
26+
default_alias/0,
2527
fallback/0,
28+
inject_dqt/1,
29+
vhosts_with_dqt/1,
2630
is_enabled/1,
2731
is_compatible/4,
2832
declare/2,
@@ -317,6 +321,15 @@ short_alias_of(rabbit_stream_queue) ->
317321
%% AMQP 1.0 management client
318322
short_alias_of({utf8, <<"stream">>}) ->
319323
<<"stream">>;
324+
%% for cases where this function is used for
325+
%% formatting of values that already might use these
326+
%% short aliases
327+
short_alias_of(<<"quorum">>) ->
328+
<<"quorum">>;
329+
short_alias_of(<<"classic">>) ->
330+
<<"classic">>;
331+
short_alias_of(<<"stream">>) ->
332+
<<"stream">>;
320333
short_alias_of(_Other) ->
321334
undefined.
322335

@@ -343,6 +356,10 @@ default() ->
343356
fallback()),
344357
rabbit_data_coercion:to_atom(V).
345358

359+
-spec default_alias() -> binary().
360+
default_alias() ->
361+
short_alias_of(default()).
362+
346363
-spec to_binary(module()) -> binary().
347364
to_binary(rabbit_classic_queue) ->
348365
<<"classic">>;
@@ -833,6 +850,29 @@ known_queue_type_names() ->
833850
QTypeBins = lists:map(fun(X) -> atom_to_binary(X) end, QueueTypes),
834851
?KNOWN_QUEUE_TYPES ++ QTypeBins.
835852

853+
inject_dqt(VHost) when ?is_vhost(VHost) ->
854+
inject_dqt(vhost:to_map(VHost));
855+
inject_dqt(VHost) when is_list(VHost) ->
856+
inject_dqt(rabbit_data_coercion:to_map(VHost));
857+
inject_dqt(M = #{default_queue_type := undefined}) ->
858+
NQT = short_alias_of(default()),
859+
Meta0 = maps:get(metadata, M, #{}),
860+
Meta = Meta0#{default_queue_type => NQT},
861+
862+
M#{default_queue_type => NQT, metadata => Meta};
863+
inject_dqt(M = #{default_queue_type := DQT}) ->
864+
NQT = short_alias_of(DQT),
865+
Meta0 = maps:get(metadata, M, #{}),
866+
Meta = Meta0#{default_queue_type => NQT},
867+
868+
M#{default_queue_type => NQT, metadata => Meta}.
869+
870+
-spec vhosts_with_dqt([any()]) -> [map()].
871+
vhosts_with_dqt(List) when is_list(List) ->
872+
%% inject DQT (default queue type) at the top level and
873+
%% its metadata
874+
lists:map(fun inject_dqt/1, List).
875+
836876
-spec check_queue_limits(amqqueue:amqqueue()) ->
837877
ok |
838878
{error, queue_limit_exceeded, Reason :: string(), Args :: term()}.

deps/rabbit/src/rabbit_vhost.erl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -511,13 +511,14 @@ default_queue_type(VirtualHost) ->
511511
default_queue_type(VirtualHost, rabbit_queue_type:fallback()).
512512
-spec default_queue_type(VirtualHost :: vhost:name(), Fallback :: rabbit_queue_type:queue_type()) -> rabbit_queue_type:queue_type().
513513
default_queue_type(VirtualHost, FallbackQueueType) ->
514+
NodeDefault = application:get_env(rabbit, default_queue_type, FallbackQueueType),
514515
case exists(VirtualHost) of
515-
false -> FallbackQueueType;
516+
false -> NodeDefault;
516517
true ->
517518
Record = lookup(VirtualHost),
518519
case vhost:get_default_queue_type(Record) of
519-
undefined -> FallbackQueueType;
520-
<<"undefined">> -> FallbackQueueType;
520+
undefined -> NodeDefault;
521+
<<"undefined">> -> NodeDefault;
521522
Type -> Type
522523
end
523524
end.
@@ -622,8 +623,19 @@ i(tracing, VHost) -> rabbit_trace:enabled(vhost:get_name(VHost));
622623
i(cluster_state, VHost) -> vhost_cluster_state(vhost:get_name(VHost));
623624
i(description, VHost) -> vhost:get_description(VHost);
624625
i(tags, VHost) -> vhost:get_tags(VHost);
625-
i(default_queue_type, VHost) -> vhost:get_default_queue_type(VHost);
626-
i(metadata, VHost) -> vhost:get_metadata(VHost);
626+
i(default_queue_type, VHost) -> rabbit_queue_type:short_alias_of(default_queue_type(vhost:get_name(VHost)));
627+
i(metadata, VHost) ->
628+
DQT = rabbit_queue_type:short_alias_of(default_queue_type(vhost:get_name(VHost))),
629+
case vhost:get_metadata(VHost) of
630+
undefined ->
631+
#{default_queue_type => DQT};
632+
M = #{default_queue_type := undefined} ->
633+
M#{default_queue_type => DQT};
634+
M = #{default_queue_type := QT} ->
635+
M#{default_queue_type => rabbit_queue_type:short_alias_of(QT)};
636+
M when is_map(M) ->
637+
M#{default_queue_type => DQT}
638+
end;
627639
i(Item, VHost) ->
628640
rabbit_log:error("Don't know how to compute a virtual host info item '~ts' for virtual host '~tp'", [Item, VHost]),
629641
throw({bad_argument, Item}).

deps/rabbit/src/vhost.erl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626
get_description/1,
2727
get_tags/1,
2828
get_default_queue_type/1,
29+
2930
set_limits/2,
3031
set_metadata/2,
3132
merge_metadata/2,
3233
new_metadata/3,
33-
is_tagged_with/2
34+
is_tagged_with/2,
35+
36+
to_map/1
3437
]).
3538

3639
-define(record_version, vhost_v2).
@@ -196,3 +199,13 @@ new_metadata(Description, Tags, DefaultQueueType) ->
196199
-spec is_tagged_with(vhost(), tag()) -> boolean().
197200
is_tagged_with(VHost, Tag) ->
198201
lists:member(Tag, get_tags(VHost)).
202+
203+
-spec to_map(vhost()) -> map().
204+
to_map(VHost) ->
205+
#{
206+
name => get_name(VHost),
207+
description => get_description(VHost),
208+
tags => get_tags(VHost),
209+
default_queue_type => get_default_queue_type(VHost),
210+
metadata => get_metadata(VHost)
211+
}.

deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/export_definitions_command.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## License, v. 2.0. If a copy of the MPL was not distributed with this
33
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
44
##
5-
## Copyright (c) 2007-2023 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
5+
## Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
66

77
defmodule RabbitMQ.CLI.Ctl.Commands.ExportDefinitionsCommand do
88
alias RabbitMQ.CLI.Core.{DocGuide, ExitCodes, Helpers}

deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/list_vhosts_command.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ defmodule RabbitMQ.CLI.Ctl.Commands.ListVhostsCommand do
1919
use RabbitMQ.CLI.Core.AcceptsDefaultSwitchesAndTimeout
2020

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

deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
add_vhost/2,
112112
add_vhost/3,
113113
add_vhost/4,
114+
update_vhost_metadata/3,
114115
delete_vhost/2,
115116
delete_vhost/3,
116117
delete_vhost/4,
@@ -1541,6 +1542,9 @@ add_vhost(Config, Node, VHost) ->
15411542
add_vhost(Config, Node, VHost, Username) ->
15421543
catch rpc(Config, Node, rabbit_vhost, add, [VHost, Username]).
15431544

1545+
update_vhost_metadata(Config, VHost, Meta) ->
1546+
catch rpc(Config, 0, rabbit_vhost, update_metadata, [VHost, Meta, <<"acting-user">>]).
1547+
15441548
delete_vhost(Config, VHost) ->
15451549
delete_vhost(Config, 0, VHost).
15461550

deps/rabbitmq_management/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ rabbitmq_integration_suite(
167167
additional_beam = [
168168
"test/rabbit_mgmt_runtime_parameters_util.beam",
169169
],
170-
shard_count = 6,
170+
shard_count = 7,
171171
runtime_deps = [
172172
"//deps/amqp10_client:erlang_app",
173173
],

0 commit comments

Comments
 (0)