Skip to content

Commit 5de5a18

Browse files
Merge pull request #14298 from rabbitmq/mergify/bp/v4.1.x/pr-14278
For 4.1.4: rabbitmqctl shovel_status: handle metrics (backport #14278)
2 parents 41b319a + 052085d commit 5de5a18

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

deps/rabbitmq_shovel/src/Elixir.RabbitMQ.CLI.Ctl.Commands.ShovelStatusCommand.erl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ aliases() ->
7575
[].
7676

7777
output({stream, ShovelStatus}, _Opts) ->
78-
Formatted = [fmt_name(Name,
79-
fmt_status(Status,
80-
#{type => Type,
81-
last_changed => fmt_ts(Timestamp)}))
82-
|| {Name, Type, Status, Timestamp} <- ShovelStatus],
78+
Formatted = [fmt_metrics(Metrics,
79+
fmt_name(Name,
80+
fmt_status(Status,
81+
#{type => Type,
82+
last_changed => fmt_ts(Timestamp)})))
83+
|| {Name, Type, Status, Metrics, Timestamp} <- ShovelStatus],
8384
{stream, Formatted};
8485
output(E, _Opts) ->
8586
'Elixir.RabbitMQ.CLI.DefaultOutput':output(E).
@@ -129,3 +130,6 @@ details_to_map(Proplist) ->
129130
{dest_exchange, destination_exchange}, {dest_exchange_key, destination_exchange_key}],
130131
maps:from_list([{New, proplists:get_value(Old, Proplist)}
131132
|| {Old, New} <- Keys, proplists:is_defined(Old, Proplist)]).
133+
134+
fmt_metrics(Metrics, Map) ->
135+
maps:merge(Metrics, Map).

deps/rabbitmq_shovel/test/shovel_status_command_SUITE.erl

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
-module(shovel_status_command_SUITE).
99

1010
-include_lib("amqp_client/include/amqp_client.hrl").
11+
-include_lib("eunit/include/eunit.hrl").
1112

1213
-compile(export_all).
1314

@@ -26,7 +27,8 @@ groups() ->
2627
run_starting,
2728
output_starting,
2829
run_running,
29-
output_running
30+
output_running,
31+
e2e
3032
]}
3133
].
3234

@@ -95,8 +97,14 @@ output_starting(Config) ->
9597
[A] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
9698
Opts = #{node => A},
9799
{stream, [#{vhost := <<"/">>, name := <<"test">>, type := dynamic,
98-
state := starting, last_changed := <<"2016-11-17 10:00:00">>}]}
100+
state := starting, last_changed := <<"2016-11-17 10:00:00">>,
101+
remaining := 10, remaining_unacked := 8,
102+
pending := 5, forwarded := 3}]}
99103
= ?CMD:output({stream, [{{<<"/">>, <<"test">>}, dynamic, starting,
104+
#{remaining => 10,
105+
remaining_unacked => 8,
106+
pending => 5,
107+
forwarded => 3},
100108
{{2016, 11, 17}, {10, 00, 00}}}]}, Opts),
101109
shovel_test_utils:clear_param(Config, <<"test">>).
102110

@@ -118,9 +126,43 @@ output_running(Config) ->
118126
state := running, source := <<"amqp://server-1">>,
119127
destination := <<"amqp://server-2">>,
120128
termination_reason := <<>>,
121-
last_changed := <<"2016-11-17 10:00:00">>}]} =
129+
last_changed := <<"2016-11-17 10:00:00">>,
130+
remaining := 10,
131+
remaining_unacked := 8,
132+
pending := 5,
133+
forwarded := 3}]} =
122134
?CMD:output({stream, [{{<<"/">>, <<"test">>}, dynamic,
123135
{running, [{src_uri, <<"amqp://server-1">>},
124136
{dest_uri, <<"amqp://server-2">>}]},
137+
#{remaining => 10,
138+
remaining_unacked => 8,
139+
pending => 5,
140+
forwarded => 3},
125141
{{2016, 11, 17}, {10, 00, 00}}}]}, Opts),
126142
shovel_test_utils:clear_param(Config, <<"test">>).
143+
144+
e2e(Config) ->
145+
shovel_test_utils:set_param_nowait(
146+
Config,
147+
<<"test">>, [{<<"src-queue">>, <<"src">>},
148+
{<<"dest-queue">>, <<"dest">>}]),
149+
{ok, StdOut} = rabbit_ct_broker_helpers:rabbitmqctl(Config, 0, [<<"shovel_status">>]),
150+
[Msg, Headers0, Shovel0] = re:split(StdOut, <<"\n">>, [trim]),
151+
?assertMatch(match, re:run(Msg, "Shovel status on node", [{capture, none}])),
152+
Headers = re:split(Headers0, <<"\t">>, [trim]),
153+
ExpectedHeaders = [<<"name">>, <<"vhost">>, <<"type">>, <<"state">>,
154+
<<"source">>, <<"destination">>, <<"termination_reason">>,
155+
<<"destination_protocol">>, <<"source_protocol">>,
156+
<<"last_changed">>, <<"source_queue">>, <<"destination_queue">>,
157+
<<"remaining">>, <<"remaining_unacked">>,
158+
<<"pending">>, <<"forwarded">>],
159+
?assert(lists:all(fun(H) ->
160+
lists:member(H, Headers)
161+
end, ExpectedHeaders)),
162+
%% Check some values are there
163+
ExpectedValues = [<<"test">>, <<"dynamic">>, <<"running">>],
164+
Shovel = re:split(Shovel0, <<"\t">>, [trim]),
165+
?assert(lists:all(fun(V) ->
166+
lists:member(V, Shovel)
167+
end, ExpectedValues)),
168+
shovel_test_utils:clear_param(Config, <<"test">>).

0 commit comments

Comments
 (0)