Skip to content

Commit 41694bf

Browse files
Merge pull request #9549 from rabbitmq/mergify/bp/v3.11.x/pr-9548
Add Classic Queue version to operator policies (backport #9547) (backport #9548)
2 parents 6d5f54b + 0fb5082 commit 41694bf

File tree

7 files changed

+197
-11
lines changed

7 files changed

+197
-11
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ RabbitMQ documentation is also [developed on GitHub](https://github.com/rabbitmq
5151

5252
## Getting Help from the Community
5353

54-
* [Community Discord server](https://rabbitmq.com/discord/)
55-
* [Community Slack](https://rabbitmq.com/slack/)
5654
* [GitHub Discussions](https://github.com/rabbitmq/rabbitmq-server/discussions/)
57-
* [RabbitMQ mailing list](https://groups.google.com/forum/#!forum/rabbitmq-users)
55+
* [Community Discord server](https://rabbitmq.com/discord/)
5856
* `#rabbitmq` on [Libera Chat](https://libera.chat/)
5957

6058

deps/rabbit/app.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ def test_suite_beam_files(name = "test_suite_beam_files"):
11041104
outs = ["test/policy_SUITE.beam"],
11051105
app_name = "rabbit",
11061106
erlc_opts = "//:test_erlc_opts",
1107-
deps = ["//deps/amqp_client:erlang_app"],
1107+
deps = ["//deps/amqp_client:erlang_app", "//deps/rabbitmq_ct_helpers:erlang_app"],
11081108
)
11091109
erlang_bytecode(
11101110
name = "priority_queue_SUITE_beam_files",

deps/rabbit/priv/schema/rabbit.schema

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,12 @@ end}.
782782
{datatype, string}
783783
]}.
784784

785+
{mapping, "default_policies.operator.$id.classic_queues.queue_version", "rabbit.default_policies.operator",
786+
[
787+
{validators, ["non_zero_positive_integer"]},
788+
{datatype, integer}
789+
]}.
790+
785791
{translation, "rabbit.default_policies.operator", fun(Conf) ->
786792
Props = rabbit_cuttlefish:aggregate_props(
787793
Conf,

deps/rabbit/src/rabbit_policies.erl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,15 @@ register() ->
5252
{operator_policy_validator, <<"max-in-memory-length">>},
5353
{operator_policy_validator, <<"max-in-memory-bytes">>},
5454
{operator_policy_validator, <<"delivery-limit">>},
55+
{operator_policy_validator, <<"queue-version">>},
5556
{policy_merge_strategy, <<"expires">>},
5657
{policy_merge_strategy, <<"message-ttl">>},
5758
{policy_merge_strategy, <<"max-length">>},
5859
{policy_merge_strategy, <<"max-length-bytes">>},
5960
{policy_merge_strategy, <<"max-in-memory-length">>},
6061
{policy_merge_strategy, <<"max-in-memory-bytes">>},
61-
{policy_merge_strategy, <<"delivery-limit">>}]],
62+
{policy_merge_strategy, <<"delivery-limit">>},
63+
{policy_merge_strategy, <<"queue-version">>}]],
6264
ok.
6365

6466
-spec validate_policy([{binary(), term()}]) -> rabbit_policy_validator:validate_results().
@@ -197,5 +199,6 @@ merge_policy_value(<<"max-in-memory-length">>, Val, OpVal) -> min(Val, OpVal);
197199
merge_policy_value(<<"max-in-memory-bytes">>, Val, OpVal) -> min(Val, OpVal);
198200
merge_policy_value(<<"expires">>, Val, OpVal) -> min(Val, OpVal);
199201
merge_policy_value(<<"delivery-limit">>, Val, OpVal) -> min(Val, OpVal);
202+
merge_policy_value(<<"queue-version">>, _Val, OpVal) -> OpVal;
200203
%% use operator policy value for booleans
201204
merge_policy_value(_Key, Val, OpVal) when is_boolean(Val) andalso is_boolean(OpVal) -> OpVal.

deps/rabbit/test/config_schema_SUITE_data/rabbit.snippets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ ssl_options.fail_if_no_peer_cert = true",
151151
default_policies.operator.a.classic_queues.ha_mode = exactly
152152
default_policies.operator.a.classic_queues.ha_params = 2
153153
default_policies.operator.a.classic_queues.ha_sync_mode = automatic
154+
default_policies.operator.a.classic_queues.queue_version = 2
154155
155156
",
156157
[{rabbit, [{default_policies, [{operator, [
@@ -159,6 +160,7 @@ ssl_options.fail_if_no_peer_cert = true",
159160
{<<"ha_params">>, 2},
160161
{<<"ha_sync_mode">>, <<"automatic">>},
161162
{<<"queue_pattern">>, <<"apple">>},
163+
{<<"queue_version">>, 2},
162164
{<<"vhost_pattern">>, "banana"}]}]}]}]}],
163165
[]},
164166

