Telemetry connection scores (#377)

* octets - total bytes needs to be uint64

uint32 wraps at 4GB

Signed-off-by: shishir gowda <shishir@livekit.io>

* Cleanup stats handler to use connectionQuality stats

remove per packet rtcp handlers, buffer stats

* cleanup connection stats

* Update mediatrack to store rtcp stats in connection stats

* Update downstream handling of connection stats and telemetry

* Update telemetry tests

Signed-off-by: shishir gowda <shishir@livekit.io>

* Misc fixes

Signed-off-by: shishir gowda <shishir@livekit.io>

* Minor fix to avoid accessing buffer before its allocated

Signed-off-by: shishir gowda <shishir@livekit.io>

* start updateStats worker in AddReciever()

Signed-off-by: shishir gowda <shishir@livekit.io>

* Use previous score to calculate avg scores

* Restructure connectionStats

Signed-off-by: shishir gowda <shishir@livekit.io>
This commit is contained in:
shishirng
2022-01-27 11:24:54 -05:00
committed by GitHub
parent 32825d2666
commit 26eea78b54
11 changed files with 266 additions and 339 deletions
+4 -47
View File
@@ -4,12 +4,9 @@ import (
"context"
"github.com/gammazero/workerpool"
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/webhook"
"github.com/pion/rtcp"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
"github.com/livekit/livekit-server/pkg/telemetry/prometheus"
)
type TelemetryServiceInternal interface {
@@ -40,58 +37,18 @@ func NewTelemetryServiceInternal(notifier webhook.Notifier, analytics AnalyticsS
}
}
func (t *telemetryServiceInternal) AddUpTrack(participantID livekit.ParticipantID, trackID livekit.TrackID, buff *buffer.Buffer) {
w := t.workers[participantID]
if w != nil {
w.AddBuffer(trackID, buff)
}
}
func (t *telemetryServiceInternal) OnDownstreamPacket(participantID livekit.ParticipantID, trackID livekit.TrackID, bytes int) {
w := t.workers[participantID]
if w != nil {
w.OnDownstreamPacket(trackID, bytes)
}
}
func (t *telemetryServiceInternal) HandleRTCP(streamType livekit.StreamType, participantID livekit.ParticipantID, trackID livekit.TrackID, pkts []rtcp.Packet) {
stats := &livekit.AnalyticsStat{}
for _, pkt := range pkts {
switch pkt := pkt.(type) {
case *rtcp.TransportLayerNack:
stats.NackCount++
case *rtcp.PictureLossIndication:
stats.PliCount++
case *rtcp.FullIntraRequest:
stats.FirCount++
case *rtcp.ReceiverReport:
for _, rr := range pkt.Reports {
if jitter := float64(rr.Jitter); jitter > stats.Jitter {
stats.Jitter = jitter
}
if totalLost := uint64(rr.TotalLost); totalLost > stats.PacketLost {
stats.PacketLost = totalLost
}
}
if streamType == livekit.StreamType_DOWNSTREAM {
rtt := GetRttMs(pkt)
if rtt >= 0 {
stats.Rtt = uint32(rtt)
}
}
}
}
func (t *telemetryServiceInternal) TrackStats(streamType livekit.StreamType, participantID livekit.ParticipantID, trackID livekit.TrackID, stat *livekit.AnalyticsStat) {
direction := prometheus.Incoming
if streamType == livekit.StreamType_DOWNSTREAM {
direction = prometheus.Outgoing
}
prometheus.IncrementRTCP(direction, stats.NackCount, stats.PliCount, stats.FirCount)
prometheus.IncrementRTCP(direction, stat.NackCount, stat.PliCount, stat.FirCount)
w := t.workers[participantID]
if w != nil {
w.OnRTCP(trackID, streamType, stats)
w.OnTrackStat(trackID, streamType, stat)
}
}