grafana/k6 · error

failed parsing threshold expression's %q left hand side; rea

Error message

failed parsing threshold expression's %q left hand side; reason: %w

What it means

The left-hand side of the threshold expression (the aggregation method) failed to parse via parseThresholdAggregationMethod. It is not one of the keywords (avg, min, max, med, count, rate, value) nor a well-formed percentile expression p(number). The wrapping keeps the whole quoted expression for context.

Source

Thrown at metrics/thresholds_parser.go:82

// 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
	}

	condition := &thresholdExpression{
		AggregationMethod: parsedMethod,
		AggregationValue:  parsedMethodValue,
		Operator:          operator,
		Value:             parsedValue,

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Use a supported aggregation method: avg, min, max, med, count, rate, value, or p(N)
  2. For percentiles use the exact form p(95) with a number between 0 and 100
  3. Match the method to the metric type: trend supports avg/min/max/med/p(N), counter supports count/rate, gauge supports value, rate supports rate
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at metrics/thresholds_parser.go:82 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/61b481149b5d3aa9. Report an issue: GitHub.