thanos-io/thanos · error
bad response status from
Error message
bad response status %v from %q
What it means
After a successful alert POST, postAlerts checks the response status and requires a 2xx code. Any non-2xx (404 wrong path, 401 auth, 429 rate limit, 5xx) yields this error carrying the status line and target URL.
Solutions
- Read the status code in the message: 404 means wrong URL/path, 401/403 means configure credentials, 429 means reduce alert volume, 5xx means check Alertmanager logs.
- Verify the alertmanager URL includes the correct path (e.g. /api/v2/alerts is handled internally) and scheme.
- Configure the dispatcher's RoundTripper with the required auth (basic auth, TLS client certs).
- Check target Alertmanager logs/metrics for the corresponding request failure to see why it rejected the batch.
Example fix
// before urls: http://alertmanager:9093/alertmanager // after (correct base URL without extra path) urls: http://alertmanager:9093
Defensive patterns
Strategy: try-catch
Validate before calling
// verify endpoint before posting
resp, err := http.Head(strings.TrimSuffix(amURL, "/") + "/-/ready")
if err != nil || resp.StatusCode/100 != 2 {
return fmt.Errorf("alertmanager %s not healthy", amURL)
} Try / catch
if err := sender.postAlerts(ctx, alerts); err != nil {
if strings.Contains(err.Error(), "status 429") {
// back off and retry later
} else if strings.Contains(err.Error(), "status 404") {
// fix URL config; do not retry
}
return err
} Prevention
- Confirm the full alertmanager URL/path against the running version's API.
- Configure auth (basic auth, client certs) required by any proxy in front.
- Watch Alertmanager-side rate limits and alert ingestion limits.
- Check target Alertmanager logs for 5xx root causes.
When it happens
Trigger: The Alertmanager (or proxy in front of it) returned e.g. 404 because the URL path is wrong, 401/403 because auth is required, or 5xx because it failed to process the alert batch.
Common situations: Alertmanager behind a reverse proxy requiring basic auth or mTLS the sender doesn't provide; URL configured with wrong path prefix; target Alertmanager rejecting payloads due to limits; version mismatch between API groups.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- send request to
- got non-200 response code
- creating request to downstream URL
- error starting web server
- http.Error(w, err.Error(), http.StatusInternalServerError)
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/fd23dd66ced485a5.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/alert/alert.go:399
func (a *Alertmanager) postAlerts(ctx context.Context, u url.URL, r io.Reader) error {
req, err := http.NewRequest("POST", u.String(), r)
if err != nil {
return err
}
ctx, cancel := context.WithTimeout(ctx, a.timeout)
defer cancel()
req = req.WithContext(ctx)
req.Header.Set("Content-Type", contentTypeJSON)
resp, err := a.dispatcher.Do(req)
if err != nil {
return errors.Wrapf(err, "send request to %q", u.String())
}
defer runutil.ExhaustCloseWithLogOnErr(a.logger, resp.Body, "send one alert")
if resp.StatusCode/100 != 2 {
return errors.Errorf("bad response status %v from %q", resp.Status, u.String())
}
return nil
}
View on GitHub (pinned to 35b8b99117)