MCPcopy Index your code
hub / github.com/VictoriaMetrics/VictoriaLogs / builtinRoutesHandler

Function builtinRoutesHandler

lib/httpserver/httpserver.go:365–451  ·  view source on GitHub ↗
(s *server, r *http.Request, w http.ResponseWriter, rh RequestHandler)

Source from the content-addressed store, hash-verified

363}
364
365func 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

Callers 2

TestHandlerWrapperFunction · 0.85
serveWithListenerFunction · 0.85

Calls 13

WritePrometheusMetricsFunction · 0.92
WriteFlagsFunction · 0.92
CheckAuthFlagFunction · 0.85
pprofHandlerFunction · 0.85
isProtectedByAuthFlagFunction · 0.85
CheckBasicAuthFunction · 0.85
HeaderMethod · 0.80
LoadMethod · 0.80
WriteMethod · 0.65
rhFunction · 0.50
SetMethod · 0.45
ErrorMethod · 0.45

Tested by 1

TestHandlerWrapperFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…