{"record":{"id":"10c9d34bb8526357","repo":"grafana/k6","slug":"submetric-criteria-for-metric-s-cannot-be-empty","errorCode":null,"errorMessage":"submetric criteria for metric '%s' cannot be empty","messagePattern":"submetric criteria for metric '(.+?)' cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"metrics/metric.go","lineNumber":43,"sourceCode":"\tObserved   bool         `json:\"-\"`\n}\n\n// A Submetric represents a filtered dataset based on a parent metric.\ntype Submetric struct {\n\tName   string  `json:\"name\"`\n\tSuffix string  `json:\"suffix\"` // TODO: rename?\n\tTags   *TagSet `json:\"tags\"`\n\n\tMetric *Metric `json:\"-\"`\n\tParent *Metric `json:\"-\"`\n}\n\n// AddSubmetric creates a new submetric from the key:value threshold definition\n// and adds it to the metric's submetrics list.\nfunc (m *Metric) AddSubmetric(keyValues string) (*Submetric, error) {\n\tkeyValues = strings.TrimSpace(keyValues)\n\tif len(keyValues) == 0 {\n\t\treturn nil, fmt.Errorf(\"submetric criteria for metric '%s' cannot be empty\", m.Name)\n\t}\n\tkvs := strings.Split(keyValues, \",\")\n\ttags := m.registry.RootTagSet()\n\tfor _, kv := range kvs {\n\t\tif kv == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tk, v, _ := strings.Cut(kv, \":\")\n\n\t\tkey := strings.Trim(strings.TrimSpace(k), `\"'`)\n\t\tif v == \"\" {\n\t\t\ttags = tags.With(key, \"\")\n\t\t\tcontinue\n\t\t}\n\n\t\tvalue := strings.Trim(strings.TrimSpace(v), `\"'`)\n\t\ttags = tags.With(key, value)\n\t}","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/metrics/metric.go#L25-L61","documentation":"Raised by Metric.AddSubmetric when the tag-filter portion of a threshold submetric name (the part inside {..} after the parent metric) is empty or whitespace-only, e.g. a threshold declared on 'my_metric{}'.","triggerScenarios":"Thrown at metrics/metric.go:43 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Provide at least one tag filter, e.g. my_metric{status:200}","Remove the empty curly braces if no filtering is intended"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}