{"record":{"id":"810953b764d24cab","repo":"vitessio/vitess","slug":"counterswithmultilabels-wrong-number-of-values-in-810953","errorCode":null,"errorMessage":"CountersWithMultiLabels: wrong number of values in Reset","messagePattern":"CountersWithMultiLabels: wrong number of values in Reset","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/stats/counters.go","lineNumber":224,"sourceCode":"// 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\n// Counts returns a copy of the Counters' map.\n// The key is a single string where all labels are joined by a \".\" e.g.\n// \"label1.label2\".\nfunc (mc *CountersWithMultiLabels) Counts() map[string]int64 {\n\treturn mc.counters.Counts()\n}\n\n// CountersFuncWithMultiLabels is a multidimensional counters implementation\n// where names of categories are compound names made with joining","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/stats/counters.go#L206-L242","documentation":"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.","triggerScenarios":"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.","commonSituations":"Resetting counters in tests or shutdown paths with stale/hardcoded label lists; dynamic label construction that omits empty labels.","solutions":["Supply all label values in the same order used at counter creation","Update the Reset call site after any change to the counter's labels","If the goal is clearing everything, use ResetAll() instead of per-key Reset"],"exampleFix":"// before\nmc.Reset([]string{keyspace}) // counter has 2 labels -> panics\n// after\nmc.Reset([]string{keyspace, table})\n// or: mc.ResetAll()","handlingStrategy":"validation","validationCode":"if len(names) == len(mc.Labels()) {\n    mc.Reset(names)\n} else {\n    mc.ResetAll()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reuse the same label-construction helper for Add and Reset","Prefer ResetAll when you don't have a complete key","Update Reset call sites together with metric schema changes"],"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"}