From accb383514c065fd1a7bec8229362840cfa5ff48 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 (cherry picked from commit 9acabdb936dfada146b0bdf9dba4189b9e8f48a6) --- 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 34d3236fa57a..28c15aeb0c22 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 a903d21f1c0c..8a82b4bc2f0f 100644 --- a/deps/rabbit/src/rabbit_classic_queue.erl +++ b/deps/rabbit/src/rabbit_classic_queue.erl @@ -94,7 +94,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 feb676a4902b..95debf1a7649 100644 --- a/deps/rabbit/src/rabbit_quorum_queue.erl +++ b/deps/rabbit/src/rabbit_quorum_queue.erl @@ -114,7 +114,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 d66b059b6fc9..16ed0b119bb9 100644 --- a/deps/rabbit/src/rabbit_stream_queue.erl +++ b/deps/rabbit/src/rabbit_stream_queue.erl @@ -129,7 +129,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 bdf5f9120e9c..1038c6257ccb 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 16b263ed52ed4a99372c1cbb18a108452c4cc66e 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 (cherry picked from commit 173b0b07be7645ec23a389f1d8cce017702cba09) --- 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 1038c6257ccb..38a5704a6d95 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 24fd8309afce3929f5d90451fc3e3a5f170669a4 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 (cherry picked from commit 37b62030fa538fb498942799551d3b5d296de0be) --- 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 38a5704a6d95..d09eabf5ee50 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"}]}]}]}]}],