grafana/k6 · error

failed parsing threshold expression %q; reason: %w

Error message

failed parsing threshold expression %q; reason: %w

What it means

The first stage of parseThresholdExpression — scanThresholdExpression — failed on the quoted input: the string could not be split into 'aggregation_method operator value'. Usually the operator token is missing or not one of the recognized tokens, or the right-hand side is empty.

Source

Thrown at metrics/thresholds_parser.go:77

// ```
// assertion           -> aggregation_method whitespace* operator whitespace* float
// aggregation_method  -> trend | rate | gauge | counter
// counter             -> "count" | "rate"
// gauge               -> "value"
// rate                -> "rate"
// trend               -> "avg" | "min" | "max" | "med" | percentile
// percentile          -> "p(" float ")"
// operator            -> ">" | ">=" | "<=" | "<" | "==" | "===" | "!="
// float               -> digit+ ("." digit+)?
// digit               -> "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
// whitespace          -> " "
// ```
func parseThresholdExpression(input string) (*thresholdExpression, error) {
	// Scanning makes no assumption on the underlying values, and only
	// checks that the expression has the right format.
	method, operator, value, err := scanThresholdExpression(input)
	if err != nil {
		return nil, fmt.Errorf("failed parsing threshold expression %q; reason: %w", input, err)
	}

	parsedMethod, parsedMethodValue, err := parseThresholdAggregationMethod(method)
	if err != nil {
		err = fmt.Errorf("failed parsing threshold expression's %q left hand side; "+
			"reason: %w", input, err,
		)
		return nil, err
	}

	parsedValue, err := strconv.ParseFloat(value, 64)
	if err != nil {
		err = fmt.Errorf("failed parsing threshold expresion's %q right hand side; "+
			"reason: %w", input, err,
		)
		return nil, err
	}

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Include a valid comparison operator: > >= <= < == === !=
  2. Provide a right-hand-side numeric value after the operator (e.g. 'p(95)<400' not 'p(95)<')
  3. Quote threshold keys in YAML so expressions are not mangled by the parser
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at metrics/thresholds_parser.go:77 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/0eb7795bf9e42d88. Report an issue: GitHub.