Delta stats throughout (#615)
* Use delta stats throughout and avoid calculating deltas in telemetry * Fix a few things after testing * Remove debug * Fix tests * delete instead of setting to nil * Point to the latest protocol
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/utils"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/webhook"
|
||||
@@ -34,11 +35,9 @@ type TelemetryService interface {
|
||||
EgressEnded(ctx context.Context, info *livekit.EgressInfo)
|
||||
}
|
||||
|
||||
type doWorkFunc func()
|
||||
|
||||
type telemetryService struct {
|
||||
internalService TelemetryServiceInternal
|
||||
jobQueue chan doWorkFunc
|
||||
jobQueue *utils.OpsQueue
|
||||
}
|
||||
|
||||
// queue should be sufficiently large to avoid blocking
|
||||
@@ -47,9 +46,11 @@ const jobQueueBufferSize = 10000
|
||||
func NewTelemetryService(notifier webhook.Notifier, analytics AnalyticsService) TelemetryService {
|
||||
t := &telemetryService{
|
||||
internalService: NewTelemetryServiceInternal(notifier, analytics),
|
||||
jobQueue: make(chan doWorkFunc, jobQueueBufferSize),
|
||||
jobQueue: utils.NewOpsQueue(logger.Logger(logger.GetLogger()), "telemetry", jobQueueBufferSize),
|
||||
}
|
||||
|
||||
t.jobQueue.Start()
|
||||
|
||||
go t.run()
|
||||
|
||||
return t
|
||||
@@ -59,119 +60,104 @@ func (t *telemetryService) run() {
|
||||
ticker := time.NewTicker(updateFrequency)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
t.internalService.SendAnalytics()
|
||||
case job, ok := <-t.jobQueue:
|
||||
if ok {
|
||||
job()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *telemetryService) enqueue(f func()) {
|
||||
select {
|
||||
case t.jobQueue <- f:
|
||||
return
|
||||
default:
|
||||
logger.Warnw("telemetry queue full, dropping message", nil)
|
||||
<-ticker.C
|
||||
t.internalService.SendAnalytics()
|
||||
}
|
||||
}
|
||||
|
||||
func (t *telemetryService) TrackStats(streamType livekit.StreamType, participantID livekit.ParticipantID, trackID livekit.TrackID, stats *livekit.AnalyticsStat) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.TrackStats(streamType, participantID, trackID, stats)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) RoomStarted(ctx context.Context, room *livekit.Room) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.RoomStarted(ctx, room)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) RoomEnded(ctx context.Context, room *livekit.Room) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.RoomEnded(ctx, room)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) ParticipantJoined(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo,
|
||||
clientInfo *livekit.ClientInfo, clientMeta *livekit.AnalyticsClientMeta) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.ParticipantJoined(ctx, room, participant, clientInfo, clientMeta)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) ParticipantActive(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo, clientMeta *livekit.AnalyticsClientMeta) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.ParticipantActive(ctx, room, participant, clientMeta)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) ParticipantLeft(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.ParticipantLeft(ctx, room, participant)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) TrackPublished(ctx context.Context, participantID livekit.ParticipantID, identity livekit.ParticipantIdentity, track *livekit.TrackInfo) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.TrackPublished(ctx, participantID, identity, track)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) TrackUnpublished(ctx context.Context, participantID livekit.ParticipantID, identity livekit.ParticipantIdentity, track *livekit.TrackInfo, ssrc uint32) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.TrackUnpublished(ctx, participantID, identity, track, ssrc)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) TrackSubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, publisher *livekit.ParticipantInfo) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.TrackSubscribed(ctx, participantID, track, publisher)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) TrackUnsubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.TrackUnsubscribed(ctx, participantID, track)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) RecordingStarted(ctx context.Context, ri *livekit.RecordingInfo) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.RecordingStarted(ctx, ri)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) RecordingEnded(ctx context.Context, ri *livekit.RecordingInfo) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.RecordingEnded(ctx, ri)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) TrackPublishedUpdate(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.TrackPublishedUpdate(ctx, participantID, track)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) TrackMaxSubscribedVideoQuality(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, maxQuality livekit.VideoQuality) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.TrackMaxSubscribedVideoQuality(ctx, participantID, track, maxQuality)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) EgressStarted(ctx context.Context, info *livekit.EgressInfo) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.EgressStarted(ctx, info)
|
||||
})
|
||||
}
|
||||
|
||||
func (t *telemetryService) EgressEnded(ctx context.Context, info *livekit.EgressInfo) {
|
||||
t.enqueue(func() {
|
||||
t.jobQueue.Enqueue(func() {
|
||||
t.internalService.EgressEnded(ctx, info)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user