diff --git a/deps/rabbit/priv/schema/rabbit.schema b/deps/rabbit/priv/schema/rabbit.schema index 4fc42f8f3db8..b5f86d3bbb01 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 8422c8609346..3e6f93085ad6 100644 --- a/deps/rabbit/src/rabbit_policies.erl +++ b/deps/rabbit/src/rabbit_policies.erl @@ -53,13 +53,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(). @@ -204,5 +206,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 45778ba119ea..d0b0cf218ec6 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 9d4201472c7d..26bd01a985c0 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, @@ -255,6 +256,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. @@ -427,10 +451,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 7b0e7728659b..6246b56bfb22 100644 --- a/deps/rabbitmq_management/priv/www/js/tmpl/policies.ejs +++ b/deps/rabbitmq_management/priv/www/js/tmpl/policies.ejs @@ -286,7 +286,8 @@ HA sync mode
Max length | Max length bytes | - Message TTL + Message TTL | + Version