deps/rabbit/test/policy_SUITE.erl

Lines changed: 181 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
-include_lib("common_test/include/ct.hrl").
1111
-include_lib("amqp_client/include/amqp_client.hrl").
12-
12+
-include_lib("stdlib/include/assert.hrl").
13+
-include_lib("rabbitmq_ct_helpers/include/rabbit_assert.hrl").
1314

1415
-compile(export_all).
1516

@@ -25,7 +26,17 @@ groups() ->
2526
policy_ttl,
2627
operator_policy_ttl,
2728
operator_retroactive_policy_ttl,
28-
operator_retroactive_policy_publish_ttl
29+
operator_retroactive_policy_publish_ttl,
30+
queue_type_specific_policies,
31+
queue_version_specific_policies,
32+
is_supported_operator_policy_expires,
33+
is_supported_operator_policy_message_ttl,
34+
is_supported_operator_policy_max_length,
35+
is_supported_operator_policy_max_length,
36+
is_supported_operator_policy_max_in_memory_length,
37+
is_supported_operator_policy_max_in_memory_bytes,
38+
is_supported_operator_policy_delivery_limit,
39+
is_supported_operator_policy_ha
2940
]}
3041
].
3142

@@ -208,14 +219,179 @@ target_count_policy(Config) ->
208219
rabbit_ct_client_helpers:close_connection(Conn),
209220
passed.
210221

222+
queue_type_specific_policies(Config) ->
223+
[Server | _] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
224+
{Conn, Ch} = rabbit_ct_client_helpers:open_connection_and_channel(Config, 0),
225+
ClassicQ = <<"policy_ttl-classic_queue">>,
226+
QuorumQ = <<"policy_ttl-quorum_queue">>,
227+
StreamQ = <<"policy_ttl-stream_queue">>,
228+
229+
%% all policies match ".*" but different values should be applied based on queue type
230+
rabbit_ct_broker_helpers:set_policy(Config, 0, <<"ttl-policy-classic">>,
231+
<<".*">>, <<"classic_queues">>, [{<<"message-ttl">>, 20}]),
211232

