grafana/k6 · error

failed to initialize the http metrics flush client: %w

Error message

failed to initialize the http metrics flush client: %w

What it means

During Output.Start, initialization of the HTTP client used to flush metrics to the cloud failed. In the switch that decides between injected (provisioning mode) client/URL and the derived legacy URL, neither a usable cloud client nor a valid configuration could be established, so the flusher cannot be created.

Source

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

	// 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()),
		maxSeriesInBatch:           int(o.config.MaxTimeSeriesInBatch.Int64),
		// TODO: when the migration from v1 is over
		// change the default of cloudapi.MetricPushConcurrency to use GOMAXPROCS(0)
		batchPushConcurrency: int(o.config.MetricPushConcurrency.Int64),
	}

	flushCtx, cancelFlush := context.WithCancel(context.Background())
	o.cancelFlush = cancelFlush

	o.runPeriodicFlush(flushCtx)

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Inspect the wrapped error for the concrete cause
  2. Verify cloud output configuration (host, token, run ID)
  3. Ensure the cloud client was properly initialized before starting the output
Defensive patterns

Strategy: try-catch

When it happens

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