Backport of chore: pprof build updates into release/0.21.x (#6424)

* backport of commit ef166d3bc1

* backport of commit 05d885efc6

---------

Co-authored-by: Michael Li <michael.li@hashicorp.com>
backport/aditya2548-update-cve-changelog-0.21/adequately-careful-gobbler
hc-github-team-secure-boundary 1 week ago committed by GitHub
parent 574d724331
commit fbab94d220
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -68,6 +68,7 @@ install-no-plugins: install
.PHONY: build-pprof
build-pprof: BUILD_TAGS+=pprof
build-pprof: BUILD_TAGS+=ui
build-pprof:
@echo "==> Building Boundary with memory pprof enabled"
@CGO_ENABLED=$(CGO_ENABLED) BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/build.sh'"

@ -10,18 +10,29 @@ import (
"context"
"errors"
"net/http"
"net/http/pprof"
"github.com/hashicorp/boundary/internal/event"
_ "net/http/pprof"
)
func StartPprof(ctx context.Context) {
const op = "base.StartPprof"
go func() {
const addr = "localhost:6060"
mux := http.NewServeMux()
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
mux.Handle("/debug/pprof/block", pprof.Handler("block"))
mux.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
mux.Handle("/debug/pprof/heap", pprof.Handler("heap"))
mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
mux.Handle("/debug/pprof/mutex", pprof.Handler("mutex"))
mux.Handle("/debug/pprof/allocs", pprof.Handler("allocs"))
event.WriteSysEvent(ctx, op, "starting pprof HTTP server", "addr", addr)
if err := http.ListenAndServe(addr, nil); err != nil && !errors.Is(err, http.ErrServerClosed) {
if err := http.ListenAndServe(addr, mux); err != nil && !errors.Is(err, http.ErrServerClosed) {
event.WriteSysEvent(ctx, op, "failed to serve pprof HTTP server", "error", err.Error())
}
}()

Loading…
Cancel
Save