212-
%%----------------------------------------------------------------------------
233+
rabbit_ct_broker_helpers:set_policy(Config, 0, <<"ttl-policy-quorum">>,
234+
<<".*">>, <<"quorum_queues">>, [{<<"message-ttl">>, 40}]),
235+
236+
rabbit_ct_broker_helpers:set_policy(Config, 0, <<"ttl-policy-stream">>,
237+
<<".*">>, <<"streams">>, [{<<"max-age">>, "1h"}]),
238+
239+
declare(Ch, ClassicQ, [{<<"x-queue-type">>, longstr, <<"classic">>}]),
240+
declare(Ch, QuorumQ, [{<<"x-queue-type">>, longstr, <<"quorum">>}]),
241+
declare(Ch, StreamQ, [{<<"x-queue-type">>, longstr, <<"stream">>}]),
242+
timer:sleep(1),
243+
244+
?assertMatch(20, check_policy_value(Server, ClassicQ, <<"message-ttl">>)),
245+
?assertMatch(40, check_policy_value(Server, QuorumQ, <<"message-ttl">>)),
246+
?assertMatch("1h", check_policy_value(Server, StreamQ, <<"max-age">>)),
247+
248+
delete(Ch, ClassicQ),
249+
delete(Ch, QuorumQ),
250+
delete(Ch, StreamQ),
251+
rabbit_ct_broker_helpers:clear_policy(Config, 0, <<"ttl-policy-classic">>),
252+
rabbit_ct_broker_helpers:clear_policy(Config, 0, <<"ttl-policy-quorum">>),
253+
rabbit_ct_broker_helpers:clear_policy(Config, 0, <<"ttl-policy-stream">>),
254+
255+
rabbit_ct_client_helpers:close_channel(Ch),
256+
rabbit_ct_client_helpers:close_connection(Conn),
257+
passed.
258+
259+
queue_version_specific_policies(Config) ->
260+
[Server | _] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
261+
{Conn, Ch} = rabbit_ct_client_helpers:open_connection_and_channel(Config, 0),
262+
QName = <<"policy_queue_version">>,
263+
declare(Ch, QName),
264+
QueueVersionOnePolicy = [{<<"queue-version">>, 1}],
265+
QueueVersionTwoPolicy = [{<<"queue-version">>, 2}],
266+
267+
Opts = #{config => Config,
268+
server => Server,
269+
qname => QName},
270+
271+
%% Queue version OperPolicy has precedence always
272+
verify_policies(QueueVersionOnePolicy, QueueVersionTwoPolicy, QueueVersionTwoPolicy, Opts),
273+
verify_policies(QueueVersionTwoPolicy, QueueVersionOnePolicy, QueueVersionOnePolicy, Opts),
274+
275+
delete(Ch, QName),
276+
rabbit_ct_broker_helpers:clear_policy(Config, 0, <<"policy">>),
277+
rabbit_ct_broker_helpers:clear_operator_policy(Config, 0, <<"op_policy">>),
278+
rabbit_ct_client_helpers:close_channel(Ch),
279+
rabbit_ct_client_helpers:close_connection(Conn),
280+
passed.
281+
282+
%% See supported policies in https://www.rabbitmq.com/parameters.html#operator-policies
283+
%% This test applies all supported operator policies to all queue types,
284+
%% and later verifies the effective policy definitions.
285+
%% Just those supported by each queue type should be present.
286+
287+
is_supported_operator_policy_expires(Config) ->
288+
Value = 6000000,
289+
effective_operator_policy_per_queue_type(
290+
Config, <<"expires">>, Value, Value, Value, undefined).
291+
292+
is_supported_operator_policy_message_ttl(Config) ->
293+
Value = 1000,
294+
effective_operator_policy_per_queue_type(
295+
Config, <<"message-ttl">>, Value, Value, Value, undefined).
296+
297+
is_supported_operator_policy_max_length(Config) ->
298+
Value = 500,
299+
effective_operator_policy_per_queue_type(
300+
Config, <<"max-length">>, Value, Value, Value, undefined).
301+
302+
is_supported_operator_policy_max_length_bytes(Config) ->
303+
Value = 1500,
304+
effective_operator_policy_per_queue_type(
305+
Config, <<"max-length-bytes">>, Value, Value, Value, Value).
306+
307+
is_supported_operator_policy_max_in_memory_length(Config) ->
308+
Value = 30,
309+
effective_operator_policy_per_queue_type(
310+
Config, <<"max-in-memory-length">>, Value, undefined, Value, undefined).
311+
312+
is_supported_operator_policy_max_in_memory_bytes(Config) ->
313+
Value = 50000,
314+
effective_operator_policy_per_queue_type(
315+
Config, <<"max-in-memory-bytes">>, Value, undefined, Value, undefined).
316+
317+
is_supported_operator_policy_delivery_limit(Config) ->
318+
Value = 3,
319+
effective_operator_policy_per_queue_type(
320+
Config, <<"delivery-limit">>, Value, undefined, Value, undefined).
321+
322+
is_supported_operator_policy_ha(Config) ->
323+
[Server | _] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
324+
{Conn, Ch} = rabbit_ct_client_helpers:open_connection_and_channel(Config, 0),
325+
ClassicQ = <<"classic_queue">>,
326+
QuorumQ = <<"quorum_queue">>,
327+
StreamQ = <<"stream_queue">>,
328+
329+
declare(Ch, ClassicQ, [{<<"x-queue-type">>, longstr, <<"classic">>}]),
330+
declare(Ch, QuorumQ, [{<<"x-queue-type">>, longstr, <<"quorum">>}]),
331+
declare(Ch, StreamQ, [{<<"x-queue-type">>, longstr, <<"stream">>}]),
332+
333+
rabbit_ct_broker_helpers:set_operator_policy(
334+
Config, 0, <<"operator-policy">>, <<".*">>, <<"all">>,
335+
[{<<"ha-mode">>, <<"exactly">>},
336+
{<<"ha-params">>, 2},
337+
{<<"ha-sync-mode">>, <<"automatic">>}]),
338+
339+
?awaitMatch(<<"exactly">>, check_policy_value(Server, ClassicQ, <<"ha-mode">>), 30_000),
340+
?awaitMatch(2, check_policy_value(Server, ClassicQ, <<"ha-params">>), 30_000),
341+
?awaitMatch(<<"automatic">>, check_policy_value(Server, ClassicQ, <<"ha-sync-mode">>), 30_000),
342+
?awaitMatch(undefined, check_policy_value(Server, QuorumQ, <<"ha-mode">>), 30_000),
343+
?awaitMatch(undefined, check_policy_value(Server, StreamQ, <<"ha-mode">>), 30_000),
344+
345+
rabbit_ct_broker_helpers:clear_operator_policy(Config, 0, <<"operator-policy">>),
346+
347+
delete(Ch, ClassicQ),
348+
delete(Ch, QuorumQ),
349+
delete(Ch, StreamQ),
350+
351+
rabbit_ct_client_helpers:close_channel(Ch),
352+
rabbit_ct_client_helpers:close_connection(Conn),
353+
passed.
354+
355+
effective_operator_policy_per_queue_type(Config, Name, Value, ClassicValue, QuorumValue, StreamValue) ->
356+
[Server | _] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
357+
{Conn, Ch} = rabbit_ct_client_helpers:open_connection_and_channel(Config, 0),
358+
ClassicQ = <<"classic_queue">>,
359+
QuorumQ = <<"quorum_queue">>,
360+
StreamQ = <<"stream_queue">>,
361+
362+
declare(Ch, ClassicQ, [{<<"x-queue-type">>, longstr, <<"classic">>}]),
363+
declare(Ch, QuorumQ, [{<<"x-queue-type">>, longstr, <<"quorum">>}]),
364+
declare(Ch, StreamQ, [{<<"x-queue-type">>, longstr, <<"stream">>}]),
365+
366+
rabbit_ct_broker_helpers:set_operator_policy(
367+
Config, 0, <<"operator-policy">>, <<".*">>, <<"all">>,
368+
[{Name, Value}]),
369+
370+
?awaitMatch(ClassicValue, check_policy_value(Server, ClassicQ, Name), 30_000),
371+
?awaitMatch(QuorumValue, check_policy_value(Server, QuorumQ, Name), 30_000),
372+
?awaitMatch(StreamValue, check_policy_value(Server, StreamQ, Name), 30_000),
213373

