{"record":{"id":"8ce87ed48edc5c64","repo":"grafana/k6","slug":"parsing-metric-name-failed","errorCode":null,"errorMessage":"parsing metric name failed","messagePattern":"parsing metric name failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"metrics/metric.go","lineNumber":85,"sourceCode":"\t}\n\n\tsubMetric := &Submetric{\n\t\tName:   m.Name + \"{\" + keyValues + \"}\",\n\t\tSuffix: keyValues,\n\t\tTags:   tags,\n\t\tParent: m,\n\t}\n\tsubMetricMetric := m.registry.newMetric(subMetric.Name, m.Type, m.Contains)\n\tsubMetricMetric.Sub = subMetric // sigh\n\tsubMetric.Metric = subMetricMetric\n\n\tm.Submetrics = append(m.Submetrics, subMetric)\n\n\treturn subMetric, nil\n}\n\n// ErrMetricNameParsing indicates parsing a metric name failed\nvar ErrMetricNameParsing = errors.New(\"parsing metric name failed\")\n\n// ParseMetricName parses a metric name expression of the form metric_name{tag_key:tag_value,...}\n// Its first return value is the parsed metric name, second are parsed tags as as slice\n// of \"key:value\" strings. On failure, it returns an error containing the `ErrMetricNameParsing` in its chain.\nfunc ParseMetricName(name string) (string, []string, error) {\n\topeningTokenPos := strings.IndexByte(name, '{')\n\tclosingTokenPos := strings.LastIndexByte(name, '}')\n\tcontainsOpeningToken := openingTokenPos != -1\n\tcontainsClosingToken := closingTokenPos != -1\n\n\t// Neither the opening '{' token nor the closing '}' token\n\t// are present, thus the metric name only consists of a literal.\n\tif !containsOpeningToken && !containsClosingToken {\n\t\treturn name, nil, nil\n\t}\n\n\t// If the name contains an opening or closing token, but not\n\t// its counterpart, the expression is malformed.","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/metrics/metric.go#L67-L103","documentation":"Sentinel error (ErrMetricNameParsing) indicating a metric name expression of the form name{tag:value,...} is malformed. ParseMetricName wraps it with specifics: unmatched curly braces, or a closing brace appearing before the opening one.","triggerScenarios":"Thrown at metrics/metric.go:85 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Balance the curly braces in the metric expression, e.g. 'http_req_duration{status:200}'","Ensure the closing '}' comes after the opening '{' and there is at most one brace group"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}