Key telemetry stats worker using combination of roomID, participantID (#4323)
* Key telemetry stats work using combination of roomID, participantID With forwarded participant, the same participantID can existing in two rooms. NOTE: This does not yet allow a participant session to report its events/track stats into multiple rooms. That would require regitering multiple listeners (from rooms a participant is forwarded to). * missed file * data channel stats * PR comments + pass in room name so that telemetry events have proper room name also
This commit is contained in:
+75
-2
@@ -28,6 +28,7 @@ import (
|
||||
"golang.org/x/exp/maps"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/protocol/codecs/mime"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/observability/roomobs"
|
||||
@@ -147,8 +148,9 @@ type Room struct {
|
||||
|
||||
dataMessageCache *utils.TimeSizeCache[types.DataMessageCache]
|
||||
|
||||
onStateChangeMu sync.Mutex
|
||||
localParticipantListener types.LocalParticipantListener
|
||||
onStateChangeMu sync.Mutex
|
||||
localParticipantListener types.LocalParticipantListener
|
||||
participantTelemetryListener types.ParticipantTelemetryListener
|
||||
}
|
||||
|
||||
type ParticipantOptions struct {
|
||||
@@ -286,6 +288,7 @@ func NewRoom(
|
||||
}
|
||||
r.trackManager = NewRoomTrackManager(r.logger)
|
||||
r.localParticipantListener = &localParticipantListener{room: r}
|
||||
r.participantTelemetryListener = &participantTelemetryListener{room: r}
|
||||
|
||||
if r.protoRoom.EmptyTimeout == 0 {
|
||||
r.protoRoom.EmptyTimeout = roomConfig.EmptyTimeout
|
||||
@@ -1890,6 +1893,10 @@ func (r *Room) LocalParticipantListener() types.LocalParticipantListener {
|
||||
return r.localParticipantListener
|
||||
}
|
||||
|
||||
func (r *Room) ParticipantTelemetryListener() types.ParticipantTelemetryListener {
|
||||
return r.participantTelemetryListener
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------
|
||||
|
||||
var _ types.LocalParticipantListener = (*localParticipantListener)(nil)
|
||||
@@ -1983,6 +1990,72 @@ func (l *localParticipantListener) OnLeave(p types.LocalParticipant, closeReason
|
||||
|
||||
// ------------------------------------------------------------
|
||||
|
||||
var _ types.ParticipantTelemetryListener = (*participantTelemetryListener)(nil)
|
||||
|
||||
type participantTelemetryListener struct {
|
||||
room *Room
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackPublishRequested(pID livekit.ParticipantID, identity livekit.ParticipantIdentity, ti *livekit.TrackInfo) {
|
||||
l.room.telemetry.TrackPublishRequested(context.Background(), l.room.ID(), l.room.Name(), pID, identity, ti)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackPublished(pID livekit.ParticipantID, identity livekit.ParticipantIdentity, ti *livekit.TrackInfo, shouldSendEvent bool) {
|
||||
l.room.telemetry.TrackPublished(context.Background(), l.room.ID(), l.room.Name(), pID, identity, ti, shouldSendEvent)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackUnpublished(pID livekit.ParticipantID, identity livekit.ParticipantIdentity, ti *livekit.TrackInfo, shouldSendEvent bool) {
|
||||
l.room.telemetry.TrackUnpublished(context.Background(), l.room.ID(), l.room.Name(), pID, identity, ti, shouldSendEvent)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackSubscribeRequested(pID livekit.ParticipantID, ti *livekit.TrackInfo) {
|
||||
l.room.telemetry.TrackSubscribeRequested(context.Background(), l.room.ID(), l.room.Name(), pID, ti)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackSubscribed(pID livekit.ParticipantID, ti *livekit.TrackInfo, publisherInfo *livekit.ParticipantInfo, shouldSendEvent bool) {
|
||||
l.room.telemetry.TrackSubscribed(context.Background(), l.room.ID(), l.room.Name(), pID, ti, publisherInfo, shouldSendEvent)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackUnsubscribed(pID livekit.ParticipantID, ti *livekit.TrackInfo, shouldSendEvent bool) {
|
||||
l.room.telemetry.TrackUnsubscribed(context.Background(), l.room.ID(), l.room.Name(), pID, ti, shouldSendEvent)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackSubscribeFailed(pID livekit.ParticipantID, ti livekit.TrackID, err error, isUserError bool) {
|
||||
l.room.telemetry.TrackSubscribeFailed(context.Background(), l.room.ID(), l.room.Name(), pID, ti, err, isUserError)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackMuted(pID livekit.ParticipantID, ti *livekit.TrackInfo) {
|
||||
l.room.telemetry.TrackMuted(context.Background(), l.room.ID(), l.room.Name(), pID, ti)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackUnmuted(pID livekit.ParticipantID, ti *livekit.TrackInfo) {
|
||||
l.room.telemetry.TrackUnmuted(context.Background(), l.room.ID(), l.room.Name(), pID, ti)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackPublishedUpdate(pID livekit.ParticipantID, ti *livekit.TrackInfo) {
|
||||
l.room.telemetry.TrackPublishedUpdate(context.Background(), l.room.ID(), l.room.Name(), pID, ti)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackMaxSubscribedVideoQuality(pID livekit.ParticipantID, ti *livekit.TrackInfo, mime mime.MimeType, maxQuality livekit.VideoQuality) {
|
||||
l.room.telemetry.TrackMaxSubscribedVideoQuality(context.Background(), l.room.ID(), l.room.Name(), pID, ti, mime, maxQuality)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackPublishRTPStats(pID livekit.ParticipantID, trackID livekit.TrackID, mimeType mime.MimeType, layer int, stats *livekit.RTPStats) {
|
||||
l.room.telemetry.TrackPublishRTPStats(context.Background(), l.room.ID(), l.room.Name(), pID, trackID, mimeType, layer, stats)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackSubscribeRTPStats(pID livekit.ParticipantID, trackID livekit.TrackID, mimeType mime.MimeType, stats *livekit.RTPStats) {
|
||||
l.room.telemetry.TrackSubscribeRTPStats(context.Background(), l.room.ID(), l.room.Name(), pID, trackID, mimeType, stats)
|
||||
}
|
||||
|
||||
func (l participantTelemetryListener) OnTrackStats(key telemetry.StatsKey, stat *livekit.AnalyticsStat) {
|
||||
roomID, roomName := l.room.ID(), l.room.Name()
|
||||
stat.RoomId, stat.RoomName = string(roomID), string(roomName)
|
||||
l.room.telemetry.TrackStats(roomID, roomName, key, stat)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------
|
||||
|
||||
func BroadcastDataPacketForRoom(
|
||||
r types.Room,
|
||||
source types.LocalParticipant,
|
||||
|
||||
Reference in New Issue
Block a user