Key telemetry stats worker using combination of roomID, participantID (#4323)
* Key telemetry stats work using combination of roomID, participantID With forwarded participant, the same participantID can existing in two rooms. NOTE: This does not yet allow a participant session to report its events/track stats into multiple rooms. That would require regitering multiple listeners (from rooms a participant is forwarded to). * missed file * data channel stats * PR comments + pass in room name so that telemetry events have proper room name also
This commit is contained in:
@@ -28,7 +28,6 @@ import (
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/sfu"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry"
|
||||
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
@@ -57,7 +56,7 @@ type SubscriptionManagerParams struct {
|
||||
OnTrackSubscribed func(subTrack types.SubscribedTrack)
|
||||
OnTrackUnsubscribed func(subTrack types.SubscribedTrack)
|
||||
OnSubscriptionError func(trackID livekit.TrackID, fatal bool, err error)
|
||||
Telemetry telemetry.TelemetryService
|
||||
TelemetryListener types.ParticipantTelemetryListener
|
||||
|
||||
SubscriptionLimitVideo, SubscriptionLimitAudio int32
|
||||
|
||||
@@ -472,8 +471,7 @@ func (m *SubscriptionManager) reconcileSubscription(s *mediaTrackSubscription) {
|
||||
|
||||
numAttempts := s.getNumAttempts()
|
||||
if numAttempts == 0 {
|
||||
m.params.Telemetry.TrackSubscribeRequested(
|
||||
context.Background(),
|
||||
m.params.TelemetryListener.OnTrackSubscribeRequested(
|
||||
s.subscriberID,
|
||||
&livekit.TrackInfo{
|
||||
Sid: string(s.trackID),
|
||||
@@ -493,14 +491,14 @@ func (m *SubscriptionManager) reconcileSubscription(s *mediaTrackSubscription) {
|
||||
// - ErrSubscriptionLimitExceeded: the participant have reached the limit of subscriptions, wait for the other subscription to be unsubscribed
|
||||
// We'll still log an event to reflect this in telemetry since it's been too long
|
||||
if s.durationSinceStart() > subscriptionTimeout {
|
||||
s.maybeRecordError(m.params.Telemetry, s.subscriberID, err, true)
|
||||
s.maybeRecordError(m.params.TelemetryListener, err, true)
|
||||
}
|
||||
case ErrTrackNotFound:
|
||||
// source track was never published or closed
|
||||
// if after timeout we'd unsubscribe from it.
|
||||
// this is the *only* case we'd change desired state
|
||||
if s.durationSinceStart() > notFoundTimeout {
|
||||
s.maybeRecordError(m.params.Telemetry, s.subscriberID, err, true)
|
||||
s.maybeRecordError(m.params.TelemetryListener, err, true)
|
||||
s.logger.Infow("unsubscribing from track after notFoundTimeout", "error", err)
|
||||
s.setDesired(false)
|
||||
m.queueReconcile(s.trackID)
|
||||
@@ -513,7 +511,7 @@ func (m *SubscriptionManager) reconcileSubscription(s *mediaTrackSubscription) {
|
||||
"failed to subscribe, triggering error handler", err,
|
||||
"attempt", s.getNumAttempts(),
|
||||
)
|
||||
s.maybeRecordError(m.params.Telemetry, s.subscriberID, err, false)
|
||||
s.maybeRecordError(m.params.TelemetryListener, err, false)
|
||||
m.params.OnSubscriptionError(s.trackID, true, err)
|
||||
} else {
|
||||
s.logger.Debugw(
|
||||
@@ -552,7 +550,7 @@ func (m *SubscriptionManager) reconcileSubscription(s *mediaTrackSubscription) {
|
||||
wait := min(time.Since(activeAt), s.durationSinceStart())
|
||||
if wait > subscriptionTimeout {
|
||||
s.logger.Warnw("track not bound after timeout", nil)
|
||||
s.maybeRecordError(m.params.Telemetry, s.subscriberID, ErrTrackNotBound, false)
|
||||
s.maybeRecordError(m.params.TelemetryListener, ErrTrackNotBound, false)
|
||||
m.params.OnSubscriptionError(s.trackID, true, ErrTrackNotBound)
|
||||
}
|
||||
}
|
||||
@@ -839,13 +837,13 @@ func (m *SubscriptionManager) addSubscriber(sub *mediaTrackSubscription, track t
|
||||
subTrack.AddOnBind(func(err error) {
|
||||
if err != nil {
|
||||
sub.logger.Infow("failed to bind track", "err", err)
|
||||
sub.maybeRecordError(m.params.Telemetry, sub.subscriberID, err, true)
|
||||
sub.maybeRecordError(m.params.TelemetryListener, err, true)
|
||||
m.UnsubscribeFromTrack(trackID)
|
||||
m.params.OnSubscriptionError(trackID, false, err)
|
||||
return
|
||||
}
|
||||
sub.setBound()
|
||||
sub.maybeRecordSuccess(m.params.Telemetry, sub.subscriberID)
|
||||
sub.maybeRecordSuccess(m.params.TelemetryListener)
|
||||
})
|
||||
sub.setSubscribedTrack(subTrack)
|
||||
|
||||
@@ -967,8 +965,7 @@ func (m *SubscriptionManager) handleSubscribedTrackClose(s *mediaTrackSubscripti
|
||||
// * the participant isn't closing
|
||||
// * it's not a migration
|
||||
if wasBound {
|
||||
m.params.Telemetry.TrackUnsubscribed(
|
||||
context.Background(),
|
||||
m.params.TelemetryListener.OnTrackUnsubscribed(
|
||||
s.subscriberID,
|
||||
&livekit.TrackInfo{Sid: string(s.trackID), Type: subTrack.MediaTrack().Kind()},
|
||||
!isExpectedToResume,
|
||||
@@ -978,8 +975,7 @@ func (m *SubscriptionManager) handleSubscribedTrackClose(s *mediaTrackSubscripti
|
||||
if dt != nil {
|
||||
stats := dt.GetTrackStats()
|
||||
if stats != nil {
|
||||
m.params.Telemetry.TrackSubscribeRTPStats(
|
||||
context.Background(),
|
||||
m.params.TelemetryListener.OnTrackSubscribeRTPStats(
|
||||
s.subscriberID,
|
||||
s.trackID,
|
||||
dt.Mime(),
|
||||
@@ -1437,15 +1433,15 @@ func (s *mediaTrackSubscription) isBound() bool {
|
||||
return s.bound
|
||||
}
|
||||
|
||||
func (s *mediaTrackSubscription) maybeRecordError(ts telemetry.TelemetryService, pID livekit.ParticipantID, err error, isUserError bool) {
|
||||
func (s *mediaTrackSubscription) maybeRecordError(tl types.ParticipantTelemetryListener, err error, isUserError bool) {
|
||||
if s.eventSent.Swap(true) {
|
||||
return
|
||||
}
|
||||
|
||||
ts.TrackSubscribeFailed(context.Background(), pID, s.trackID, err, isUserError)
|
||||
tl.OnTrackSubscribeFailed(s.subscriberID, s.trackID, err, isUserError)
|
||||
}
|
||||
|
||||
func (s *mediaTrackSubscription) maybeRecordSuccess(ts telemetry.TelemetryService, pID livekit.ParticipantID) {
|
||||
func (s *mediaTrackSubscription) maybeRecordSuccess(tl types.ParticipantTelemetryListener) {
|
||||
subTrack := s.getSubscribedTrack()
|
||||
if subTrack == nil {
|
||||
return
|
||||
@@ -1474,7 +1470,7 @@ func (s *mediaTrackSubscription) maybeRecordSuccess(ts telemetry.TelemetryServic
|
||||
Identity: string(subTrack.PublisherIdentity()),
|
||||
Sid: string(subTrack.PublisherID()),
|
||||
}
|
||||
ts.TrackSubscribed(context.Background(), pID, mediaTrack.ToProto(), pi, !eventSent)
|
||||
tl.OnTrackSubscribed(s.subscriberID, mediaTrack.ToProto(), pi, !eventSent)
|
||||
}
|
||||
|
||||
func (s *mediaTrackSubscription) isCanceled() bool {
|
||||
|
||||
Reference in New Issue
Block a user