thanos-io/thanos · error

is 'web.enable-admin-api' flag enabled? got non-200…

Error message

is 'web.enable-admin-api' flag enabled? got non-200 response code: %v, response: %v

What it means

Client.Snapshot requires HTTP 200 from the admin snapshot API. Any other status triggers this error, which explicitly hints that Prometheus must be started with the --web.enable-admin-api flag. The status code and response body are included for diagnosis.

Solutions

  1. Restart Prometheus with --web.enable-admin-api to enable the snapshot endpoint
  2. Check the status code in the error: 404/405 means admin API disabled; 401/403 means auth required
  3. Confirm the URL path resolves to /api/v1/admin/tsdb/snapshot
  4. If admin API cannot be enabled, use an alternative backup mechanism (e.g. filesystem-level backup of the TSDB)

Example fix

// before
# prometheus started with defaults
./prometheus --config.file=prometheus.yml
// after
./prometheus --config.file=prometheus.yml --web.enable-admin-api
Defensive patterns

Strategy: validation

Validate before calling

// Check the flag is present before calling Snapshot
flags, err := client.ConfiguredFlags(ctx)
if err != nil { return err }
if _, ok := flags["web.enable-admin-api"]; !ok {
    return errors.New("prometheus must run with --web.enable-admin-api for snapshots")
}

Try / catch

dir, err := client.Snapshot(ctx, base, skipHead)
if err != nil && strings.Contains(err.Error(), "web.enable-admin-api") {
    return fmt.Errorf("enable admin API on prometheus: %w", err)
}

Prevention

When it happens

Trigger: The POST to /api/v1/admin/tsdb/snapshot returns non-200 — most commonly 405/404 because the admin API is disabled (default in Prometheus), or 401/403 due to auth, or 5xx server-side failure.

Common situations: Prometheus running with default flags where admin APIs are disabled — the by-far most common cause; reverse proxy blocking POST; permission-gated admin endpoints in secured clusters.

Related errors


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

Appendix: source

Thrown at pkg/promclient/promclient.go:368

	}
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")

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

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

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

	if resp.StatusCode != 200 {
		return "", errors.Errorf("is 'web.enable-admin-api' flag enabled? got non-200 response code: %v, response: %v", resp.StatusCode, string(b))
	}

	var d struct {
		Data struct {
			Name string `json:"name"`
		} `json:"data"`
	}
	if err := json.Unmarshal(b, &d); err != nil {
		return "", errors.Wrapf(err, "unmarshal response: %v", string(b))
	}

	return path.Join("snapshots", d.Data.Name), nil
}

type QueryOptions struct {
	DoNotAddThanosParams    bool
	Deduplicate             bool
	PartialResponseStrategy storepb.PartialResponseStrategy

View on GitHub (pinned to 35b8b99117)