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:
@@ -74,7 +74,8 @@ type SubscribedTrack struct {
|
||||
bound bool
|
||||
onBindCallbacks []func(error)
|
||||
|
||||
onClose atomic.Value // func(bool)
|
||||
onSubscribeStreamStarted atomic.Value //func(time.Duration)
|
||||
onClose atomic.Value // func(bool)
|
||||
|
||||
debouncer func(func())
|
||||
|
||||
@@ -242,6 +243,10 @@ func (t *SubscribedTrack) Close(isExpectedToResume bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *SubscribedTrack) OnSubscribeStreamStarted(f func(time.Duration)) {
|
||||
t.onSubscribeStreamStarted.Store(f)
|
||||
}
|
||||
|
||||
func (t *SubscribedTrack) OnClose(f func(bool)) {
|
||||
t.onClose.Store(f)
|
||||
}
|
||||
@@ -492,6 +497,9 @@ func (t *SubscribedTrack) OnDownTrackClose(isExpectedToResume bool) {
|
||||
t.Close(isExpectedToResume)
|
||||
}
|
||||
|
||||
func (t *SubscribedTrack) OnStreamStarted() {
|
||||
t.params.TelemetryListener.OnTrackSubscribeStreamStarted(t.params.Subscriber.ID(), t.params.MediaTrack.ToProto())
|
||||
func (t *SubscribedTrack) OnStreamStarted(elapsed time.Duration) {
|
||||
t.params.TelemetryListener.OnTrackSubscribeStreamStarted(t.params.Subscriber.ID(), t.params.MediaTrack.ToProto(), elapsed)
|
||||
if onSubscribeStreamStarted := t.onSubscribeStreamStarted.Load(); onSubscribeStreamStarted != nil {
|
||||
onSubscribeStreamStarted.(func(time.Duration))(elapsed)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user