Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions vertical-pod-autoscaler/pkg/recommender/util/histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,24 @@ func (h *histogram) AddSample(value float64, weight float64, time time.Time) {
}
}

func safeSubtract(value, sub, epsilon float64) float64 {
value -= sub
if value < epsilon {
return 0.0
}
return value
}

func (h *histogram) SubtractSample(value float64, weight float64, time time.Time) {
if weight < 0.0 {
panic("sample weight must be non-negative")
}
bucket := h.options.FindBucket(value)
epsilon := h.options.Epsilon()
if weight > h.bucketWeight[bucket]-epsilon {
weight = h.bucketWeight[bucket]
}
h.totalWeight -= weight
h.bucketWeight[bucket] -= weight

h.totalWeight = safeSubtract(h.totalWeight, weight, epsilon)
h.bucketWeight[bucket] = safeSubtract(h.bucketWeight[bucket], weight, epsilon)

h.updateMinAndMaxBucket()
}

Expand Down