MCPcopy Index your code
hub / github.com/cortexproject/cortex / RegisterAlertmanager

Method RegisterAlertmanager

pkg/api/api.go:235–265  ·  view source on GitHub ↗

RegisterAlertmanager registers endpoints associated with the alertmanager. It will only serve endpoints using the legacy http-prefix if it is not run as a single binary.

(am *alertmanager.MultitenantAlertmanager, target, apiEnabled bool)

Source from the content-addressed store, hash-verified

233// RegisterAlertmanager registers endpoints associated with the alertmanager. It will only
234// serve endpoints using the legacy http-prefix if it is not run as a single binary.
235func (a *API) RegisterAlertmanager(am *alertmanager.MultitenantAlertmanager, target, apiEnabled bool) {
236 alertmanagerpb.RegisterAlertmanagerServer(a.server.GRPC, am)
237
238 a.indexPage.AddLink(SectionAdminEndpoints, "/multitenant_alertmanager/status", "Alertmanager Status")
239 a.indexPage.AddLink(SectionAdminEndpoints, "/multitenant_alertmanager/ring", "Alertmanager Ring Status")
240 // Ensure this route is registered before the prefixed AM route
241 a.RegisterRoute("/multitenant_alertmanager/status", am.GetStatusHandler(), false, "GET")
242 a.RegisterRoute("/multitenant_alertmanager/configs", http.HandlerFunc(am.ListAllConfigs), false, "GET")
243 a.RegisterRoute("/multitenant_alertmanager/ring", http.HandlerFunc(am.RingHandler), false, "GET", "POST")
244 a.RegisterRoute("/multitenant_alertmanager/delete_tenant_config", http.HandlerFunc(am.DeleteUserConfig), true, "POST")
245
246 // UI components lead to a large number of routes to support, utilize a path prefix instead
247 a.RegisterRoutesWithPrefix(a.cfg.AlertmanagerHTTPPrefix, am, true)
248 level.Debug(a.logger).Log("msg", "api: registering alertmanager", "path_prefix", a.cfg.AlertmanagerHTTPPrefix)
249
250 // MultiTenant Alertmanager Experimental API routes
251 if apiEnabled {
252 a.RegisterRoute("/api/v1/alerts", http.HandlerFunc(am.GetUserConfig), true, "GET")
253 a.RegisterRoute("/api/v1/alerts", http.HandlerFunc(am.SetUserConfig), true, "POST")
254 a.RegisterRoute("/api/v1/alerts", http.HandlerFunc(am.DeleteUserConfig), true, "DELETE")
255 }
256
257 // If the target is Alertmanager, enable the legacy behaviour. Otherwise only enable
258 // the component routed API.
259 if target {
260 a.RegisterRoute("/status", am.GetStatusHandler(), false, "GET")
261 // WARNING: If LegacyHTTPPrefix is an empty string, any other paths added after this point will be
262 // silently ignored by the HTTP service. Therefore, this must be the last route to be configured.
263 a.RegisterRoutesWithPrefix(a.cfg.LegacyHTTPPrefix, am, true)
264 }
265}
266
267// RegisterAPI registers the standard endpoints associated with a running Cortex.
268func (a *API) RegisterAPI(httpPathPrefix string, actualCfg any, defaultCfg any) {

Callers 1

initAlertManagerMethod · 0.80

Calls 6

RegisterRouteMethod · 0.95
AddLinkMethod · 0.80
GetStatusHandlerMethod · 0.80
LogMethod · 0.45

Tested by

no test coverage detected