Push the new origin into the sample ring so a reset cannot underflow the totals

This commit is contained in:
flamingcow
2026-08-04 12:59:50 -07:00
parent a285b8999c
commit fb6a0d2c1b
2 changed files with 42 additions and 2 deletions
+4 -2
View File
@@ -263,11 +263,13 @@ func (d *direction) snapshot() sample {
}
// Counters keep climbing in the workers, so resetting just moves the origin
// everything is measured from. Rates are deliberately left running, since they
// are instantaneous and would only blink to zero and back.
// everything is measured from. Rates and the rolling error window are about now
// rather than since the reset, so they keep running; the origin goes into the
// ring so the newest bucket never sits behind it.
func (d *direction) reset() {
d.mu.Lock()
d.base = d.capture(time.Now())
d.win.push(d.base)
d.mu.Unlock()
d.heldFrames = heldValue{}