MCPcopy Create free account
hub / github.com/prometheus/prometheus / Register

Method Register

web/api/v1/api.go:401–501  ·  view source on GitHub ↗

Register the API's endpoints in the given router.

(r *route.Router)

Source from the content-addressed store, hash-verified

399
400// Register the API's endpoints in the given router.
401func (api *API) Register(r *route.Router) {
402 wrap := func(f apiFunc) http.HandlerFunc {
403 hf := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
404 httputil.SetCORS(w, api.CORSOrigin, r)
405 result := setUnavailStatusOnTSDBNotReady(f(r))
406 if result.finalizer != nil {
407 defer result.finalizer()
408 }
409 if result.err != nil {
410 api.respondError(w, result.err, result.data)
411 return
412 }
413
414 if result.data != nil {
415 api.respond(w, r, result.data, result.warnings, r.FormValue("query"))
416 return
417 }
418 w.WriteHeader(http.StatusNoContent)
419 })
420 return api.ready(httputil.CompressionHandler{
421 Handler: api.openAPIBuilder.WrapHandler(hf),
422 }.ServeHTTP)
423 }
424
425 wrapAgent := func(f apiFunc) http.HandlerFunc {
426 return wrap(func(r *http.Request) apiFuncResult {
427 if api.isAgent {
428 return apiFuncResult{nil, &apiError{errorExec, errors.New("unavailable with Prometheus Agent")}, nil, nil}
429 }
430 return f(r)
431 })
432 }
433
434 r.Options("/*path", wrap(api.options))
435
436 r.Get("/query", wrapAgent(api.query))
437 r.Post("/query", wrapAgent(api.query))
438 r.Get("/query_range", wrapAgent(api.queryRange))
439 r.Post("/query_range", wrapAgent(api.queryRange))
440 r.Get("/query_exemplars", wrapAgent(api.queryExemplars))
441 r.Post("/query_exemplars", wrapAgent(api.queryExemplars))
442
443 r.Get("/format_query", wrapAgent(api.formatQuery))
444 r.Post("/format_query", wrapAgent(api.formatQuery))
445
446 r.Get("/parse_query", wrapAgent(api.parseQuery))
447 r.Post("/parse_query", wrapAgent(api.parseQuery))
448
449 r.Get("/labels", wrapAgent(api.labelNames))
450 r.Post("/labels", wrapAgent(api.labelNames))
451 r.Get("/label/:name/values", wrapAgent(api.labelValues))
452
453 r.Get("/series", wrapAgent(api.series))
454 r.Post("/series", wrapAgent(api.series))
455
456 r.Get("/scrape_pools", wrap(api.scrapePools))
457 r.Get("/targets", wrap(api.targets))
458 r.Get("/targets/metadata", wrap(api.targetMetadata))

Callers 3

newTestAPIFunction · 0.95
createPrometheusAPIFunction · 0.95
TestOptionsMethodFunction · 0.95

Calls 10

respondErrorMethod · 0.95
respondMethod · 0.95
SetCORSFunction · 0.92
fFunction · 0.85
WriteHeaderMethod · 0.80
readyMethod · 0.80
WrapHandlerMethod · 0.80
GetMethod · 0.65
PutMethod · 0.65

Tested by 3

newTestAPIFunction · 0.76
createPrometheusAPIFunction · 0.76
TestOptionsMethodFunction · 0.76