telemetry: support roomID change for a participant (#4816)

* telemetry: support roomID change for a participant

A room can get a new id while participants are connected. Key stats
workers as map[roomID]map[participantID] so moving a room is a single
map splice, and add reKeyRoom/RoomIDChanged to do the move.

Stats collected before the change are sealed off with the room they
were collected in so they stay attributed to it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* telemetry: close superseded worker on re-key collision

Only one worker can be keyed at (room, participant). If a re-key lands
on a room that already has a worker for the same participant, keep the
one already filed there and close the superseded one so it drains and
is reaped instead of lingering in the flush list.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* telemetry: hand references to the successor on force close

A ReferenceGuard records that it activated some worker, not which one,
so a superseded worker cannot just drop its references - the survivor
would be left with references it never sees released and would never
close. Hand them over instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Raja Subramanian
2026-08-29 12:58:22 +05:30
committed by GitHub
co-authored by Claude Opus 5
parent 54496c765d
commit 5528c464a0
6 changed files with 441 additions and 30 deletions
+12
View File
@@ -184,6 +184,18 @@ func (t *telemetryService) ParticipantResumed(
})
}
// RoomIDChanged re-keys the room's stats workers.
//
// NOTE: this shares the queue with the stats and participant events it races with, so
// ops raised before the id changed (carrying `prevRoomID`) are applied before the
// re-key and ops raised after it (carrying the new id) are applied after. Callers
// should raise this as soon as the room starts reporting the new id.
func (t *telemetryService) RoomIDChanged(ctx context.Context, prevRoomID livekit.RoomID, room *livekit.Room) {
t.enqueue(func() {
t.reKeyRoom(prevRoomID, livekit.RoomID(room.Sid), livekit.RoomName(room.Name))
})
}
func (t *telemetryService) ParticipantLeft(ctx context.Context,
room *livekit.Room,
participant *livekit.ParticipantInfo,