mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: crenshaw-dev <[email protected]>
31 lines
1.0 KiB
Go
31 lines
1.0 KiB
Go
package profile
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/pprof"
|
|
"os"
|
|
|
|
"github.com/argoproj/argo-cd/v3/util/env"
|
|
)
|
|
|
|
var enableProfilerFilePath = env.StringFromEnv("ARGOCD_ENABLE_PROFILER_FILE_PATH", "/home/argocd/params/profiler.enabled")
|
|
|
|
func wrapHandler(handler http.HandlerFunc) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if data, err := os.ReadFile(enableProfilerFilePath); err == nil && string(data) == "true" {
|
|
handler.ServeHTTP(w, r)
|
|
} else {
|
|
http.Error(w, "Profiler endpoint is not enabled in 'argocd-cmd-params-cm' ConfigMap", http.StatusUnauthorized)
|
|
}
|
|
}
|
|
}
|
|
|
|
// RegisterProfiler adds pprof endpoints to mux.
|
|
func RegisterProfiler(mux *http.ServeMux) {
|
|
mux.HandleFunc("/debug/pprof/", wrapHandler(pprof.Index))
|
|
mux.HandleFunc("/debug/pprof/cmdline", wrapHandler(pprof.Cmdline))
|
|
mux.HandleFunc("/debug/pprof/profile", wrapHandler(pprof.Profile))
|
|
mux.HandleFunc("/debug/pprof/symbol", wrapHandler(pprof.Symbol))
|
|
mux.HandleFunc("/debug/pprof/trace", wrapHandler(pprof.Trace))
|
|
}
|