Merge pull request #13628 from rabbitmq/ik-13620-shovel-forward-counter-followup

RMQ-1263: An attempt to make shovel status tuple handling backwards compatible
This commit is contained in:
Michael Klishin 2025-03-26 16:20:46 -04:00 committed by GitHub
commit 9439756d62
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 26 deletions

View File

@ -76,23 +76,27 @@ run([Name], #{node := Node, vhost := VHost}) ->
undefined -> undefined ->
try_force_removing(Node, VHost, Name, ActingUser), try_force_removing(Node, VHost, Name, ActingUser),
{error, rabbit_data_coercion:to_binary(ErrMsg)}; {error, rabbit_data_coercion:to_binary(ErrMsg)};
Match -> {{_Name, _VHost}, _Type, {_State, Opts}, _Metrics, _Timestamp} ->
{{_Name, _VHost}, _Type, {_State, Opts}, _Metrics, _Timestamp} = Match, delete_shovel(ErrMsg, VHost, Name, ActingUser, Opts, Node);
{_, HostingNode} = lists:keyfind(node, 1, Opts), {{_Name, _VHost}, _Type, {_State, Opts}, _Timestamp} ->
case rabbit_misc:rpc_call( delete_shovel(ErrMsg, VHost, Name, ActingUser, Opts, Node)
HostingNode, rabbit_shovel_util, delete_shovel, [VHost, Name, ActingUser]) of
{badrpc, _} = Error ->
Error;
{error, not_found} ->
try_force_removing(HostingNode, VHost, Name, ActingUser),
{error, rabbit_data_coercion:to_binary(ErrMsg)};
ok ->
_ = try_clearing_runtime_parameter(Node, VHost, Name, ActingUser),
ok
end
end end
end. end.
delete_shovel(ErrMsg, VHost, Name, ActingUser, Opts, Node) ->
{_, HostingNode} = lists:keyfind(node, 1, Opts),
case rabbit_misc:rpc_call(
HostingNode, rabbit_shovel_util, delete_shovel, [VHost, Name, ActingUser]) of
{badrpc, _} = Error ->
Error;
{error, not_found} ->
try_force_removing(HostingNode, VHost, Name, ActingUser),
{error, rabbit_data_coercion:to_binary(ErrMsg)};
ok ->
_ = try_clearing_runtime_parameter(Node, VHost, Name, ActingUser),
ok
end.
switches() -> switches() ->
[]. [].

View File

@ -62,20 +62,24 @@ run([Name], #{node := Node, vhost := VHost}) ->
case rabbit_shovel_status:find_matching_shovel(VHost, Name, Xs) of case rabbit_shovel_status:find_matching_shovel(VHost, Name, Xs) of
undefined -> undefined ->
{error, rabbit_data_coercion:to_binary(ErrMsg)}; {error, rabbit_data_coercion:to_binary(ErrMsg)};
Match -> {{_Name, _VHost}, _Type, {_State, Opts}, _Metrics, _Timestamp} ->
{{_Name, _VHost}, _Type, {_State, Opts}, _Metrics, _Timestamp} = Match, restart_shovel(ErrMsg, Name, VHost, Opts);
{_, HostingNode} = lists:keyfind(node, 1, Opts), {{_Name, _VHost}, _Type, {_State, Opts}, _Timestamp} ->
case rabbit_misc:rpc_call( restart_shovel(ErrMsg, Name, VHost, Opts)
HostingNode, rabbit_shovel_util, restart_shovel, [VHost, Name]) of
{badrpc, _} = Error ->
Error;
{error, not_found} ->
{error, rabbit_data_coercion:to_binary(ErrMsg)};
ok -> ok
end
end end
end. end.
restart_shovel(ErrMsg, Name, VHost, Opts) ->
{_, HostingNode} = lists:keyfind(node, 1, Opts),
case rabbit_misc:rpc_call(
HostingNode, rabbit_shovel_util, restart_shovel, [VHost, Name]) of
{badrpc, _} = Error ->
Error;
{error, not_found} ->
{error, rabbit_data_coercion:to_binary(ErrMsg)};
ok -> ok
end.
output(Output, _Opts) -> output(Output, _Opts) ->
'Elixir.RabbitMQ.CLI.DefaultOutput':output(Output). 'Elixir.RabbitMQ.CLI.DefaultOutput':output(Output).

View File

@ -45,7 +45,9 @@
pending := rabbit_types:option(non_neg_integer()), pending := rabbit_types:option(non_neg_integer()),
forwarded := rabbit_types:option(non_neg_integer()) forwarded := rabbit_types:option(non_neg_integer())
} | #{}. } | #{}.
-type status_tuple() :: {name(), type(), info(), metrics(), calendar:datetime()}. -type status_tuple_41x() :: {name(), type(), info(), metrics(), calendar:datetime()}.
-type status_tuple_40x_and_older() :: {name(), type(), info(), calendar:datetime()}.
-type status_tuple() :: status_tuple_41x() | status_tuple_40x_and_older().
-export_type([info/0, blocked_status/0, shovel_status/0, metrics/0]). -export_type([info/0, blocked_status/0, shovel_status/0, metrics/0]).

View File

@ -43,6 +43,10 @@ status(Node) ->
end. end.
format(Node, {Name, Type, Info, _Metrics, TS}) -> format(Node, {Name, Type, Info, _Metrics, TS}) ->
[{node, Node}, {timestamp, format_ts(TS)}] ++
format_name(Type, Name) ++
format_info(Info);
format(Node, {Name, Type, Info, TS}) ->
[{node, Node}, {timestamp, format_ts(TS)}] ++ [{node, Node}, {timestamp, format_ts(TS)}] ++
format_name(Type, Name) ++ format_name(Type, Name) ++
format_info(Info). format_info(Info).