Fix incorrect unsubscribed track telemetry (#1350)

- only log unsubscribe on close if Track was actually bound
- update subscribed counters even if a failure had been logged before
This commit is contained in:
David Zhao
2023-01-30 10:16:21 -08:00
committed by GitHub
parent 2671493870
commit b023c531c2
5 changed files with 42 additions and 23 deletions
+5
View File
@@ -260,10 +260,15 @@ func (t *telemetryService) TrackSubscribed(
participantID livekit.ParticipantID,
track *livekit.TrackInfo,
publisher *livekit.ParticipantInfo,
shouldSendEvent bool,
) {
t.enqueue(func() {
prometheus.RecordTrackSubscribeSuccess(track.Type.String())
if !shouldSendEvent {
return
}
room := t.getRoomDetails(participantID)
ev := newTrackEvent(livekit.AnalyticsEventType_TRACK_SUBSCRIBED, room, participantID, track)
ev.Publisher = publisher
+4 -2
View File
@@ -207,10 +207,12 @@ func Test_OnTrackSubscribed_EventIsSent(t *testing.T) {
require.Equal(t, room, event.Room)
// do
fixture.sut.TrackSubscribed(context.Background(), livekit.ParticipantID(partSID), trackInfo, publisherInfo)
fixture.sut.TrackSubscribed(context.Background(), livekit.ParticipantID(partSID), trackInfo, publisherInfo, true)
time.Sleep(time.Millisecond * 500)
require.Equal(t, 2, fixture.analytics.SendEventCallCount())
require.Eventually(t, func() bool {
return fixture.analytics.SendEventCallCount() == 2
}, time.Second, time.Millisecond*50, "expected send event to be called twice")
_, eventTrackSubscribed := fixture.analytics.SendEventArgsForCall(1)
require.Equal(t, livekit.AnalyticsEventType_TRACK_SUBSCRIBED, eventTrackSubscribed.Type)
require.Equal(t, partSID, eventTrackSubscribed.ParticipantId)
@@ -152,13 +152,14 @@ type FakeTelemetryService struct {
arg3 *livekit.TrackInfo
arg4 *livekit.ParticipantInfo
}
TrackSubscribedStub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo)
TrackSubscribedStub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo, bool)
trackSubscribedMutex sync.RWMutex
trackSubscribedArgsForCall []struct {
arg1 context.Context
arg2 livekit.ParticipantID
arg3 *livekit.TrackInfo
arg4 *livekit.ParticipantInfo
arg5 bool
}
TrackUnmutedStub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo)
trackUnmutedMutex sync.RWMutex
@@ -868,19 +869,20 @@ func (fake *FakeTelemetryService) TrackSubscribeRequestedArgsForCall(i int) (con
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4
}
func (fake *FakeTelemetryService) TrackSubscribed(arg1 context.Context, arg2 livekit.ParticipantID, arg3 *livekit.TrackInfo, arg4 *livekit.ParticipantInfo) {
func (fake *FakeTelemetryService) TrackSubscribed(arg1 context.Context, arg2 livekit.ParticipantID, arg3 *livekit.TrackInfo, arg4 *livekit.ParticipantInfo, arg5 bool) {
fake.trackSubscribedMutex.Lock()
fake.trackSubscribedArgsForCall = append(fake.trackSubscribedArgsForCall, struct {
arg1 context.Context
arg2 livekit.ParticipantID
arg3 *livekit.TrackInfo
arg4 *livekit.ParticipantInfo
}{arg1, arg2, arg3, arg4})
arg5 bool
}{arg1, arg2, arg3, arg4, arg5})
stub := fake.TrackSubscribedStub
fake.recordInvocation("TrackSubscribed", []interface{}{arg1, arg2, arg3, arg4})
fake.recordInvocation("TrackSubscribed", []interface{}{arg1, arg2, arg3, arg4, arg5})
fake.trackSubscribedMutex.Unlock()
if stub != nil {
fake.TrackSubscribedStub(arg1, arg2, arg3, arg4)
fake.TrackSubscribedStub(arg1, arg2, arg3, arg4, arg5)
}
}
@@ -890,17 +892,17 @@ func (fake *FakeTelemetryService) TrackSubscribedCallCount() int {
return len(fake.trackSubscribedArgsForCall)
}
func (fake *FakeTelemetryService) TrackSubscribedCalls(stub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo)) {
func (fake *FakeTelemetryService) TrackSubscribedCalls(stub func(context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo, bool)) {
fake.trackSubscribedMutex.Lock()
defer fake.trackSubscribedMutex.Unlock()
fake.TrackSubscribedStub = stub
}
func (fake *FakeTelemetryService) TrackSubscribedArgsForCall(i int) (context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo) {
func (fake *FakeTelemetryService) TrackSubscribedArgsForCall(i int) (context.Context, livekit.ParticipantID, *livekit.TrackInfo, *livekit.ParticipantInfo, bool) {
fake.trackSubscribedMutex.RLock()
defer fake.trackSubscribedMutex.RUnlock()
argsForCall := fake.trackSubscribedArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4
return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3, argsForCall.arg4, argsForCall.arg5
}
func (fake *FakeTelemetryService) TrackUnmuted(arg1 context.Context, arg2 livekit.ParticipantID, arg3 *livekit.TrackInfo) {
+1 -1
View File
@@ -38,7 +38,7 @@ type TelemetryService interface {
// TrackSubscribeRequested - a participant requested to subscribe to a track
TrackSubscribeRequested(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, publisher *livekit.ParticipantInfo)
// TrackSubscribed - a participant subscribed to a track successfully
TrackSubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, publisher *livekit.ParticipantInfo)
TrackSubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, publisher *livekit.ParticipantInfo, shouldSendEvent bool)
// TrackUnsubscribed - a participant unsubscribed from a track successfully
TrackUnsubscribed(ctx context.Context, participantID livekit.ParticipantID, track *livekit.TrackInfo, shouldSendEvent bool)
// TrackSubscribeFailed - failure to subscribe to a track