2
0

apiutil.go 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. package apiutil
  2. import (
  3. "net/http"
  4. "net/http/pprof"
  5. "github.com/julienschmidt/httprouter"
  6. "github.com/opencost/opencost/core/pkg/env"
  7. )
  8. func ApplyContainerDiagnosticEndpoints(router *httprouter.Router) {
  9. router.HandlerFunc("GET", "/healthz", healthz)
  10. router.GET("/logs/level", GetLogLevel)
  11. router.POST("/logs/level", SetLogLevel)
  12. if env.IsPProfEnabled() {
  13. router.HandlerFunc(http.MethodGet, "/debug/pprof/", pprof.Index)
  14. router.HandlerFunc(http.MethodGet, "/debug/pprof/cmdline", pprof.Cmdline)
  15. router.HandlerFunc(http.MethodGet, "/debug/pprof/profile", pprof.Profile)
  16. router.HandlerFunc(http.MethodGet, "/debug/pprof/symbol", pprof.Symbol)
  17. router.HandlerFunc(http.MethodGet, "/debug/pprof/trace", pprof.Trace)
  18. router.Handler(http.MethodGet, "/debug/pprof/goroutine", pprof.Handler("goroutine"))
  19. router.Handler(http.MethodGet, "/debug/pprof/heap", pprof.Handler("heap"))
  20. }
  21. }
  22. func healthz(w http.ResponseWriter, _ *http.Request) {
  23. w.WriteHeader(200)
  24. w.Header().Set("Content-Length", "0")
  25. w.Header().Set("Content-Type", "text/plain")
  26. }