Skip to content

Commit

Permalink
register pprof endpoints for allocator (#1408)
Browse files Browse the repository at this point in the history
* register pprof endpoints for allocator

* changelog entry

* full sentence for changelog
  • Loading branch information
seankhliao authored Feb 2, 2023
1 parent 05b871d commit 195744f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .chloggen/allocator-pprof.yaml
Original file line number Diff line number Diff line change
@@ -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:
10 changes: 10 additions & 0 deletions cmd/otel-allocator/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/http/pprof"
"net/url"
"time"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
}

0 comments on commit 195744f

Please sign in to comment.