Allow skipping of sending ParticipantJoined analytics event (#1236)

In certain scenarios such as migration, we do not want a duplicate event
to be sent when the participant is reconnecting. The Prometheus metric
should still be updated though.
This commit is contained in:
David Zhao
2022-12-18 22:09:20 -08:00
committed by GitHub
parent 241a7120f5
commit 120335da00
6 changed files with 45 additions and 36 deletions
+18 -11
View File
@@ -65,6 +65,7 @@ func (t *telemetryService) ParticipantJoined(
participant *livekit.ParticipantInfo,
clientInfo *livekit.ClientInfo,
clientMeta *livekit.AnalyticsClientMeta,
shouldSendEvent bool,
) {
t.enqueue(func() {
prometheus.IncrementParticipantJoin(1)
@@ -78,16 +79,18 @@ func (t *telemetryService) ParticipantJoined(
livekit.ParticipantIdentity(participant.Identity),
)
t.SendEvent(ctx, &livekit.AnalyticsEvent{
Type: livekit.AnalyticsEventType_PARTICIPANT_JOINED,
Timestamp: timestamppb.Now(),
RoomId: room.Sid,
ParticipantId: participant.Sid,
Participant: participant,
Room: room,
ClientInfo: clientInfo,
ClientMeta: clientMeta,
})
if shouldSendEvent {
t.SendEvent(ctx, &livekit.AnalyticsEvent{
Type: livekit.AnalyticsEventType_PARTICIPANT_JOINED,
Timestamp: timestamppb.Now(),
RoomId: room.Sid,
ParticipantId: participant.Sid,
Participant: participant,
Room: room,
ClientInfo: clientInfo,
ClientMeta: clientMeta,
})
}
})
}
@@ -128,7 +131,11 @@ func (t *telemetryService) ParticipantActive(
})
}
func (t *telemetryService) ParticipantLeft(ctx context.Context, room *livekit.Room, participant *livekit.ParticipantInfo, shouldSendEvent bool) {
func (t *telemetryService) ParticipantLeft(ctx context.Context,
room *livekit.Room,
participant *livekit.ParticipantInfo,
shouldSendEvent bool,
) {
t.enqueue(func() {
isConnected := false
if worker, ok := t.getWorker(livekit.ParticipantID(participant.Sid)); ok {