vitessio/vitess · error

CountersWithMultiLabels: wrong number of values in Reset

Error message

CountersWithMultiLabels: wrong number of values in Reset

What it means

CountersWithMultiLabels.Reset panics when len(names) does not equal the number of labels the counter was declared with. Like Add, Reset joins names into the counter key and must match the declared arity exactly.

Source

Thrown at go/stats/counters.go:224

// Labels returns the list of labels.
func (mc *CountersWithMultiLabels) Labels() []string {
	return mc.labels
}

// Add adds a value to a named counter.
// len(names) must be equal to len(Labels)
func (mc *CountersWithMultiLabels) Add(names []string, value int64) {
	if len(names) != len(mc.labels) {
		panic("CountersWithMultiLabels: wrong number of values in Add")
	}
	mc.add(safeJoinLabels(names, mc.combinedLabels), value)
}

// Reset resets the value of a named counter back to 0.
// len(names) must be equal to len(Labels).
func (mc *CountersWithMultiLabels) Reset(names []string) {
	if len(names) != len(mc.labels) {
		panic("CountersWithMultiLabels: wrong number of values in Reset")
	}
	mc.set(safeJoinLabels(names, mc.combinedLabels), 0)
}

// ResetAll clears the counters
func (mc *CountersWithMultiLabels) ResetAll() {
	mc.reset()
}

// Counts returns a copy of the Counters' map.
// The key is a single string where all labels are joined by a "." e.g.
// "label1.label2".
func (mc *CountersWithMultiLabels) Counts() map[string]int64 {
	return mc.counters.Counts()
}

// CountersFuncWithMultiLabels is a multidimensional counters implementation
// where names of categories are compound names made with joining

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Supply all label values in the same order used at counter creation
  2. Update the Reset call site after any change to the counter's labels
  3. If the goal is clearing everything, use ResetAll() instead of per-key Reset

Example fix

// before
mc.Reset([]string{keyspace}) // counter has 2 labels -> panics
// after
mc.Reset([]string{keyspace, table})
// or: mc.ResetAll()
Defensive patterns

Strategy: validation

Validate before calling

if len(names) == len(mc.Labels()) {
    mc.Reset(names)
} else {
    mc.ResetAll()
}

Prevention

When it happens

Trigger: Calling mc.Reset(names) with a slice whose length differs from len(mc.labels), e.g. resetting with a partial label list after a metric schema change.

Common situations: Resetting counters in tests or shutdown paths with stale/hardcoded label lists; dynamic label construction that omits empty labels.

Related errors


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