From 8c6ba6dacab1d1b673169c32d9abcb3c37edced8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20Dominique?= Date: Tue, 26 Sep 2023 15:09:55 -0400 Subject: [PATCH] Add Classic Queue version to operator policies --- deps/rabbit/priv/schema/rabbit.schema | 6 ++++ deps/rabbit/src/rabbit_policies.erl | 5 +++- .../config_schema_SUITE_data/rabbit.snippets | 2 ++ deps/rabbit/test/policy_SUITE.erl | 28 +++++++++++++++++-- .../priv/www/js/tmpl/policies.ejs | 3 +- 5 files changed, 40 insertions(+), 4 deletions(-) diff --git a/deps/rabbit/priv/schema/rabbit.schema b/deps/rabbit/priv/schema/rabbit.schema index d250e95f1094..977861f054f4 100644 --- a/deps/rabbit/priv/schema/rabbit.schema +++ b/deps/rabbit/priv/schema/rabbit.schema @@ -782,6 +782,12 @@ end}. {datatype, string} ]}. +{mapping, "default_policies.operator.$id.classic_queues.queue_version", "rabbit.default_policies.operator", + [ + {validators, ["non_zero_positive_integer"]}, + {datatype, integer} + ]}. + {translation, "rabbit.default_policies.operator", fun(Conf) -> Props = rabbit_cuttlefish:aggregate_props( Conf, diff --git a/deps/rabbit/src/rabbit_policies.erl b/deps/rabbit/src/rabbit_policies.erl index a6677e8a534e..c01f8a480437 100644 --- a/deps/rabbit/src/rabbit_policies.erl +++ b/deps/rabbit/src/rabbit_policies.erl @@ -54,13 +54,15 @@ register() -> {operator_policy_validator, <<"max-in-memory-length">>}, {operator_policy_validator, <<"max-in-memory-bytes">>}, {operator_policy_validator, <<"delivery-limit">>}, + {operator_policy_validator, <<"queue-version">>}, {policy_merge_strategy, <<"expires">>}, {policy_merge_strategy, <<"message-ttl">>}, {policy_merge_strategy, <<"max-length">>}, {policy_merge_strategy, <<"max-length-bytes">>}, {policy_merge_strategy, <<"max-in-memory-length">>}, {policy_merge_strategy, <<"max-in-memory-bytes">>}, - {policy_merge_strategy, <<"delivery-limit">>}]], + {policy_merge_strategy, <<"delivery-limit">>}, + {policy_merge_strategy, <<"queue-version">>}]], ok. -spec validate_policy([{binary(), term()}]) -> rabbit_policy_validator:validate_results(). @@ -211,5 +213,6 @@ merge_policy_value(<<"max-in-memory-length">>, Val, OpVal) -> min(Val, OpVal); merge_policy_value(<<"max-in-memory-bytes">>, Val, OpVal) -> min(Val, OpVal); merge_policy_value(<<"expires">>, Val, OpVal) -> min(Val, OpVal); merge_policy_value(<<"delivery-limit">>, Val, OpVal) -> min(Val, OpVal); +merge_policy_value(<<"queue-version">>, _Val, OpVal) -> OpVal; %% use operator policy value for booleans merge_policy_value(_Key, Val, OpVal) when is_boolean(Val) andalso is_boolean(OpVal) -> OpVal. diff --git a/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets b/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets index 5904066eee70..5b2879de35ed 100644 --- a/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets +++ b/deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets @@ -151,6 +151,7 @@ ssl_options.fail_if_no_peer_cert = true", 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, [ @@ -159,6 +160,7 @@ ssl_options.fail_if_no_peer_cert = true", {<<"ha_params">>, 2}, {<<"ha_sync_mode">>, <<"automatic">>}, {<<"queue_pattern">>, <<"apple">>}, + {<<"queue_version">>, 2}, {<<"vhost_pattern">>, "banana"}]}]}]}]}], []}, diff --git a/deps/rabbit/test/policy_SUITE.erl b/deps/rabbit/test/policy_SUITE.erl index 905e9a477ddd..952b7b9dea0a 100644 --- a/deps/rabbit/test/policy_SUITE.erl +++ b/deps/rabbit/test/policy_SUITE.erl @@ -28,6 +28,7 @@ groups() -> operator_retroactive_policy_ttl, operator_retroactive_policy_publish_ttl, queue_type_specific_policies, + queue_version_specific_policies, is_supported_operator_policy_expires, is_supported_operator_policy_message_ttl, is_supported_operator_policy_max_length, @@ -256,6 +257,29 @@ queue_type_specific_policies(Config) -> rabbit_ct_client_helpers:close_connection(Conn), passed. +queue_version_specific_policies(Config) -> + [Server | _] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename), + {Conn, Ch} = rabbit_ct_client_helpers:open_connection_and_channel(Config, 0), + QName = <<"policy_queue_version">>, + declare(Ch, QName), + QueueVersionOnePolicy = [{<<"queue-version">>, 1}], + QueueVersionTwoPolicy = [{<<"queue-version">>, 2}], + + Opts = #{config => Config, + server => Server, + qname => QName}, + + %% Queue version OperPolicy has precedence always + verify_policies(QueueVersionOnePolicy, QueueVersionTwoPolicy, QueueVersionTwoPolicy, Opts), + verify_policies(QueueVersionTwoPolicy, QueueVersionOnePolicy, QueueVersionOnePolicy, Opts), + + delete(Ch, QName), + rabbit_ct_broker_helpers:clear_policy(Config, 0, <<"policy">>), + rabbit_ct_broker_helpers:clear_operator_policy(Config, 0, <<"op_policy">>), + rabbit_ct_client_helpers:close_channel(Ch), + rabbit_ct_client_helpers:close_connection(Conn), + passed. + %% See supported policies in https://www.rabbitmq.com/parameters.html#operator-policies %% This test applies all supported operator policies to all queue types, %% and later verifies the effective policy definitions. @@ -433,10 +457,10 @@ verify_policies(Policy, OperPolicy, VerifyFuns, #{config := Config, server := Server, qname := QName}) -> rabbit_ct_broker_helpers:set_policy(Config, 0, <<"policy">>, - <<"policy_ha">>, <<"queues">>, + QName, <<"queues">>, Policy), rabbit_ct_broker_helpers:set_operator_policy(Config, 0, <<"op_policy">>, - <<"policy_ha">>, <<"queues">>, + QName, <<"queues">>, OperPolicy), verify_policy(VerifyFuns, Server, QName). diff --git a/deps/rabbitmq_management/priv/www/js/tmpl/policies.ejs b/deps/rabbitmq_management/priv/www/js/tmpl/policies.ejs index 50d3d8b3a562..855d8c83638d 100644 --- a/deps/rabbitmq_management/priv/www/js/tmpl/policies.ejs +++ b/deps/rabbitmq_management/priv/www/js/tmpl/policies.ejs @@ -288,7 +288,8 @@ HA sync mode
Max length | Max length bytes | - Message TTL + Message TTL | + Version