diff --git a/.chloggen/allocator-pprof.yaml b/.chloggen/allocator-pprof.yaml new file mode 100755 index 0000000000..0f389d5b37 --- /dev/null +++ b/.chloggen/allocator-pprof.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action) +component: target allocator + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Register pprof endpoints under `/debug/pprof`. + +# One or more tracking issues related to the change +issues: [188] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/cmd/otel-allocator/server/server.go b/cmd/otel-allocator/server/server.go index 8bd25a8ead..a1aee2f453 100644 --- a/cmd/otel-allocator/server/server.go +++ b/cmd/otel-allocator/server/server.go @@ -19,6 +19,7 @@ import ( "encoding/json" "fmt" "net/http" + "net/http/pprof" "net/url" "time" @@ -78,6 +79,7 @@ func NewServer(log logr.Logger, allocator allocation.Allocator, discoveryManager router.GET("/jobs", s.JobHandler) router.GET("/jobs/:job_id/targets", s.TargetsHandler) router.GET("/metrics", gin.WrapH(promhttp.Handler())) + registerPprof(router.Group("/debug/pprof/")) s.server = &http.Server{Addr: *listenAddr, Handler: router, ReadHeaderTimeout: 90 * time.Second} return s @@ -192,3 +194,11 @@ func GetAllTargetsByJob(allocator allocation.Allocator, job string) map[string]c } return displayData } + +func registerPprof(g *gin.RouterGroup) { + g.GET("/", gin.WrapF(pprof.Index)) + g.GET("/cmdline", gin.WrapF(pprof.Cmdline)) + g.GET("/profile", gin.WrapF(pprof.Profile)) + g.GET("/symbol", gin.WrapF(pprof.Symbol)) + g.GET("/trace", gin.WrapF(pprof.Trace)) +}