thanos-io/thanos · error

create request

Error message

create request

What it means

ConfiguredFlags builds a GET request to <base>/api/v1/status/flags via http.NewRequest; this error wraps any failure of request construction, such as a malformed URL produced from the base URL. It means the HTTP request could not even be created, before any network I/O.

Solutions

  1. Validate the base URL string with url.Parse before passing it to the client
  2. Fix the --prometheus.url / configured base URL (scheme://host:port, no stray characters)
  3. Trim whitespace/newlines from URL values coming from config files or env vars
  4. Log u.String() to see the exact URL being built

Example fix

// before
base := os.Getenv("PROM_URL") // "http://prom:9090\n"
client.ConfiguredFlags(ctx, mustParse(base))
// after
u, err := url.Parse(strings.TrimSpace(os.Getenv("PROM_URL")))
if err != nil { return err }
if u.Scheme == "" || u.Host == "" { return errors.New("invalid prometheus url") }
client.ConfiguredFlags(ctx, u)
Defensive patterns

Strategy: validation

Validate before calling

func validBaseURL(raw string) (*url.URL, error) {
    u, err := url.Parse(strings.TrimSpace(raw))
    if err != nil { return nil, err }
    if u.Scheme == "" || u.Host == "" {
        return nil, fmt.Errorf("base URL must include scheme and host: %q", raw)
    }
    return u, nil
}

Try / catch

flags, err := client.ConfiguredFlags(ctx, u)
if err != nil {
    if strings.Contains(err.Error(), "create request") {
        return fmt.Errorf("invalid prometheus URL %q: %w", u, err)
    }
    return err
}

Prevention

When it happens

Trigger: http.NewRequest fails — practically only when the composed URL (base URL joined with /api/v1/status/flags) is invalid, e.g. base URL containing control characters or an unparseable scheme/host. Called by an anonymous caller reading Prometheus flags.

Common situations: A base URL read from config/environment contains whitespace, newlines, or invalid characters; empty or malformed --prometheus.url flag value; templating produced a bad URL.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/1dcfbc79424c2f90. Report an issue: GitHub.

Appendix: source

Thrown at pkg/promclient/promclient.go:298

	}

	boolean, err := strconv.ParseBool(s)
	if err != nil {
		return err
	}
	*m = modelBool(boolean)
	return nil
}

// ConfiguredFlags returns configured flags from /api/v1/status/flags Prometheus endpoint.
// Added to Prometheus from v2.2.
func (c *Client) ConfiguredFlags(ctx context.Context, base *url.URL) (Flags, error) {
	u := *base
	u.Path = path.Join(u.Path, "/api/v1/status/flags")

	req, err := http.NewRequest(http.MethodGet, u.String(), nil)
	if err != nil {
		return Flags{}, errors.Wrap(err, "create request")
	}

	span, ctx := tracing.StartSpan(ctx, "/prom_flags HTTP[client]")
	defer span.Finish()

	resp, err := c.Do(req.WithContext(ctx))
	if err != nil {
		return Flags{}, errors.Wrapf(err, "request config against %s", u.String())
	}
	defer runutil.ExhaustCloseWithLogOnErr(c.logger, resp.Body, "query body")

	b, err := io.ReadAll(resp.Body)
	if err != nil {
		return Flags{}, errors.New("failed to read body")
	}

	switch resp.StatusCode {
	case 404:

View on GitHub (pinned to 35b8b99117)