grafana/k6 · error

unknown metric

Error message

unknown metric: %s

What it means

The web dashboard aggregator (internal/dashboard/aggregate.go:246) processes a stream of JSON events: 'metric' events define metrics in a registry, 'point' events carry samples. processPoint looks the name up in the registry and returns errUnknownMetric (wrapped as 'unknown metric: <name>') when a sample arrives for a metric that was never defined.

Solutions

  1. Ensure metric definition events precede their sample points in whatever stream the dashboard consumes.
  2. Verify metric names match exactly (no extra whitespace/case differences) between definitions and points.
  3. If this reproduces with a plain `k6 run --web-dashboard script.js`, report it with the script to github.com/grafana/k6/issues.
Defensive patterns

Strategy: fallback

Validate before calling

// when feeding a recorded stream to the dashboard, drop points for undefined metrics
const defined = new Set(events.filter(e => e.type === 'metric').map(e => e.data.name));
const safe = events.filter(e => e.type !== 'point' || defined.has(e.metric));

Prevention

When it happens

Trigger: Feeding the dashboard (websocket input or replay of a recorded stream via --web-dashboard-record/export artifacts) a point event whose 'metric' name has no preceding metric-definition event; name mismatches such as sending 'http_req_duration ' vs 'http_req_duration' or sub-metric names before their parent is registered.

Common situations: Custom tooling that replays k6 metric JSON into the dashboard and drops definition events; scripts where metric names are constructed dynamically and injected externally; in rare cases a genuine k6 ordering bug worth reporting.

Related errors


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

Appendix: source

Thrown at internal/dashboard/aggregate.go:246

	thresholds := make([]string, 0, len(tres))

	for _, res := range tres {
		thresholds = append(thresholds, res.String())
	}

	_, err = agg.registry.getOrNew(name, metricType, valueType, thresholds)

	return err
}

func (agg *aggregator) processPoint(data []byte) error {
	timestamp := gjson.GetBytes(data, "data.time").Time()
	name := gjson.GetBytes(data, "metric").String()

	metric := agg.registry.Get(name)
	if metric == nil {
		return fmt.Errorf("%w: %s", errUnknownMetric, name)
	}

	tags := agg.tagSetFrom(gjson.GetBytes(data, "data.tags"))

	sample := metrics.Sample{ //nolint:exhaustruct
		Time:  timestamp,
		Value: gjson.GetBytes(data, "data.value").Float(),
		TimeSeries: metrics.TimeSeries{ //nolint:exhaustruct
			Metric: metric,
			Tags:   tags,
		},
	}

	container := metrics.ConnectedSamples{ //nolint:exhaustruct
		Samples: []metrics.Sample{sample},
		Time:    sample.Time,
		Tags:    tags,
	}

View on GitHub (pinned to 01ffac6f24)