grafana/k6 · error

invalid threshold

Error message

invalid threshold

What it means

Sentinel error (ErrInvalidThreshold) from Thresholds.Validate: a threshold definition is inconsistent with its metric — either the metric name does not exist in the registry, or the threshold's aggregation method is unsupported for the metric's type. It is stamped with exit code InvalidConfig.

Solutions

  1. Verify the metric name in the threshold exists (watch for typos or missing submetric tags)
  2. Use an aggregation method supported by the metric type, e.g. rate/count only on counters, avg/max/p on trends
  3. Ensure custom metrics are declared before thresholds reference them
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at metrics/thresholds.go:236 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/6931b5399af4599f. Report an issue: GitHub.

Appendix: source

Thrown at metrics/thresholds.go:236

}

// Parse parses the Thresholds and fills each Threshold.parsed field with the result.
// It effectively asserts they are syntaxically correct.
func (ts *Thresholds) Parse() error {
	for _, t := range ts.Thresholds {
		parsed, err := parseThresholdExpression(t.Source)
		if err != nil {
			return err
		}

		t.parsed = parsed
	}

	return nil
}

// ErrInvalidThreshold indicates a threshold is not valid
var ErrInvalidThreshold = errors.New("invalid threshold")

// Validate ensures a threshold definition is consistent with the metric it applies to.
// Given a metric registry and a metric name to apply the expressions too, Validate will
// assert that each threshold expression uses an aggregation method that's supported by the
// provided metric. It returns an error otherwise.
// Note that this function expects the passed in thresholds to have been parsed already, and
// have their Parsed (ThresholdExpression) field already filled.
func (ts *Thresholds) Validate(metricName string, r *Registry) error {
	parsedMetricName, _, err := ParseMetricName(metricName)
	if err != nil {
		parseErr := fmt.Errorf("unable to validate threshold expressions; reason: %w", err)
		return errext.WithExitCodeIfNone(parseErr, exitcodes.InvalidConfig)
	}

	// Obtain the metric the thresholds apply to from the registry.
	// if the metric doesn't exist, then we return an error indicating
	// the InvalidConfig exitcode should be used.
	metric := r.Get(parsedMetricName)

View on GitHub (pinned to 01ffac6f24)