Skip to content

Commit

Permalink
runtime: Add pprof.GetHandlers to help setup the metrics server
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <[email protected]>
  • Loading branch information
stefanprodan committed Nov 20, 2023
1 parent 768085d commit 09ba5d8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions runtime/pprof/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package pprof
import (
"net/http"
"net/http/pprof"
"runtime"
)

// HTTPPrefixPProf is the prefix appended to all Endpoints.
Expand All @@ -37,3 +38,25 @@ var Endpoints = map[string]http.Handler{
HTTPPrefixPProf + "/block": pprof.Handler("block"),
HTTPPrefixPProf + "/mutex": pprof.Handler("mutex"),
}

// GetHandlers returns the pprof endpoints for the mgr metrics server.
//
// The func can be used in the main.go file of your controller, when initializing the manager:
//
// func main() {
// mgrConfig := ctrl.Options{
// Metrics: metricsserver.Options{
// BindAddress: metricsAddr,
// ExtraHandlers: pprof.GetHandlers(),
// },
// }
// }
func GetHandlers() map[string]http.Handler {
// Only set the fraction if there is no existing setting
if runtime.SetMutexProfileFraction(-1) == 0 {
// Default to report 1 out of 5 mutex events, on average
runtime.SetMutexProfileFraction(5)
}

return Endpoints
}

0 comments on commit 09ba5d8

Please sign in to comment.