374+
rabbit_ct_broker_helpers:clear_operator_policy(Config, 0, <<"operator-policy">>),
375+
376+
delete(Ch, ClassicQ),
377+
delete(Ch, QuorumQ),
378+
delete(Ch, StreamQ),
379+
380+
rabbit_ct_client_helpers:close_channel(Ch),
381+
rabbit_ct_client_helpers:close_connection(Conn),
382+
passed.
383+
384+
%%----------------------------------------------------------------------------
214385

215386
declare(Ch, Q) ->
216387
amqp_channel:call(Ch, #'queue.declare'{queue = Q,
217388
durable = true}).
218389

390+
declare(Ch, Q, Args) ->
391+
amqp_channel:call(Ch, #'queue.declare'{queue = Q,
392+
durable = true,
393+
arguments = Args}).
394+
219395
delete(Ch, Q) ->
220396
amqp_channel:call(Ch, #'queue.delete'{queue = Q}).
221397

@@ -269,10 +445,10 @@ verify_policies(Policy, OperPolicy, VerifyFuns, #{config := Config,
269445
server := Server,
270446
qname := QName}) ->
271447
rabbit_ct_broker_helpers:set_policy(Config, 0, <<"policy">>,
272-
<<"policy_ha">>, <<"queues">>,
448+
QName, <<"queues">>,
273449
Policy),
274450
rabbit_ct_broker_helpers:set_operator_policy(Config, 0, <<"op_policy">>,
275-
<<"policy_ha">>, <<"queues">>,
451+
QName, <<"queues">>,
276452
OperPolicy),
277453
verify_policy(VerifyFuns, Server, QName).
278454

deps/rabbitmq_management/priv/www/js/tmpl/policies.ejs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@
288288
<span class="argument-link" field="definitionop" key="expires" type="number">Auto expire</span>
289289
<span class="argument-link" field="definitionop" key="ha-mode" type="string">HA mode</span> <span class="help" id="policy-ha-mode"></span> |
290290
<span class="argument-link" field="definitionop" key="ha-params" type="number">HA params</span> <span class="help" id="policy-ha-params"></span> |
291-
<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>
291+
<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> |
292+
<span class="argument-link" field="definitionop" key="queue-version" type="number">Version</span> <span class="help" id="queue-version"></span> </br>
292293
</td>
293294
</tr>
294295
<tr>

0 commit comments

Comments
 (0)