github.com/argoproj/argo-cd/v3@v3.2.1/util/profile/profile.go (about) 1 package profile 2 3 import ( 4 "net/http" 5 "net/http/pprof" 6 "os" 7 8 "github.com/argoproj/argo-cd/v3/util/env" 9 ) 10 11 var enableProfilerFilePath = env.StringFromEnv("ARGOCD_ENABLE_PROFILER_FILE_PATH", "/home/argocd/params/profiler.enabled") 12 13 func wrapHandler(handler http.HandlerFunc) http.HandlerFunc { 14 return func(w http.ResponseWriter, r *http.Request) { 15 if data, err := os.ReadFile(enableProfilerFilePath); err == nil && string(data) == "true" { 16 handler.ServeHTTP(w, r) 17 } else { 18 http.Error(w, "Profiler endpoint is not enabled in 'argocd-cmd-params-cm' ConfigMap", http.StatusUnauthorized) 19 } 20 } 21 } 22 23 // RegisterProfiler adds pprof endpoints to mux. 24 func RegisterProfiler(mux *http.ServeMux) { 25 mux.HandleFunc("/debug/pprof/", wrapHandler(pprof.Index)) 26 mux.HandleFunc("/debug/pprof/cmdline", wrapHandler(pprof.Cmdline)) 27 mux.HandleFunc("/debug/pprof/profile", wrapHandler(pprof.Profile)) 28 mux.HandleFunc("/debug/pprof/symbol", wrapHandler(pprof.Symbol)) 29 mux.HandleFunc("/debug/pprof/trace", wrapHandler(pprof.Trace)) 30 }