From 24f56c770d09b31eeace1d2d2ff27baf611c1fa1 Mon Sep 17 00:00:00 2001 From: oleksandr Date: Thu, 15 May 2025 16:10:15 +0300 Subject: [PATCH] add pprof handlers --- endpoints/routing/handler.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/endpoints/routing/handler.go b/endpoints/routing/handler.go index c5141ef5..901d4658 100644 --- a/endpoints/routing/handler.go +++ b/endpoints/routing/handler.go @@ -2,6 +2,7 @@ package routing import ( "net/http" + "net/http/pprof" "time" "github.com/didip/tollbooth/v6" @@ -19,6 +20,7 @@ func NewAdminHandler(cfg config.Configuration, dataStore backends.Backend, appMe router := httprouter.New() addReadRoutes(cfg, dataStore, appMetrics, router) addWriteRoutes(cfg, dataStore, appMetrics, router) + addPProfRoutes(router) return router } @@ -45,6 +47,24 @@ func addWriteRoutes(cfg config.Configuration, dataStore backends.Backend, appMet router.POST("/cache", endpoints.NewPutHandler(dataStore, appMetrics, cfg.RequestLimits.MaxNumValues, cfg.RequestLimits.AllowSettingKeys, cfg.RequestLogging.RefererSamplingRate)) } +func addPProfRoutes(router *httprouter.Router) { + router.GET("/debug/pprof/*profile", func(w http.ResponseWriter, r *http.Request, params httprouter.Params) { + switch params.ByName("profile") { + case "/profile": + pprof.Profile(w, r) + case "/cmdline": + pprof.Cmdline(w, r) + case "/symbol": + pprof.Symbol(w, r) + case "/trace": + pprof.Trace(w, r) + default: + pprof.Index(w, r) + } + }) + +} + func handleCors(handler http.Handler) http.Handler { coresCfg := cors.New(cors.Options{AllowCredentials: true, AllowOriginFunc: func(origin string) bool { return true