diff --git a/pkg/app/api.go b/pkg/app/api.go index 264829ba..4b1a8c64 100644 --- a/pkg/app/api.go +++ b/pkg/app/api.go @@ -15,6 +15,7 @@ import ( "fmt" "io" "net/http" + "net/http/pprof" "path/filepath" "sort" "strings" @@ -49,6 +50,21 @@ func (a *App) newAPIServer() (*http.Server, error) { } } + if a.Config.APIServer.EnableProfiling { + a.router.HandleFunc("/debug/pprof/", pprof.Index) + a.router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + a.router.HandleFunc("/debug/pprof/profile", pprof.Profile) + a.router.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + a.router.Path("/debug/pprof/symbol").Methods("POST", "GET").HandlerFunc(pprof.Symbol) + a.router.HandleFunc("/debug/pprof/trace", pprof.Trace) + a.router.Handle("/debug/pprof/heap", pprof.Handler("heap")) + a.router.Handle("/debug/pprof/mutex", pprof.Handler("mutex")) + a.router.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate")) + a.router.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine")) + a.router.Handle("/debug/pprof/allocs", pprof.Handler("allocs")) + a.router.Handle("/debug/pprof/block", pprof.Handler("block")) + } + if a.Config.APIServer.EnableMetrics { a.router.Handle("/metrics", promhttp.HandlerFor(a.reg, promhttp.HandlerOpts{})) a.reg.MustRegister(collectors.NewGoCollector()) diff --git a/pkg/config/api_server.go b/pkg/config/api_server.go index ec92ff4e..b41914eb 100644 --- a/pkg/config/api_server.go +++ b/pkg/config/api_server.go @@ -27,6 +27,7 @@ type APIServer struct { Timeout time.Duration `mapstructure:"timeout,omitempty" json:"timeout,omitempty"` TLS *types.TLSConfig `mapstructure:"tls,omitempty" json:"tls,omitempty"` EnableMetrics bool `mapstructure:"enable-metrics,omitempty" json:"enable-metrics,omitempty"` + EnableProfiling bool `mapstructure:"enable-profiling,omitempty" json:"enable-profiling,omitempty"` Debug bool `mapstructure:"debug,omitempty" json:"debug,omitempty"` HealthzDisableLogging bool `mapstructure:"healthz-disable-logging,omitempty" json:"healthz-disable-logging,omitempty"` } @@ -53,6 +54,7 @@ func (c *Config) GetAPIServer() error { } c.APIServer.EnableMetrics = os.ExpandEnv(c.FileConfig.GetString("api-server/enable-metrics")) == trueString + c.APIServer.EnableProfiling = os.ExpandEnv(c.FileConfig.GetString("api-server/enable-profiling")) == trueString c.APIServer.Debug = os.ExpandEnv(c.FileConfig.GetString("api-server/debug")) == trueString c.APIServer.HealthzDisableLogging = os.ExpandEnv(c.FileConfig.GetString("api-server/healthz-disable-logging")) == trueString c.setAPIServerDefaults()