vitessio/vitess · error

MultiTimings: wrong number of values in Record

Error message

MultiTimings: wrong number of values in Record

What it means

Like Add, MultiTimings.Record derives the histogram key from the tuple of label values, so it validates that names has exactly one entry per declared label and panics otherwise. Record is the time.Time-based variant used when the caller captured a start time earlier.

Source

Thrown at go/stats/timings.go:242

// Labels returns descriptions of the parts of each compound category name.
func (mt *MultiTimings) Labels() []string {
	return mt.labels
}

// Add will add a new value to the named histogram.
func (mt *MultiTimings) Add(names []string, elapsed time.Duration) {
	if len(names) != len(mt.labels) {
		panic("MultiTimings: wrong number of values in Add")
	}
	mt.Timings.Add(safeJoinLabels(names, mt.combinedLabels), elapsed)
}

// Record is a convenience function that records completion
// timing data based on the provided start time of an event.
func (mt *MultiTimings) Record(names []string, startTime time.Time) {
	if len(names) != len(mt.labels) {
		panic("MultiTimings: wrong number of values in Record")
	}
	mt.Timings.Record(safeJoinLabels(names, mt.combinedLabels), startTime)
}

// Cutoffs returns the cutoffs used in the component histograms.
// Do not change the returned slice.
func (mt *MultiTimings) Cutoffs() []int64 {
	return bucketCutoffs
}

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Pass exactly one string per declared label: mt.Record([]string{keyspace, table}, start).
  2. Grep all Record call sites when changing the number of labels in NewMultiTimings.
  3. Build the names slice where the dimensions are known, and assert len(names) == len(mt.labels) in tests.

Example fix

// before (labels = ["Keyspace", "Table"])
mt.Record([]string{ks}, start) // panics: wrong number of values
// after
mt.Record([]string{ks, table}, start)
Defensive patterns

Strategy: validation

Validate before calling

if len(labelValues) != len(mt.Labels()) {
    return fmt.Errorf("MultiTimings.Record expects %d values, got %d", len(mt.Labels()), len(labelValues))
}
mt.Record(labelValues, start)

Prevention

When it happens

Trigger: Calling mt.Record(names, startTime) where len(names) != len(mt.labels), typically after adding a dimension to the MultiTimings without updating Record call sites.

Common situations: Refactoring Timings.Record to MultiTimings.Record while keeping a single-element slice; label count changed at construction (new dimension added) but Record callers not updated; forgetting that Record requires the same arity as Add.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/098ad862c28958e2. Report an issue: GitHub.