Record subscribe stream start time in prometheus. (#4704)
* Record subscribe stream start time in prometheus. Adjust for mutes, i. e. take the last unmute time as the start point and calculate time till the first byte is sent. * close the tiny window of race * Prevent long tail sample when publisher glitches. Thanks to @milos-lk for this. Publisher restarting would have reset the layer and would have caused a sample with very high stream start time. We only need to capture when we do a dummy start or when the state is seeded to a different node upon migration. * reduce a diff * test * changed the wrong thing, thank you Devin
This commit is contained in:
@@ -852,6 +852,7 @@ func (m *SubscriptionManager) addSubscriber(sub *mediaTrackSubscription, track t
|
||||
)
|
||||
}
|
||||
if err == nil && subTrack != nil { // subTrack could be nil if already subscribed
|
||||
subTrack.OnSubscribeStreamStarted(sub.recordStreamStartLatency)
|
||||
subTrack.OnClose(func(isExpectedToResume bool) {
|
||||
m.handleSubscribedTrackClose(sub, isExpectedToResume)
|
||||
|
||||
@@ -1532,6 +1533,28 @@ func (s *mediaTrackSubscription) maybeRecordSuccess(tl types.ParticipantTelemetr
|
||||
tl.OnTrackSubscribed(s.subscriberID, mediaTrack.ToProto(), pi, !eventSent)
|
||||
}
|
||||
|
||||
func (s *mediaTrackSubscription) recordStreamStartLatency(elapsed time.Duration) {
|
||||
subTrack := s.getSubscribedTrack()
|
||||
if subTrack == nil {
|
||||
return
|
||||
}
|
||||
mediaTrack := subTrack.MediaTrack()
|
||||
if mediaTrack == nil {
|
||||
return
|
||||
}
|
||||
|
||||
s.logger.Debugw("track subscribe stream started", "cost", elapsed.Microseconds())
|
||||
subscriber := subTrack.Subscriber()
|
||||
prometheus.RecordSubscribeStreamStartTime(
|
||||
subscriber.GetCountry(),
|
||||
mediaTrack.Source(),
|
||||
mediaTrack.Kind(),
|
||||
elapsed,
|
||||
subscriber.GetClientInfo().GetSdk(),
|
||||
subscriber.Kind(),
|
||||
)
|
||||
}
|
||||
|
||||
func (s *mediaTrackSubscription) isCanceled() bool {
|
||||
return !s.eventSent.Load() && s.isDesired()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user