Skip to content

Commit

Permalink
Support enable_queue_totals when queue name is specified
Browse files Browse the repository at this point in the history
For `/api/queues`, users can specify `disable_stats=true` and
`enable_queue_totals=true` parameters to return a concise set of
fields. However, the `enable_queue_totals` is not currently
supported for `/api/queues/<vhost>/<name>`, probably just a small
oversight that slipped through the cracks. This commit adds that
support and updates the respective unit test, focusing on not breaking
existing public functions and on simplicity, at the cost of a slight
bit of duplication.
  • Loading branch information
aaron-seo authored and michaelklishin committed Mar 27, 2024
1 parent 26f65d7 commit 569e430
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
27 changes: 24 additions & 3 deletions deps/rabbitmq_management/src/rabbit_mgmt_wm_queue.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,13 @@ to_json(ReqData, Context) ->
rabbit_mgmt_format:strip_pids(Q)),
rabbit_mgmt_util:reply(ensure_defaults(Payload), ReqData, Context);
true ->
rabbit_mgmt_util:reply(rabbit_mgmt_format:strip_pids(queue(ReqData)),
ReqData, Context)
Q = case rabbit_mgmt_util:enable_queue_totals(ReqData) of
false -> queue(ReqData);
true -> queue_with_totals(ReqData)
end,
rabbit_mgmt_util:reply(
rabbit_mgmt_format:strip_pids(Q),
ReqData, Context)
end
catch
{error, invalid_range_parameters, Reason} ->
Expand Down Expand Up @@ -110,10 +115,26 @@ queue(ReqData) ->
VHost -> queue(VHost, rabbit_mgmt_util:id(queue, ReqData))
end.


queue(VHost, QName) ->
Name = rabbit_misc:r(VHost, queue, QName),
case rabbit_amqqueue:lookup(Name) of
{ok, Q} -> rabbit_mgmt_format:queue(Q);
{error, not_found} -> not_found
end.

queue_with_totals(ReqData) ->
case rabbit_mgmt_util:vhost(ReqData) of
not_found -> not_found;
VHost -> queue_with_totals(VHost, rabbit_mgmt_util:id(queue, ReqData))
end.

queue_with_totals(VHost, QName) ->
Name = rabbit_misc:r(VHost, queue, QName),
case rabbit_amqqueue:lookup(Name) of
{ok, Q} -> QueueInfo = rabbit_amqqueue:info(Q,
[name, durable, auto_delete, exclusive,
owner_pid, arguments, type, state,
policy, totals, online, type_specific]),
rabbit_mgmt_format:queue_info(QueueInfo);
{error, not_found} -> not_found
end.
8 changes: 4 additions & 4 deletions deps/rabbitmq_management/test/rabbit_mgmt_only_http_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,14 @@ queues_enable_totals_test(Config) ->
vhost => <<"/">>,
durable => true,
auto_delete => false,
exclusive => false,
exclusive => null,
arguments => #{'x-queue-type' => <<"quorum">>},
leader => NodeBin,
messages => 2,
messages_ready => 2,
messages_unacknowledged => 0,
members => [NodeBin]}, Queue),

?assert(not maps:is_key(messages, Queue)),
?assert(not maps:is_key(messages_ready, Queue)),
?assert(not maps:is_key(messages_unacknowledged, Queue)),
?assert(not maps:is_key(message_stats, Queue)),
?assert(not maps:is_key(messages_details, Queue)),
?assert(not maps:is_key(reductions_details, Queue)),
Expand Down

0 comments on commit 569e430

Please sign in to comment.