grafana/k6 · error

invalid metric '%s' in threshold definitions: %w

Error message

invalid metric '%s' in threshold definitions: %w

What it means

While initializing thresholds from the test options, resolving the named metric or submetric failed (e.g. nonexistent metric or malformed submetric). InitSubMetricsAndThresholds wraps the underlying error from getThresholdMetricOrSubmetric; when onlyLogErrors is set the same condition is logged as a warning instead.

Source

Thrown at internal/metrics/engine/engine.go:130

	}
}

// InitSubMetricsAndThresholds parses the thresholds from the test Options and
// initializes both the thresholds themselves, as well as any submetrics that
// were referenced in them.
func (me *MetricsEngine) InitSubMetricsAndThresholds(options lib.Options, onlyLogErrors bool) error {
	for metricName, thresholds := range options.Thresholds {
		metric, err := me.getThresholdMetricOrSubmetric(metricName)

		if onlyLogErrors {
			if err != nil {
				me.logger.WithError(err).Warnf("Invalid metric '%s' in threshold definitions", metricName)
			}
			continue
		}

		if err != nil {
			return fmt.Errorf("invalid metric '%s' in threshold definitions: %w", metricName, err)
		}

		metric.Thresholds = thresholds
		me.metricsWithThresholds = append(me.metricsWithThresholds, metric)

		// Mark the metric (and the parent metric, if we're dealing with a
		// submetric) as observed, so they are shown in the end-of-test summary,
		// even if they don't have any metric samples during the test run
		me.markObserved(metric)
		if metric.Sub != nil {
			me.markObserved(metric.Sub.Parent)
		}
	}

	// TODO: refactor out of here when https://github.com/grafana/k6/issues/1321
	// lands and there is a better way to enable a metric with tag
	if options.SystemTags.Has(metrics.TagExpectedResponse) {
		_, err := me.getThresholdMetricOrSubmetric("http_req_duration{expected_response:true}")

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Fix or remove the invalid threshold entry in options.thresholds
  2. Ensure the metric name and optional {key:value} submetric syntax are correct
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/metrics/engine/engine.go:130 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/1aceef2d96b46d95. Report an issue: GitHub.