From 9acabdb936dfada146b0bdf9dba4189b9e8f48a6 Mon Sep 17 00:00:00 2001 From: Simon Unge Date: Wed, 19 Nov 2025 19:38:00 +0000 Subject: [PATCH 1/3] Add apply_to to default oper policy, and fix boot steps --- deps/rabbit/priv/schema/rabbit.schema | 8 +++++++- deps/rabbit/src/rabbit_classic_queue.erl | 2 +- deps/rabbit/src/rabbit_db_vhost_defaults.erl | 14 +++++++++----- deps/rabbit/src/rabbit_quorum_queue.erl | 3 ++- deps/rabbit/src/rabbit_stream_queue.erl | 3 ++- .../test/config_schema_SUITE_data/rabbit.snippets | 1 + 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/deps/rabbit/priv/schema/rabbit.schema b/deps/rabbit/priv/schema/rabbit.schema index f0df90c2a227..d1862de2132e 100644 --- a/deps/rabbit/priv/schema/rabbit.schema +++ b/deps/rabbit/priv/schema/rabbit.schema @@ -749,6 +749,10 @@ end}. {datatype, string} ]}. +{mapping, "default_policies.operator.$id.apply_to", "rabbit.default_policies.operator", [ + {datatype, string} +]}. + {mapping, "default_policies.operator.$id.expires", "rabbit.default_policies.operator", [ {datatype, {duration, ms}} ]}. @@ -815,7 +819,9 @@ end}. end, {["default_policies","operator",ID|T], NewV}; ({["default_policies","operator",ID, "queue_pattern"], V}) -> - {["default_policies","operator",ID,"queue_pattern"], list_to_binary(V)}; + {["default_policies","operator",ID, "queue_pattern"], list_to_binary(V)}; + ({["default_policies","operator",ID, "apply_to"], V}) -> + {["default_policies","operator",ID, "apply_to"], list_to_binary(V)}; (E) -> E end), case Props of diff --git a/deps/rabbit/src/rabbit_classic_queue.erl b/deps/rabbit/src/rabbit_classic_queue.erl index 97115a07ac8a..4ec5e58df441 100644 --- a/deps/rabbit/src/rabbit_classic_queue.erl +++ b/deps/rabbit/src/rabbit_classic_queue.erl @@ -91,7 +91,7 @@ {cleanup, {rabbit_registry, unregister, [queue, <<"classic">>]}}, {requires, rabbit_registry}, - {enables, ?MODULE}]}). + {enables, [?MODULE, rabbit_policy]}]}). -rabbit_boot_step( {?MODULE, diff --git a/deps/rabbit/src/rabbit_db_vhost_defaults.erl b/deps/rabbit/src/rabbit_db_vhost_defaults.erl index 952006f703b8..1c99283364a0 100644 --- a/deps/rabbit/src/rabbit_db_vhost_defaults.erl +++ b/deps/rabbit/src/rabbit_db_vhost_defaults.erl @@ -18,7 +18,8 @@ -record(seeding_policy, { name :: binary(), queue_pattern = <<".*">> :: binary(), - definition = [] :: definitions() + definition = [] :: definitions(), + apply_to = <<"all">> }). -type seeded_user_properties() :: #{ @@ -43,9 +44,9 @@ apply(VHost, ActingUser) -> end, lists:foreach( fun(P) -> - ok = rabbit_policy:set_op(VHost, P#seeding_policy.name, P#seeding_policy.queue_pattern, P#seeding_policy.definition, - undefined, undefined, ActingUser), - ?LOG_INFO("Applied default operator policy to vhost '~tp': ~tp", [VHost, P]) + ok = rabbit_policy:set_op(VHost, P#seeding_policy.name, P#seeding_policy.queue_pattern, P#seeding_policy.definition, + undefined, P#seeding_policy.apply_to, ActingUser), + ?LOG_INFO("Applied default operator policy to vhost '~tp': ~tp", [VHost, P]) end, list_operator_policies(VHost) ), @@ -93,12 +94,15 @@ list_operator_policies(VHost) -> case re:run(VHost, RE, [{capture, none}]) of match -> QPattern = proplists:get_value(<<"queue_pattern">>, Ss, <<".*">>), + ApplyTo = proplists:get_value(<<"apply_to">>, Ss, <<"all">>), Ss1 = proplists:delete(<<"queue_pattern">>, Ss), Ss2 = proplists:delete(<<"vhost_pattern">>, Ss1), + Ss3 = proplists:delete(<<"apply_to">>, Ss2), {true, #seeding_policy{ name = PolicyName, queue_pattern = QPattern, - definition = underscore_to_dash(Ss2) + apply_to = ApplyTo, + definition = underscore_to_dash(Ss3) }}; _ -> false diff --git a/deps/rabbit/src/rabbit_quorum_queue.erl b/deps/rabbit/src/rabbit_quorum_queue.erl index 205f42fe1ef4..9f0c04546abf 100644 --- a/deps/rabbit/src/rabbit_quorum_queue.erl +++ b/deps/rabbit/src/rabbit_quorum_queue.erl @@ -112,7 +112,8 @@ [queue, <<"quorum">>, ?MODULE]}}, {cleanup, {rabbit_registry, unregister, [queue, <<"quorum">>]}}, - {requires, rabbit_registry}]}). + {requires, rabbit_registry}, + {enables, rabbit_policy}]}). -type msg_id() :: non_neg_integer(). -type qmsg() :: {rabbit_types:r('queue'), pid(), msg_id(), boolean(), diff --git a/deps/rabbit/src/rabbit_stream_queue.erl b/deps/rabbit/src/rabbit_stream_queue.erl index 4d4bf7d506a8..863b9d77dd61 100644 --- a/deps/rabbit/src/rabbit_stream_queue.erl +++ b/deps/rabbit/src/rabbit_stream_queue.erl @@ -126,7 +126,8 @@ [queue, <<"stream">>, ?MODULE]}}, {cleanup, {rabbit_registry, unregister, [queue, <<"stream">>]}}, - {requires, rabbit_registry} + {requires, rabbit_registry}, + {enables, rabbit_policy} ]}). -type client() :: #stream_client{}. diff --git a/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets b/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets index 7d0370e5eb5d..8a18767a13f5 100644 --- a/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets +++ b/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets @@ -199,6 +199,7 @@ ssl_options.fail_if_no_peer_cert = true", default_policies.operator.a.expires = 1h default_policies.operator.a.queue_pattern = apple default_policies.operator.a.vhost_pattern = banana + default_policies.operator.a.apply_to = quorum_queues default_policies.operator.a.classic_queues.ha_mode = exactly default_policies.operator.a.classic_queues.ha_params = 2 default_policies.operator.a.classic_queues.ha_sync_mode = automatic From 173b0b07be7645ec23a389f1d8cce017702cba09 Mon Sep 17 00:00:00 2001 From: Simon Unge Date: Wed, 19 Nov 2025 21:06:55 +0000 Subject: [PATCH 2/3] Add forgotten expect --- deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets b/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets index 8a18767a13f5..aa7a5f2a6c03 100644 --- a/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets +++ b/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets @@ -207,7 +207,8 @@ ssl_options.fail_if_no_peer_cert = true", ", [{rabbit, [{default_policies, [{operator, [ - {<<"a">>, [{<<"expires">>, 3600000}, + {<<"a">>, [{<<"apply_to">>,<<"quorum_queues">>}, + {<<"expires">>, 3600000}, {<<"ha_mode">>, <<"exactly">>}, {<<"ha_params">>, 2}, {<<"ha_sync_mode">>, <<"automatic">>}, From 37b62030fa538fb498942799551d3b5d296de0be Mon Sep 17 00:00:00 2001 From: Michael Klishin Date: Thu, 20 Nov 2025 15:53:53 -0800 Subject: [PATCH 3/3] Use modern policy keys in this snippet --- deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets | 6 ------ 1 file changed, 6 deletions(-) diff --git a/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets b/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets index aa7a5f2a6c03..9cd8d7cad902 100644 --- a/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets +++ b/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets @@ -200,18 +200,12 @@ ssl_options.fail_if_no_peer_cert = true", default_policies.operator.a.queue_pattern = apple default_policies.operator.a.vhost_pattern = banana default_policies.operator.a.apply_to = quorum_queues - default_policies.operator.a.classic_queues.ha_mode = exactly - default_policies.operator.a.classic_queues.ha_params = 2 - default_policies.operator.a.classic_queues.ha_sync_mode = automatic default_policies.operator.a.classic_queues.queue_version = 2 ", [{rabbit, [{default_policies, [{operator, [ {<<"a">>, [{<<"apply_to">>,<<"quorum_queues">>}, {<<"expires">>, 3600000}, - {<<"ha_mode">>, <<"exactly">>}, - {<<"ha_params">>, 2}, - {<<"ha_sync_mode">>, <<"automatic">>}, {<<"queue_pattern">>, <<"apple">>}, {<<"queue_version">>, 2}, {<<"vhost_pattern">>, "banana"}]}]}]}]}],