Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable pprof #92

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.tools
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export TOOLS_BUILDNUMBER=20240829.1
export TOOLS_BUILDNUMBER=20241108.3
23 changes: 23 additions & 0 deletions httpserver/pprofserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package httpserver

import (
"net/http"
"net/http/pprof"
_ "net/http/pprof"

"github.com/datatrails/go-datatrails-common/environment"
)

func NewPPROF(log Logger, name string) *Server {
port, err := environment.GetRequired("PPROF_PORT")
if err != nil {
return nil
}
h := http.NewServeMux()
h.HandleFunc("/debug/pprof/", pprof.Index)
h.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
h.HandleFunc("/debug/pprof/profile", pprof.Profile)
h.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
h.HandleFunc("/debug/pprof/trace", pprof.Trace)
return New(log, name, port, h)
}
11 changes: 11 additions & 0 deletions startup/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ func WithListeners(listeners ...Listener) ListenersOption {
}
}

// WithOptionalListeners add multiple listeners. Nil listeners are ignored.
func WithOptionalListeners(listeners ...Listener) ListenersOption {
return func(l *Listeners) {
for _, listener := range listeners {
if listener != nil {
l.listeners = append(l.listeners, listener)
}
}
}
}

func NewListeners(log Logger, name string, opts ...ListenersOption) Listeners {
l := Listeners{name: strings.ToLower(name)}
for _, opt := range opts {
Expand Down
Loading