telemetry interfaces (#210)

* telemetry interfaces

* move AddUptrack under stats

* regenerate

* a space

* consistency

* fix test
This commit is contained in:
David Colburn
2021-11-24 17:58:04 -08:00
committed by GitHub
parent f4c96449ae
commit 991c334d2d
14 changed files with 152 additions and 98 deletions
+23 -43
View File
@@ -9,11 +9,10 @@ import (
"github.com/livekit/protocol/webhook"
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
)
func (t *TelemetryService) RoomStarted(ctx context.Context, room *livekit.Room) {
func (t *telemetryService) RoomStarted(ctx context.Context, room *livekit.Room) {
prometheus.RoomStarted()
t.notifyEvent(ctx, &livekit.WebhookEvent{
@@ -21,14 +20,14 @@ func (t *TelemetryService) RoomStarted(ctx context.Context, room *livekit.Room)
Room: room,
})
t.sendEvent(&livekit.AnalyticsEvent{
t.analytics.SendEvent(ctx, &livekit.AnalyticsEvent{
Type: livekit.AnalyticsEventType_ROOM_CREATED,
Timestamp: &timestamppb.Timestamp{Seconds: room.CreationTime},
Room: room,
})
}
func (t *TelemetryService) RoomEnded(ctx context.Context, room *livekit.Room) {
func (t *telemetryService) RoomEnded(ctx context.Context, room *livekit.Room) {
prometheus.RoomEnded(time.Unix(room.CreationTime, 0))
t.notifyEvent(ctx, &livekit.WebhookEvent{
@@ -36,16 +35,16 @@ func (t *TelemetryService) RoomEnded(ctx context.Context, room *livekit.Room) {
Room: room,
})
t.sendEvent(&livekit.AnalyticsEvent{
t.analytics.SendEvent(ctx, &livekit.AnalyticsEvent{
Type: livekit.AnalyticsEventType_ROOM_ENDED,
Timestamp: timestamppb.Now(),
RoomSid: room.Sid,
})
}
func (t *TelemetryService) ParticipantJoined(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo) {
func (t *telemetryService) ParticipantJoined(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo) {
t.Lock()
t.workers[participant.Sid] = NewStatsWorker(t, room.Sid, participant.Sid, room.Name)
t.workers[participant.Sid] = newStatsWorker(ctx, t, room.Sid, participant.Sid, room.Name)
t.Unlock()
prometheus.AddParticipant()
@@ -56,14 +55,14 @@ func (t *TelemetryService) ParticipantJoined(ctx context.Context, room *livekit.
Participant: participant,
})
t.sendEvent(&livekit.AnalyticsEvent{
t.analytics.SendEvent(ctx, &livekit.AnalyticsEvent{
Type: livekit.AnalyticsEventType_PARTICIPANT_JOINED,
Timestamp: timestamppb.Now(),
Participant: participant,
})
}
func (t *TelemetryService) ParticipantLeft(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo) {
func (t *telemetryService) ParticipantLeft(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo) {
t.Lock()
if w := t.workers[participant.Sid]; w != nil {
w.Close()
@@ -79,17 +78,17 @@ func (t *TelemetryService) ParticipantLeft(ctx context.Context, room *livekit.Ro
Participant: participant,
})
t.sendEvent(&livekit.AnalyticsEvent{
t.analytics.SendEvent(ctx, &livekit.AnalyticsEvent{
Type: livekit.AnalyticsEventType_PARTICIPANT_LEFT,
Timestamp: timestamppb.Now(),
ParticipantId: participant.Sid,
})
}
func (t *TelemetryService) TrackPublished(participantID string, track *livekit.TrackInfo) {
func (t *telemetryService) TrackPublished(ctx context.Context, participantID string, track *livekit.TrackInfo) {
prometheus.AddPublishedTrack(track.Type.String())
t.sendEvent(&livekit.AnalyticsEvent{
t.analytics.SendEvent(ctx, &livekit.AnalyticsEvent{
Type: livekit.AnalyticsEventType_TRACK_PUBLISHED,
Timestamp: timestamppb.Now(),
ParticipantId: participantID,
@@ -97,16 +96,7 @@ func (t *TelemetryService) TrackPublished(participantID string, track *livekit.T
})
}
func (t *TelemetryService) AddUpTrack(participantID string, buff *buffer.Buffer) {
t.RLock()
w := t.workers[participantID]
t.RUnlock()
if w != nil {
w.AddBuffer(buff)
}
}
func (t *TelemetryService) TrackUnpublished(participantID string, track *livekit.TrackInfo, ssrc uint32) {
func (t *telemetryService) TrackUnpublished(ctx context.Context, participantID string, track *livekit.TrackInfo, ssrc uint32) {
t.RLock()
w := t.workers[participantID]
t.RUnlock()
@@ -116,7 +106,7 @@ func (t *TelemetryService) TrackUnpublished(participantID string, track *livekit
prometheus.SubPublishedTrack(track.Type.String())
t.sendEvent(&livekit.AnalyticsEvent{
t.analytics.SendEvent(ctx, &livekit.AnalyticsEvent{
Type: livekit.AnalyticsEventType_TRACK_UNPUBLISHED,
Timestamp: timestamppb.Now(),
ParticipantId: participantID,
@@ -124,10 +114,10 @@ func (t *TelemetryService) TrackUnpublished(participantID string, track *livekit
})
}
func (t *TelemetryService) TrackSubscribed(participantID string, track *livekit.TrackInfo) {
func (t *telemetryService) TrackSubscribed(ctx context.Context, participantID string, track *livekit.TrackInfo) {
prometheus.AddSubscribedTrack(track.Type.String())
t.sendEvent(&livekit.AnalyticsEvent{
t.analytics.SendEvent(ctx, &livekit.AnalyticsEvent{
Type: livekit.AnalyticsEventType_TRACK_SUBSCRIBED,
Timestamp: timestamppb.Now(),
ParticipantId: participantID,
@@ -135,10 +125,10 @@ func (t *TelemetryService) TrackSubscribed(participantID string, track *livekit.
})
}
func (t *TelemetryService) TrackUnsubscribed(participantID string, track *livekit.TrackInfo) {
func (t *telemetryService) TrackUnsubscribed(ctx context.Context, participantID string, track *livekit.TrackInfo) {
prometheus.SubSubscribedTrack(track.Type.String())
t.sendEvent(&livekit.AnalyticsEvent{
t.analytics.SendEvent(ctx, &livekit.AnalyticsEvent{
Type: livekit.AnalyticsEventType_TRACK_UNSUBSCRIBED,
Timestamp: timestamppb.Now(),
ParticipantId: participantID,
@@ -146,7 +136,7 @@ func (t *TelemetryService) TrackUnsubscribed(participantID string, track *liveki
})
}
func (t *TelemetryService) RecordingStarted(ctx context.Context, recordingID string, req *livekit.StartRecordingRequest) {
func (t *telemetryService) RecordingStarted(ctx context.Context, recordingID string, req *livekit.StartRecordingRequest) {
t.notifyEvent(ctx, &livekit.WebhookEvent{
Event: webhook.EventRecordingStarted,
RecordingInfo: &livekit.RecordingInfo{
@@ -155,27 +145,27 @@ func (t *TelemetryService) RecordingStarted(ctx context.Context, recordingID str
},
})
t.sendEvent(&livekit.AnalyticsEvent{
t.analytics.SendEvent(ctx, &livekit.AnalyticsEvent{
Type: livekit.AnalyticsEventType_RECORDING_STARTED,
Timestamp: timestamppb.Now(),
RecordingId: recordingID,
})
}
func (t *TelemetryService) RecordingEnded(res *livekit.RecordingResult) {
t.notifyEvent(context.Background(), &livekit.WebhookEvent{
func (t *telemetryService) RecordingEnded(ctx context.Context, res *livekit.RecordingResult) {
t.notifyEvent(ctx, &livekit.WebhookEvent{
Event: webhook.EventRecordingFinished,
RecordingResult: res,
})
t.sendEvent(&livekit.AnalyticsEvent{
t.analytics.SendEvent(ctx, &livekit.AnalyticsEvent{
Type: livekit.AnalyticsEventType_RECORDING_ENDED,
Timestamp: timestamppb.Now(),
RecordingId: res.Id,
})
}
func (t *TelemetryService) notifyEvent(ctx context.Context, event *livekit.WebhookEvent) {
func (t *telemetryService) notifyEvent(ctx context.Context, event *livekit.WebhookEvent) {
if t.notifier == nil {
return
}
@@ -186,13 +176,3 @@ func (t *TelemetryService) notifyEvent(ctx context.Context, event *livekit.Webho
}
})
}
func (t *TelemetryService) sendEvent(event *livekit.AnalyticsEvent) {
if t.analyticsEnabled {
if err := t.events.Send(&livekit.AnalyticsEvents{
Events: []*livekit.AnalyticsEvent{event},
}); err != nil {
logger.Errorw("failed to send event", err, "eventType", event.Type.String())
}
}
}