diff --git a/CHANGELOG.md b/CHANGELOG.md index 151406c0ac..0e35ec9549 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,6 +99,7 @@ * [BUGFIX] Prevent panic at start if the http_prefix setting doesn't have a valid value. #3796 * [BUGFIX] Memberlist: fixed panic caused by race condition in `armon/go-metrics` used by memberlist client. #3724 * [BUGFIX] Querier: returning 422 (instead of 500) when query hits `max_chunks_per_query` limit with block storage. #3895 +* [BUGFIX] Alertmanager: Ensure that experimental `/api/v1/alerts` endpoints work when `-http.prefix` is empty. #3905 ## 1.7.0 diff --git a/pkg/api/api.go b/pkg/api/api.go index 989f7bca39..75177d83ce 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -172,19 +172,21 @@ func (a *API) RegisterAlertmanager(am *alertmanager.MultitenantAlertmanager, tar a.RegisterRoutesWithPrefix(a.cfg.AlertmanagerHTTPPrefix, am, true) level.Debug(a.logger).Log("msg", "api: registering alertmanager", "path_prefix", a.cfg.AlertmanagerHTTPPrefix) - // If the target is Alertmanager, enable the legacy behaviour. Otherwise only enable - // the component routed API. - if target { - a.RegisterRoute("/status", am.GetStatusHandler(), false, "GET") - a.RegisterRoutesWithPrefix(a.cfg.LegacyHTTPPrefix, am, true) - } - // MultiTenant Alertmanager Experimental API routes if apiEnabled { a.RegisterRoute("/api/v1/alerts", http.HandlerFunc(am.GetUserConfig), true, "GET") a.RegisterRoute("/api/v1/alerts", http.HandlerFunc(am.SetUserConfig), true, "POST") a.RegisterRoute("/api/v1/alerts", http.HandlerFunc(am.DeleteUserConfig), true, "DELETE") } + + // If the target is Alertmanager, enable the legacy behaviour. Otherwise only enable + // the component routed API. + if target { + a.RegisterRoute("/status", am.GetStatusHandler(), false, "GET") + // WARNING: If LegacyHTTPPrefix is an empty string, any other paths added after this point will be + // silently ignored by the HTTP service. Therefore, this must be the last route to be configured. + a.RegisterRoutesWithPrefix(a.cfg.LegacyHTTPPrefix, am, true) + } } // RegisterAPI registers the standard endpoints associated with a running Cortex.