grafana/k6 · error · ErrMetricNameParsing

parsing metric name failed

Error message

parsing metric name failed

What it means

ErrMetricNameParsing (metrics/metric.go:85) is the sentinel wrapped by every failure of metrics.ParseMetricName (lines 90-146). Metric name expressions have the form name{tag:value,...}; parsing fails on: unmatched '{' or '}' (line 104), '}' appearing before '{' (line 114), the last character not being '}' (line 120), or a tag entry whose value after ':' is empty (line 138). Callers such as Thresholds.Validate and outputs hit it while resolving sub-metric expressions like 'http_req_duration{status:200}'.

Source

Thrown at metrics/metric.go:85

	}

	subMetric := &Submetric{
		Name:   m.Name + "{" + keyValues + "}",
		Suffix: keyValues,
		Tags:   tags,
		Parent: m,
	}
	subMetricMetric := m.registry.newMetric(subMetric.Name, m.Type, m.Contains)
	subMetricMetric.Sub = subMetric // sigh
	subMetric.Metric = subMetricMetric

	m.Submetrics = append(m.Submetrics, subMetric)

	return subMetric, nil
}

// ErrMetricNameParsing indicates parsing a metric name failed
var ErrMetricNameParsing = errors.New("parsing metric name failed")

// ParseMetricName parses a metric name expression of the form metric_name{tag_key:tag_value,...}
// Its first return value is the parsed metric name, second are parsed tags as as slice
// of "key:value" strings. On failure, it returns an error containing the `ErrMetricNameParsing` in its chain.
func ParseMetricName(name string) (string, []string, error) {
	openingTokenPos := strings.IndexByte(name, '{')
	closingTokenPos := strings.LastIndexByte(name, '}')
	containsOpeningToken := openingTokenPos != -1
	containsClosingToken := closingTokenPos != -1

	// Neither the opening '{' token nor the closing '}' token
	// are present, thus the metric name only consists of a literal.
	if !containsOpeningToken && !containsClosingToken {
		return name, nil, nil
	}

	// If the name contains an opening or closing token, but not
	// its counterpart, the expression is malformed.

View on GitHub (pinned to 93accf6570)

Solutions

  1. Fix the expression to name{tag:value} with a closing brace in last position and non-empty tag values, e.g. 'http_req_duration{status:200}': ['p(95)<800']
  2. Multiple tags are comma-separated inside the braces: 'metric{a:1,b:2}'
  3. If the error surfaced from Thresholds.Validate, note it is wrapped as 'unable to validate threshold expressions; reason: ...' with exit code InvalidConfig — fix the metric name expression it names

Example fix

// before
export const options = {
  thresholds: { 'http_req_duration{status:}': ['p(95)<800'] },
};

// after
export const options = {
  thresholds: { 'http_req_duration{status:200}': ['p(95)<800'] },
};
Defensive patterns

Strategy: validation

Validate before calling

// Go: pre-check a sub-metric expression before handing it to metrics APIs
func validMetricExpr(name string) bool {
    o := strings.IndexByte(name, '{')
    c := strings.LastIndexByte(name, '}')
    if o == -1 && c == -1 { return true }
    if o == -1 || c == -1 || c < o || c != len(name)-1 { return false }
    for _, t := range strings.Split(name[o+1:c], ",") {
        _, v, _ := strings.Cut(t, ":")
        if v == "" { return false }
    }
    return true
}

Try / catch

// Go: detect this sentinel in a returned error chain
if err != nil {
    if errors.Is(err, metrics.ErrMetricNameParsing) {
        // fix the metric name expression: name{tag:value}
    }
}

Prevention

When it happens

Trigger: Thresholds on 'http_req_duration{status' (missing brace), 'metric}{' (wrong order), 'metric{a:b}extra' (trailing text after brace), or 'http_req_duration{status:}' (empty tag value). ParseMetricName returns the parsed name and key:value tags, or an error whose chain contains this sentinel (check with errors.Is).

Common situations: Hand-written thresholds on tagged sub-metrics where the tag value references a non-existent or misspelled tag, or is accidentally blank; quoted braces in templated scripts; copying threshold syntax from docs into configs that strip braces.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/8ce87ed48edc5c64. Report an issue: GitHub.