vitessio/vitess · error
CountersWithMultiLabels: wrong number of values in Add
Error message
CountersWithMultiLabels: wrong number of values in Add
What it means
CountersWithMultiLabels.Add panics when the number of label values in names does not match the number of labels the counter was created with. Multi-label counters require an exact arity match to join names into a single safe key. This is a programming error caught eagerly rather than producing malformed metric keys.
Source
Thrown at go/stats/counters.go:215
t.combinedLabels[i] = IsDimensionCombined(label)
}
if name != "" {
publish(name, t)
}
return t
}
// 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()
}
View on GitHub (pinned to 01a25a7d17)
Solutions
- Pass exactly one value per declared label: pad or trim the names slice to len(mc.labels)
- Update all Add call sites after changing the counter's label definition
- Add a runtime check/log before Add when names are built dynamically
Example fix
// before
mc.Add([]string{keyspace}, 1) // counter has 2 labels -> panics
// after
mc.Add([]string{keyspace, table}, 1) Defensive patterns
Strategy: validation
Validate before calling
if len(names) == len(mc.Labels()) {
mc.Add(names, value)
} Prevention
- Define counter labels in one constant and build names slices from it
- Grep for Add call sites whenever a counter's label list changes
- Pad optional labels with explicit placeholders rather than omitting them
When it happens
Trigger: Calling mc.Add(names, value) with len(names) != len(mc.labels), e.g. a counter created with NewCountersWithMultiLabels("x", []string{"keyspace","table"}) but Add called with one or three names.
Common situations: Metric schema changed (a label added/removed) but all Add call sites weren't updated; dynamic label slices built at runtime with optional segments omitted; copy-pasted code reusing a counter with different arity.
Related errors
- CountersWithMultiLabels: wrong number of values in Reset
- GaugesWithMultiLabels: wrong number of values in Set
- You've already registered a function
- nil not allowed
- interval too small
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/af86996b0020a2bb.
Report an issue: GitHub.