grafana/k6 · error
unable to apply threshold %s over metrics; reason: %s is an
Error message
unable to apply threshold %s over metrics; reason: %s is an invalid operator
What it means
Reached the default branch of the operator switch in Threshold.run: the parsed threshold expression carries an operator token that is not one of >, >=, <=, <, ==, ===, !=. The parser (parseThresholdExpression) should reject unknown operators earlier, so hitting this guard means a mismatch between the scanner's accepted operator set and this switch — effectively an internal invariant check.
Source
Thrown at metrics/thresholds.go:71
switch t.parsed.Operator {
case ">":
passes = lhs > t.parsed.Value
case ">=":
passes = lhs >= t.parsed.Value
case "<=":
passes = lhs <= t.parsed.Value
case "<":
passes = lhs < t.parsed.Value
case "==", "===":
// Considering a sink always maps to float64 values,
// strictly equal is equivalent to loosely equal
passes = lhs == t.parsed.Value
case "!=":
passes = lhs != t.parsed.Value
default:
// The parseThresholdExpression function should ensure that no invalid
// operator gets through, but let's protect our future selves anyhow.
return false, fmt.Errorf("unable to apply threshold %s over metrics; "+
"reason: %s is an invalid operator",
t.Source,
t.parsed.Operator,
)
}
// Perform the actual threshold verification
return passes, nil
}
func (t *Threshold) run(sinks map[string]float64) (bool, error) {
passes, err := t.runNoTaint(sinks)
t.LastFailed = !passes
return passes, err
}
type thresholdConfig struct {
Threshold string `json:"threshold"`View on GitHub (pinned to 01ffac6f24)
Solutions
- Verify the operator token lists (operatorTokens in thresholds_parser.go) exactly match the cases handled in Threshold.run
- Fix the threshold expression to use a supported operator: >, >=, <=, <, ==, ===, !=
- Report the inconsistency as a k6 bug if the expression was produced by the parser
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at metrics/thresholds.go:71 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/08f9693c293e997d.
Report an issue: GitHub.