Check if current stats < prev and guard against underflow (#563)
Signed-off-by: shishir gowda <shishir@livekit.io>
This commit is contained in:
@@ -3,6 +3,8 @@ package telemetry
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/livekit/protocol/logger"
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"google.golang.org/protobuf/proto"
|
||||||
|
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
@@ -370,11 +372,13 @@ func (stats *Stats) computeDeltaStats() *livekit.AnalyticsStat {
|
|||||||
// store new max layer for next round
|
// store new max layer for next round
|
||||||
cur.MaxLayer = maxLayer
|
cur.MaxLayer = maxLayer
|
||||||
// we accumulate bytes/packets across layers
|
// we accumulate bytes/packets across layers
|
||||||
videoLayer.TotalBytes = cur.TotalBytes - prev.TotalBytes
|
|
||||||
videoLayer.TotalPackets = cur.TotalPackets - prev.TotalPackets
|
if cur.TotalBytes < prev.TotalBytes || cur.TotalPackets < prev.TotalPackets {
|
||||||
if int64(videoLayer.TotalBytes) < 0 || int32(videoLayer.TotalPackets) < 0 {
|
logger.Debugw("computeDeltaStats cur less than prev", "current", cur, "prev", prev)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
videoLayer.TotalBytes = cur.TotalBytes - prev.TotalBytes
|
||||||
|
videoLayer.TotalPackets = cur.TotalPackets - prev.TotalPackets
|
||||||
}
|
}
|
||||||
// if no packets from any layers, return nil to send no stats
|
// if no packets from any layers, return nil to send no stats
|
||||||
if deltaStats.TotalPackets == 0 && deltaStats.TotalPrimaryPackets == 0 && deltaStats.TotalRetransmitPackets == 0 && deltaStats.TotalPaddingPackets == 0 {
|
if deltaStats.TotalPackets == 0 && deltaStats.TotalPrimaryPackets == 0 && deltaStats.TotalRetransmitPackets == 0 && deltaStats.TotalPaddingPackets == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user