Fix incorrect accounting for track published/subscribed stats. (#1336)

It was not getting decremented in certain cases.
This commit is contained in:
David Zhao
2023-01-26 16:07:04 -08:00
committed by GitHub
parent 2fa46e2df4
commit 2d6c896bba
2 changed files with 16 additions and 17 deletions

View File

@@ -1611,16 +1611,13 @@ func (p *ParticipantImpl) addMediaTrack(signalCid string, sdpCid string, ti *liv
p.supervisor.ClearPublishedTrack(livekit.TrackID(ti.Sid), mt)
// not logged when closing
if !p.isClosed.Load() {
p.params.Telemetry.TrackUnpublished(
context.Background(),
p.ID(),
p.Identity(),
mt.ToProto(),
true,
)
}
p.MigrateState()
p.params.Telemetry.TrackUnpublished(
context.Background(),
p.ID(),
p.Identity(),
mt.ToProto(),
!p.IsClosed(),
)
// re-use track sid
p.pendingTracksLock.Lock()

View File

@@ -512,14 +512,16 @@ func (m *SubscriptionManager) handleSubscribedTrackClose(s *trackSubscription, w
s.setSubscribedTrack(nil)
go m.params.OnTrackUnsubscribed(subTrack)
// always trigger to decrement unsubscribed counter. However, only log an analytics event when
// * the participant isn't closing
// * it's not a migration
m.params.Telemetry.TrackUnsubscribed(
context.Background(),
m.params.Participant.ID(),
&livekit.TrackInfo{Sid: string(s.trackID), Type: subTrack.MediaTrack().Kind()},
!willBeResumed && !m.params.Participant.IsClosed(),
)
if !willBeResumed {
m.params.Telemetry.TrackUnsubscribed(
context.Background(),
m.params.Participant.ID(),
&livekit.TrackInfo{Sid: string(s.trackID), Type: subTrack.MediaTrack().Kind()},
!m.params.Participant.IsClosed(),
)
sender := subTrack.RTPSender()
if sender != nil {
m.params.Logger.Debugw("removing PeerConnection track",