Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Classic Queue version to operator policies #9541

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions deps/rabbit/priv/schema/rabbit.schema
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion deps/rabbit/src/rabbit_policies.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down Expand Up @@ -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.
2 changes: 2 additions & 0 deletions deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand All @@ -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"}]}]}]}]}],
[]},

Expand Down
29 changes: 26 additions & 3 deletions deps/rabbit/test/policy_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ groups() ->
operator_policy_ttl,
operator_retroactive_policy_ttl,
operator_retroactive_policy_publish_ttl,
queue_type_specific_policies
queue_type_specific_policies,
queue_version_specific_policies
]}
].

Expand Down Expand Up @@ -246,6 +247,28 @@ 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.

%%----------------------------------------------------------------------------

Expand Down Expand Up @@ -312,10 +335,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).

Expand Down
3 changes: 2 additions & 1 deletion deps/rabbitmq_management/priv/www/js/tmpl/policies.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@
<span class="argument-link" field="definitionop" key="expires" type="number">Auto expire</span>
<span class="argument-link" field="definitionop" key="ha-mode" type="string">HA mode</span> <span class="help" id="policy-ha-mode"></span> |
<span class="argument-link" field="definitionop" key="ha-params" type="number">HA params</span> <span class="help" id="policy-ha-params"></span> |
<span class="argument-link" field="definitionop" key="ha-sync-mode" type="string">HA sync mode</span> <span class="help" id="policy-ha-sync-mode"></span> </br>
<span class="argument-link" field="definitionop" key="ha-sync-mode" type="string">HA sync mode</span> <span class="help" id="policy-ha-sync-mode"></span> |
<span class="argument-link" field="definitionop" key="queue-version" type="number">Version</span> <span class="help" id="queue-version"></span> </br>
</td>
</tr>
<tr>
Expand Down
Loading