Register the API's endpoints in the given router.
(r *route.Router)
| 399 | |
| 400 | // Register the API's endpoints in the given router. |
| 401 | func (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)) |