vitessio/vitess · error
interval too small
Error message
interval too small
What it means
NewGauges samples gauge values on a background timer, so the sampling interval must be at least 1 second (the -1s sentinel disables snapshotting, mainly for tests). Any smaller positive interval is rejected with a panic because the sampler cannot run reliably below one second.
Source
Thrown at go/stats/gauges.go:45
// Gauges tracks gauge values over time by sampling them at regular intervals.
// Unlike Rates which tracks operation rates, Gauges tracks actual values.
type Gauges struct {
mu sync.Mutex
timeStamps *RingInt64
history map[string]*RingInt64 // Historical sampled values
current map[string]*atomic.Int64 // Current gauge values
samples int
interval time.Duration
ctx context.Context
cancel context.CancelFunc
}
// NewGauges creates a new Gauges object that samples gauge values at regular intervals.
// samples: number of historical samples to keep
// interval: how often to sample the current gauge values
func NewGauges(samples int, interval time.Duration) *Gauges {
if interval < 1*time.Second && interval != -1*time.Second {
panic("interval too small")
}
ctx, cancel := context.WithCancel(context.Background())
g := &Gauges{
timeStamps: NewRingInt64(samples + 1),
history: make(map[string]*RingInt64),
current: make(map[string]*atomic.Int64),
samples: samples + 1,
interval: interval,
ctx: ctx,
cancel: cancel,
}
// Start background sampling goroutine
if interval > 0 {
go g.track()
}
return gView on GitHub (pinned to 01a25a7d17)
Solutions
- Pass an interval of at least 1*time.Second to NewGauges.
- Use -1*time.Second if you intentionally want no snapshotting (test mode).
- If you need sub-second sampling, this API does not support it — aggregate more frequently elsewhere or change the call site's cadence.
Example fix
// before g := stats.NewGauges(5, 100*time.Millisecond) // panics: interval too small // after g := stats.NewGauges(5, 1*time.Second)
Defensive patterns
Strategy: validation
Validate before calling
const minInterval = 1 * time.Second
if interval != -1*time.Second && interval < minInterval {
interval = minInterval // clamp before calling NewGauges
}
g := stats.NewGauges(samples, interval) Prevention
- Centralize sampling intervals as named constants >= 1s.
- Always write durations with units (time.Millisecond), never bare integers.
- Remember the -1s sentinel means 'no snapshot' (tests only).
When it happens
Trigger: Calling stats.NewGauges(samples, d) where d is 0, or any duration in (0, 1s), e.g. NewGauges(5, 100*time.Millisecond).
Common situations: Copy-pasting an interval from a fast unit test; passing time.Duration(0) as a 'default' without realizing 0 means an unusable sampler; converting from milliseconds to time.Duration incorrectly (e.g. 500 instead of 500*time.Millisecond).
Related errors
- interval too small
- CountersWithMultiLabels: wrong number of values in Add
- CountersWithMultiLabels: wrong number of values in Reset
- GaugesWithMultiLabels: wrong number of values in Set
- You've already registered a function
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/10151d4785101421.
Report an issue: GitHub.