grafana/k6 · error

failed to derive the metrics push URL: %w

Error message

failed to derive the metrics push URL: %w

What it means

During Output.Start, deriveMetricsURL could not build the metrics push URL from the cloud client's base URL and the test run ID. This happens while wiring up the legacy /v2/metrics/<testRunID> endpoint when no explicit metrics client/URL was injected; the wrapped error explains the malformed base URL or run ID.

Source

Thrown at output/cloud/expv2/output.go:136

	o.collector, err = newCollector(
		o.config.AggregationPeriod.TimeDuration(),
		o.config.AggregationWaitPeriod.TimeDuration())
	if err != nil {
		return fmt.Errorf("failed to initialize the samples collector: %w", err)
	}

	// The metrics client always pushes to an explicit URL. In provisioning
	// mode both the HTTP client and URL are injected via the setters;
	// otherwise we derive the legacy /v2/metrics/<testRunID> URL from the
	// cloud client. The two must be set together — one without the other is
	// a misconfiguration rather than a silent fallback.
	switch {
	case o.metricsHTTPClient != nil && o.metricsURL != "":
		// Both injected (provisioning mode); use as-is.
	case o.metricsHTTPClient == nil && o.metricsURL == "":
		o.metricsURL, err = deriveMetricsURL(o.cloudClient.BaseURL(), o.testRunID)
		if err != nil {
			return fmt.Errorf("failed to derive the metrics push URL: %w", err)
		}
		o.metricsHTTPClient = o.cloudClient
	default:
		return errors.New("metrics push client misconfigured: " +
			"metricsHTTPClient and metricsURL must be set together")
	}

	mc, err := newMetricsClientWithURL(o.metricsHTTPClient, o.metricsURL)
	if err != nil {
		return fmt.Errorf("failed to initialize the http metrics flush client: %w", err)
	}
	o.flushing = &metricsFlusher{
		testRunID:                  o.testRunID,
		bq:                         &o.collector.bq,
		client:                     mc,
		logger:                     o.logger,
		discardedLabels:            make(map[string]struct{}),
		aggregationPeriodInSeconds: uint32(o.config.AggregationPeriod.TimeDuration().Seconds()),

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Verify K6_CLOUD_HOST / cloud API base URL is a valid, complete URL
  2. Ensure the cloud test run was created successfully and a test run ID exists
  3. Check for typos in cloud-related environment variables
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at output/cloud/expv2/output.go:136 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/dd873892bc22b61b. Report an issue: GitHub.