grafana/k6 · error
create new HTTP request failed: %w
Error message
create new HTTP request failed: %w
What it means
Store failed to construct the outgoing HTTP request object for the Prometheus remote-write batch. http.NewRequestWithContext only errors when the URL is malformed or the method is invalid, so this fires at request-build time before any network I/O — the write client was initialized with a URL that cannot be parsed into a request.
Source
Thrown at internal/output/prometheusrw/remote/client.go:86
if err != nil {
return nil, err
}
wc.hc.Transport = tripper
}
return wc, nil
}
// Store sends a batch of samples to the HTTP endpoint,
// the request is the proto marshaled and encoded.
func (c *WriteClient) Store(ctx context.Context, series []*prompb.TimeSeries) error {
b, err := newWriteRequestBody(series)
if err != nil {
return err
}
req, err := http.NewRequestWithContext(
ctx, http.MethodPost, c.url.String(), bytes.NewReader(b))
if err != nil {
return fmt.Errorf("create new HTTP request failed: %w", err)
}
if c.cfg.BasicAuth != nil {
req.SetBasicAuth(c.cfg.BasicAuth.Username, c.cfg.BasicAuth.Password)
}
if len(c.cfg.Headers) > 0 {
req.Header = c.cfg.Headers.Clone()
}
req.Header.Set("User-Agent", "k6-prometheus-rw-output")
// They are mostly defined by the specs
req.Header.Set("Content-Encoding", "snappy")
req.Header.Set("Content-Type", "application/x-protobuf")
req.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.0")
resp, err := c.hc.Do(req) //nolint:gosec
if err != nil {View on GitHub (pinned to 01ffac6f24)
Solutions
- Fix the --out prometheus-rw=url value to a valid URL, e.g. http://prometheus:9090/api/v1/write
- Check for control characters or whitespace in the URL
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/output/prometheusrw/remote/client.go:86 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/2a9f4ac881b747f0.
Report an issue: GitHub.