reset subscription time when downtrack closed and expect resume (#3083)

This commit is contained in:
cnderrauber
2024-10-10 08:06:44 +00:00
committed by GitHub
parent 6829ec8600
commit c8dbe8e977

View File

@@ -721,6 +721,9 @@ func (m *SubscriptionManager) handleSubscribedTrackClose(s *trackSubscription, i
}
m.params.Participant.Negotiate(false)
} else {
t := time.Now()
s.subscribeAt.Store(&t)
}
if relieveFromLimits {
m.queueReconcile(trackIDForReconcileSubscriptions)
@@ -755,16 +758,19 @@ type trackSubscription struct {
// this timestamp determines when failures are reported
subStartedAt atomic.Pointer[time.Time]
createAt time.Time
// the timestamp when the subscription was started, will be reset when downtrack is closed with expected resume
subscribeAt atomic.Pointer[time.Time]
}
func newTrackSubscription(subscriberID livekit.ParticipantID, trackID livekit.TrackID, l logger.Logger) *trackSubscription {
return &trackSubscription{
s := &trackSubscription{
subscriberID: subscriberID,
trackID: trackID,
logger: l,
createAt: time.Now(),
}
t := time.Now()
s.subscribeAt.Store(&t)
return s
}
func (s *trackSubscription) setPublisher(publisherIdentity livekit.ParticipantIdentity, publisherID livekit.ParticipantID) {
@@ -790,6 +796,7 @@ func (s *trackSubscription) setDesired(desired bool) bool {
// we'll reset the timer so it has sufficient time to reconcile
t := time.Now()
s.subStartedAt.Store(&t)
s.subscribeAt.Store(&t)
}
if s.desired == desired {
@@ -822,6 +829,7 @@ func (s *trackSubscription) setHasPermission(perm bool) bool {
// when permission is granted, reset the timer so it has sufficient time to reconcile
t := time.Now()
s.subStartedAt.Store(&t)
s.subscribeAt.Store(&t)
}
return true
}
@@ -992,7 +1000,7 @@ func (s *trackSubscription) maybeRecordSuccess(ts telemetry.TelemetryService, pI
return
}
d := time.Since(s.createAt)
d := time.Since(*s.subscribeAt.Load())
s.logger.Debugw("track subscribed", "cost", d.Milliseconds())
subscriber := subTrack.Subscriber()
prometheus.RecordSubscribeTime(mediaTrack.Source(), mediaTrack.Kind(), d, subscriber.GetClientInfo().GetSdk(), subscriber.Kind())