{"record":{"id":"af86996b0020a2bb","repo":"vitessio/vitess","slug":"counterswithmultilabels-wrong-number-of-values-in","errorCode":null,"errorMessage":"CountersWithMultiLabels: wrong number of values in Add","messagePattern":"CountersWithMultiLabels: wrong number of values in Add","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/stats/counters.go","lineNumber":215,"sourceCode":"\t\tt.combinedLabels[i] = IsDimensionCombined(label)\n\t}\n\tif name != \"\" {\n\t\tpublish(name, t)\n\t}\n\n\treturn t\n}\n\n// Labels returns the list of labels.\nfunc (mc *CountersWithMultiLabels) Labels() []string {\n\treturn mc.labels\n}\n\n// Add adds a value to a named counter.\n// len(names) must be equal to len(Labels)\nfunc (mc *CountersWithMultiLabels) Add(names []string, value int64) {\n\tif len(names) != len(mc.labels) {\n\t\tpanic(\"CountersWithMultiLabels: wrong number of values in Add\")\n\t}\n\tmc.add(safeJoinLabels(names, mc.combinedLabels), value)\n}\n\n// Reset resets the value of a named counter back to 0.\n// len(names) must be equal to len(Labels).\nfunc (mc *CountersWithMultiLabels) Reset(names []string) {\n\tif len(names) != len(mc.labels) {\n\t\tpanic(\"CountersWithMultiLabels: wrong number of values in Reset\")\n\t}\n\tmc.set(safeJoinLabels(names, mc.combinedLabels), 0)\n}\n\n// ResetAll clears the counters\nfunc (mc *CountersWithMultiLabels) ResetAll() {\n\tmc.reset()\n}\n","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/stats/counters.go#L197-L233","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nmc.Add([]string{keyspace}, 1) // counter has 2 labels -> panics\n// after\nmc.Add([]string{keyspace, table}, 1)","handlingStrategy":"validation","validationCode":"if len(names) == len(mc.Labels()) {\n    mc.Add(names, value)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["go","panic","stats","metrics"],"backgroundTag":"label-arity-mismatch","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}