Include dc_id to migration metric

This is to see which DCs trigger migrations more often.
In UI should be divided by number of clients of DC
This commit is contained in:
Sergey Prokhorov 2026-04-10 00:50:00 +02:00
parent 16abd21927
commit 3c29fa31e5
No known key found for this signature in database
GPG key ID: 1C570244E4EF3337
2 changed files with 7 additions and 6 deletions

View file

@ -180,7 +180,7 @@ handle_cast({close_ext, Down}, #state{down = Down, sock = USock, transport = UTr
?LOG_DEBUG("asked to close connection by downstream"),
ok = UTrans:close(USock),
{stop, normal, S#state{down = undefined}};
handle_cast({migrate, OldDown}, #state{down = OldDown, dc_id = {_DcId, Pool},
handle_cast({migrate, OldDown}, #state{down = OldDown, dc_id = {DcId, Pool},
codec = Codec, addr = Addr,
ad_tag = AdTag, listener = Listener} = S) ->
{PacketLayerMod, _} = mtp_codec:info(packet, Codec),
@ -190,12 +190,12 @@ handle_cast({migrate, OldDown}, #state{down = OldDown, dc_id = {_DcId, Pool},
?LOG_DEBUG("Migration failed (~p), closing client", [Reason]),
true = is_atom(Reason),
mtp_metric:count_inc([?APP, downstream_migration, total], 1,
#{labels => [Listener, Reason]}),
#{labels => [Listener, DcId, Reason]}),
{stop, normal, S#state{down = undefined}};
NewDown ->
?LOG_DEBUG("Migrated from ~p to ~p", [OldDown, NewDown]),
mtp_metric:count_inc([?APP, downstream_migration, total], 1,
#{labels => [Listener, ok]}),
#{labels => [Listener, DcId, ok]}),
{noreply, S#state{down = NewDown}}
end;
handle_cast({migrate, _StaleDown}, S) ->
@ -639,7 +639,7 @@ up_send_raw(Data, #state{sock = Sock,
end
end, #{labels => [Listener]}).
down_send(Packet, #state{down = Down, listener = Listener} = S) ->
down_send(Packet, #state{down = Down, listener = Listener, dc_id = Dc} = S) ->
%% ?LOG_DEBUG(">Down: ~p", [Packet]),
case mtp_down_conn:send(Down, Packet) of
ok ->
@ -649,8 +649,9 @@ down_send(Packet, #state{down = Down, listener = Listener} = S) ->
{error, migrating} ->
%% DC connection is closing; this packet was never sent to TG.
%% Stop the handler so the client reconnects and resends.
{DcId, _} = Dc,
mtp_metric:count_inc([?APP, downstream_migration, total], 1,
#{labels => [Listener, mid_send]}),
#{labels => [Listener, DcId, mid_send]}),
throw({stop, normal, S})
end.

View file

@ -192,5 +192,5 @@ active_metrics() ->
{count, [?APP, downstream_migration, total],
"Count of client migrations to a new downstream connection",
#{labels => [listener, result]}}
#{labels => [listener, dc_id, result]}}
].