Add country label to edge prom stats. (#3816)

* Add country label to edge prom stats.

* data channel country stats

* test

* pub/sub time country
This commit is contained in:
Raja Subramanian
2025-07-24 13:23:05 +05:30
committed by GitHub
parent 68387b41fe
commit 10103449c5
12 changed files with 268 additions and 116 deletions
+10 -2
View File
@@ -67,6 +67,7 @@ type MediaTrackParams struct {
ParticipantID func() livekit.ParticipantID
ParticipantIdentity livekit.ParticipantIdentity
ParticipantVersion uint32
ParticipantCountry string
BufferFactory *buffer.Factory
ReceiverConfig ReceiverConfig
SubscriberConfig DirectionConfig
@@ -335,14 +336,21 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track sfu.TrackRe
})
// SIMULCAST-CODEC-TODO: these need to be receiver/mime aware, setting it up only for primary now
statsKey := telemetry.StatsKeyForTrack(
t.params.ParticipantCountry,
livekit.StreamType_UPSTREAM,
t.PublisherID(),
t.ID(),
ti.Source,
ti.Type,
)
newWR.OnStatsUpdate(func(_ *sfu.WebRTCReceiver, stat *livekit.AnalyticsStat) {
// send for only one codec, either primary (priority == 0) OR regressed codec
t.lock.RLock()
regressionTargetCodecReceived := t.regressionTargetCodecReceived
t.lock.RUnlock()
if priority == 0 || regressionTargetCodecReceived {
key := telemetry.StatsKeyForTrack(livekit.StreamType_UPSTREAM, t.PublisherID(), t.ID(), ti.Source, ti.Type)
t.params.Telemetry.TrackStats(key, stat)
t.params.Telemetry.TrackStats(statsKey, stat)
if cs, ok := telemetry.CondenseStat(stat); ok {
t.params.Reporter.Tx(func(tx roomobs.TrackTx) {
+9 -2
View File
@@ -210,10 +210,17 @@ func (t *MediaTrackSubscriptions) AddSubscriber(sub types.LocalParticipant, wr *
subTrack.SetPublisherMuted(t.params.MediaTrack.IsMuted())
})
statsKey := telemetry.StatsKeyForTrack(
sub.GetCountry(),
livekit.StreamType_DOWNSTREAM,
subscriberID,
trackID,
t.params.MediaTrack.Source(),
t.params.MediaTrack.Kind(),
)
reporter := sub.GetReporter().WithTrack(trackID.String())
downTrack.OnStatsUpdate(func(_ *sfu.DownTrack, stat *livekit.AnalyticsStat) {
key := telemetry.StatsKeyForTrack(livekit.StreamType_DOWNSTREAM, subscriberID, trackID, t.params.MediaTrack.Source(), t.params.MediaTrack.Kind())
t.params.Telemetry.TrackStats(key, stat)
t.params.Telemetry.TrackStats(statsKey, stat)
if cs, ok := telemetry.CondenseStat(stat); ok {
ti := wr.TrackInfo()
+15 -1
View File
@@ -205,6 +205,7 @@ type ParticipantParams struct {
FireOnTrackBySdp bool
DisableCodecRegression bool
LastPubReliableSeq uint32
Country string
}
type ParticipantImpl struct {
@@ -379,6 +380,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
p.id.Store(params.SID)
p.dataChannelStats = telemetry.NewBytesTrackStats(
p.params.Country,
telemetry.BytesTrackIDForParticipantID(telemetry.BytesTrackTypeData, p.ID()),
p.ID(),
params.Telemetry,
@@ -436,6 +438,10 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
return p, nil
}
func (p *ParticipantImpl) GetCountry() string {
return p.params.Country
}
func (p *ParticipantImpl) GetTrailer() []byte {
trailer := make([]byte, len(p.params.Trailer))
copy(trailer, p.params.Trailer)
@@ -2947,7 +2953,14 @@ func (p *ParticipantImpl) mediaTrackReceived(track sfu.TrackRemote, rtpReceiver
)
}
prometheus.RecordPublishTime(mt.Source(), mt.Kind(), pubTime, p.GetClientInfo().GetSdk(), p.Kind())
prometheus.RecordPublishTime(
p.params.Country,
mt.Source(),
mt.Kind(),
pubTime,
p.GetClientInfo().GetSdk(),
p.Kind(),
)
p.handleTrackPublished(mt, isMigrated)
}()
}
@@ -3015,6 +3028,7 @@ func (p *ParticipantImpl) addMediaTrack(signalCid string, sdpCid string, ti *liv
ParticipantID: p.ID,
ParticipantIdentity: p.params.Identity,
ParticipantVersion: p.version.Load(),
ParticipantCountry: p.params.Country,
BufferFactory: p.params.Config.BufferFactory,
ReceiverConfig: p.params.Config.Receiver,
AudioConfig: p.params.AudioConfig,
+9 -1
View File
@@ -1140,7 +1140,15 @@ func (s *trackSubscription) maybeRecordSuccess(ts telemetry.TelemetryService, pI
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(), int(s.succRecordCounter.Inc()))
prometheus.RecordSubscribeTime(
subscriber.GetCountry(),
mediaTrack.Source(),
mediaTrack.Kind(),
d,
subscriber.GetClientInfo().GetSdk(),
subscriber.Kind(),
int(s.succRecordCounter.Inc()),
)
eventSent := s.eventSent.Swap(true)
+1
View File
@@ -350,6 +350,7 @@ type LocalParticipant interface {
ToProtoWithVersion() (*livekit.ParticipantInfo, utils.TimedVersion)
// getters
GetCountry() string
GetTrailer() []byte
GetLogger() logger.Logger
GetLoggerResolver() logger.DeferredFieldResolver
@@ -292,6 +292,16 @@ type FakeLocalParticipant struct {
getConnectionQualityReturnsOnCall map[int]struct {
result1 *livekit.ConnectionQualityInfo
}
GetCountryStub func() string
getCountryMutex sync.RWMutex
getCountryArgsForCall []struct {
}
getCountryReturns struct {
result1 string
}
getCountryReturnsOnCall map[int]struct {
result1 string
}
GetDisableSenderReportPassThroughStub func() bool
getDisableSenderReportPassThroughMutex sync.RWMutex
getDisableSenderReportPassThroughArgsForCall []struct {
@@ -2832,6 +2842,59 @@ func (fake *FakeLocalParticipant) GetConnectionQualityReturnsOnCall(i int, resul
}{result1}
}
func (fake *FakeLocalParticipant) GetCountry() string {
fake.getCountryMutex.Lock()
ret, specificReturn := fake.getCountryReturnsOnCall[len(fake.getCountryArgsForCall)]
fake.getCountryArgsForCall = append(fake.getCountryArgsForCall, struct {
}{})
stub := fake.GetCountryStub
fakeReturns := fake.getCountryReturns
fake.recordInvocation("GetCountry", []interface{}{})
fake.getCountryMutex.Unlock()
if stub != nil {
return stub()
}
if specificReturn {
return ret.result1
}
return fakeReturns.result1
}
func (fake *FakeLocalParticipant) GetCountryCallCount() int {
fake.getCountryMutex.RLock()
defer fake.getCountryMutex.RUnlock()
return len(fake.getCountryArgsForCall)
}
func (fake *FakeLocalParticipant) GetCountryCalls(stub func() string) {
fake.getCountryMutex.Lock()
defer fake.getCountryMutex.Unlock()
fake.GetCountryStub = stub
}
func (fake *FakeLocalParticipant) GetCountryReturns(result1 string) {
fake.getCountryMutex.Lock()
defer fake.getCountryMutex.Unlock()
fake.GetCountryStub = nil
fake.getCountryReturns = struct {
result1 string
}{result1}
}
func (fake *FakeLocalParticipant) GetCountryReturnsOnCall(i int, result1 string) {
fake.getCountryMutex.Lock()
defer fake.getCountryMutex.Unlock()
fake.GetCountryStub = nil
if fake.getCountryReturnsOnCall == nil {
fake.getCountryReturnsOnCall = make(map[int]struct {
result1 string
})
}
fake.getCountryReturnsOnCall[i] = struct {
result1 string
}{result1}
}
func (fake *FakeLocalParticipant) GetDisableSenderReportPassThrough() bool {
fake.getDisableSenderReportPassThroughMutex.Lock()
ret, specificReturn := fake.getDisableSenderReportPassThroughReturnsOnCall[len(fake.getDisableSenderReportPassThroughArgsForCall)]
@@ -9262,6 +9325,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
defer fake.getClientInfoMutex.RUnlock()
fake.getConnectionQualityMutex.RLock()
defer fake.getConnectionQualityMutex.RUnlock()
fake.getCountryMutex.RLock()
defer fake.getCountryMutex.RUnlock()
fake.getDisableSenderReportPassThroughMutex.RLock()
defer fake.getDisableSenderReportPassThroughMutex.RUnlock()
fake.getEnabledPublishCodecsMutex.RLock()