(s *server, r *http.Request, w http.ResponseWriter, rh RequestHandler)
| 363 | } |
| 364 | |
| 365 | func builtinRoutesHandler(s *server, r *http.Request, w http.ResponseWriter, rh RequestHandler) bool { |
| 366 | |
| 367 | h := w.Header() |
| 368 | |
| 369 | path := r.URL.Path |
| 370 | if strings.HasSuffix(path, "/favicon.ico") { |
| 371 | w.Header().Set("Cache-Control", "max-age=3600") |
| 372 | faviconRequests.Inc() |
| 373 | w.Write(faviconData) |
| 374 | return true |
| 375 | } |
| 376 | |
| 377 | switch r.URL.Path { |
| 378 | case "/health": |
| 379 | h.Set("Content-Type", "text/plain; charset=utf-8") |
| 380 | deadline := s.shutdownDelayDeadline.Load() |
| 381 | if deadline <= 0 { |
| 382 | w.Write([]byte("OK")) |
| 383 | return true |
| 384 | } |
| 385 | // Return non-OK response during grace period before shutting down the server. |
| 386 | // Load balancers must notify these responses and re-route new requests to other servers. |
| 387 | // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/463 . |
| 388 | d := time.Until(time.Unix(0, deadline)) |
| 389 | if d < 0 { |
| 390 | d = 0 |
| 391 | } |
| 392 | errMsg := fmt.Sprintf("The server is in delayed shutdown mode, which will end in %.3fs", d.Seconds()) |
| 393 | http.Error(w, errMsg, http.StatusServiceUnavailable) |
| 394 | return true |
| 395 | case "/ping": |
| 396 | // This is needed for compatibility with InfluxDB agents. |
| 397 | // See https://docs.influxdata.com/influxdb/v1.7/tools/api/#ping-http-endpoint |
| 398 | status := http.StatusNoContent |
| 399 | if verbose := r.FormValue("verbose"); verbose == "true" { |
| 400 | status = http.StatusOK |
| 401 | } |
| 402 | w.WriteHeader(status) |
| 403 | return true |
| 404 | case "/metrics": |
| 405 | metricsRequests.Inc() |
| 406 | if !CheckAuthFlag(w, r, metricsAuthKey) { |
| 407 | return true |
| 408 | } |
| 409 | startTime := time.Now() |
| 410 | h.Set("Content-Type", "text/plain; charset=utf-8") |
| 411 | appmetrics.WritePrometheusMetrics(w) |
| 412 | metricsHandlerDuration.UpdateDuration(startTime) |
| 413 | return true |
| 414 | case "/flags": |
| 415 | if !CheckAuthFlag(w, r, flagsAuthKey) { |
| 416 | return true |
| 417 | } |
| 418 | h.Set("Content-Type", "text/plain; charset=utf-8") |
| 419 | flagutil.WriteFlags(w) |
| 420 | return true |
| 421 | case "/-/healthy": |
| 422 | // This is needed for Prometheus compatibility |
searching dependent graphs…