vitessio/vitess · error

MultiTimings: wrong number of values in Add

Error message

MultiTimings: wrong number of values in Add

What it means

MultiTimings histograms are keyed by a fixed tuple of label dimensions; Add must therefore receive exactly one value per declared label. When the number of names differs from len(mt.labels), the library panics rather than recording data under a malformed key.

Source

Thrown at go/stats/timings.go:233

		labels:         labels,
		combinedLabels: combinedLabels,
	}
	if name != "" {
		publish(name, t)
	}

	return t
}

// 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, in declaration order: mt.Add([]string{keyspace, table}, elapsed).
  2. Check mt.labels (or the NewMultiTimings labels argument) to see how many values each call needs.
  3. Derive the label values from a single source of truth so creation and Add sites stay in sync.

Example fix

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

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: Calling mt.Add(names, elapsed) where len(names) != len(mt.labels), e.g. mt.Add([]string{"ks"}, d) on a MultiTimings created with two labels (e.g. "Keyspace"+"Table").

Common situations: Adding a second dimension to a MultiTimings at the creation site without updating all Add call sites; passing a single combined string instead of one value per label; refactoring code shared between single-dimension Timings and MultiTimings.

Related errors


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