{"record":{"id":"d9a2c8b2edb7ef44","repo":"vitessio/vitess","slug":"multitimings-wrong-number-of-values-in-add","errorCode":null,"errorMessage":"MultiTimings: wrong number of values in Add","messagePattern":"MultiTimings: wrong number of values in Add","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/stats/timings.go","lineNumber":233,"sourceCode":"\t\tlabels:         labels,\n\t\tcombinedLabels: combinedLabels,\n\t}\n\tif name != \"\" {\n\t\tpublish(name, t)\n\t}\n\n\treturn t\n}\n\n// Labels returns descriptions of the parts of each compound category name.\nfunc (mt *MultiTimings) Labels() []string {\n\treturn mt.labels\n}\n\n// Add will add a new value to the named histogram.\nfunc (mt *MultiTimings) Add(names []string, elapsed time.Duration) {\n\tif len(names) != len(mt.labels) {\n\t\tpanic(\"MultiTimings: wrong number of values in Add\")\n\t}\n\tmt.Timings.Add(safeJoinLabels(names, mt.combinedLabels), elapsed)\n}\n\n// Record is a convenience function that records completion\n// timing data based on the provided start time of an event.\nfunc (mt *MultiTimings) Record(names []string, startTime time.Time) {\n\tif len(names) != len(mt.labels) {\n\t\tpanic(\"MultiTimings: wrong number of values in Record\")\n\t}\n\tmt.Timings.Record(safeJoinLabels(names, mt.combinedLabels), startTime)\n}\n\n// Cutoffs returns the cutoffs used in the component histograms.\n// Do not change the returned slice.\nfunc (mt *MultiTimings) Cutoffs() []int64 {\n\treturn bucketCutoffs\n}","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/stats/timings.go#L215-L251","documentation":"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.","triggerScenarios":"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\").","commonSituations":"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.","solutions":["Pass exactly one string per declared label, in declaration order: mt.Add([]string{keyspace, table}, elapsed).","Check mt.labels (or the NewMultiTimings labels argument) to see how many values each call needs.","Derive the label values from a single source of truth so creation and Add sites stay in sync."],"exampleFix":"// before (labels = [\"Keyspace\", \"Table\"])\nmt.Add([]string{ks}, elapsed) // panics: wrong number of values\n// after\nmt.Add([]string{ks, table}, elapsed)","handlingStrategy":"validation","validationCode":"if len(labelValues) != len(mt.Labels()) {\n    return fmt.Errorf(\"MultiTimings.Add expects %d values, got %d\", len(mt.Labels()), len(labelValues))\n}\nmt.Add(labelValues, elapsed)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When changing NewMultiTimings labels, grep and update every Add call site in the same commit.","Build the label-value slice at the single point where the dimensions are known.","Add a test that calls Add with the production label tuple."],"tags":["go","stats","panic","timings","arity-mismatch"],"backgroundTag":"length-mismatch","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}