grafana/k6 · error

malformed threshold expression

Error message

malformed threshold expression

What it means

scanThresholdExpression found no valid operator token in the input: none of the operatorTokens (>, >=, <=, <, ==, ===, !=) split the string into a non-empty left and right part. The expression is malformed at the top level — typically a missing operator or a dangling value.

Source

Thrown at metrics/thresholds_parser.go:152

	tokenLooselyEqual,
	tokenBangEqual,
}

// scanThresholdExpression scans a threshold condition expression of the
// form: `aggregation_method operator value`. An invalid or unknown operator
// will produce an error. However, no assertions regarding
// either the left-hand side aggregation method nor the right-hand
// side value will be made: they will be returned as is, only trimmed from
// their spaces.
func scanThresholdExpression(input string) (string, string, string, error) {
	for _, op := range operatorTokens {
		left, right, _ := strings.Cut(input, op)
		if right != "" {
			return strings.TrimSpace(left), op, strings.TrimSpace(right), nil
		}
	}

	return "", "", "", fmt.Errorf("malformed threshold expression")
}

// Define accepted threshold expression aggregation tokens
// Percentile token `p(..)` is accepted too but handled separately.
const (
	tokenValue      = "value"
	tokenCount      = "count"
	tokenRate       = "rate"
	tokenAvg        = "avg"
	tokenMin        = "min"
	tokenMed        = "med"
	tokenMax        = "max"
	tokenPercentile = "p"
)

// aggregationMethodTokens defines the list of aggregation method
// used in the parsing of threshold expressions.
//

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Add a comparison operator to the threshold, e.g. 'avg>100'
  2. Make sure both sides of the operator are non-empty
  3. Verify the threshold key wasn't truncated or mis-quoted in the options
Defensive patterns

Strategy: validation

When it happens

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

Common situations: See trigger scenarios.

Understand the failure class


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