From 7c7ff34a5a39616ee669f2ec5d06bbb007a92876 Mon Sep 17 00:00:00 2001 From: Mike Spreitzer Date: Mon, 21 Aug 2023 15:26:38 -0400 Subject: [PATCH] Handle edge cases in seat demand stats Signed-off-by: Mike Spreitzer Kubernetes-commit: b0e249f657a18c1435ace391fa752711dafce732 --- pkg/util/flowcontrol/apf_controller.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/util/flowcontrol/apf_controller.go b/pkg/util/flowcontrol/apf_controller.go index 708bf2cde..f2df57ccc 100644 --- a/pkg/util/flowcontrol/apf_controller.go +++ b/pkg/util/flowcontrol/apf_controller.go @@ -263,9 +263,15 @@ type seatDemandStats struct { } func (stats *seatDemandStats) update(obs fq.IntegratorResults) { + stats.highWatermark = obs.Max + if obs.Duration <= 0 { + return + } + if math.IsNaN(obs.Deviation) { + obs.Deviation = 0 + } stats.avg = obs.Average stats.stdDev = obs.Deviation - stats.highWatermark = obs.Max envelope := obs.Average + obs.Deviation stats.smoothed = math.Max(envelope, seatDemandSmoothingCoefficient*stats.smoothed+(1-seatDemandSmoothingCoefficient)*envelope) }