Skip to content
New issue

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

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

Already on GitHub? # to your account

add pprof #24

Merged
merged 1 commit into from
Jun 11, 2024
Merged
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
7 changes: 7 additions & 0 deletions cmd/httpserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ var flags []cli.Flag = []cli.Flag{
Value: "your-project",
Usage: "add 'service' tag to logs",
},
&cli.BoolFlag{
Name: "pprof",
Value: false,
Usage: "enable pprof debug endpoint",
},
&cli.Int64Flag{
Name: "drain-seconds",
Value: 45,
Expand All @@ -63,6 +68,7 @@ func main() {
logDebug := cCtx.Bool("log-debug")
logUID := cCtx.Bool("log-uid")
logService := cCtx.String("log-service")
enablePprof := cCtx.Bool("pprof")
drainDuration := time.Duration(cCtx.Int64("drain-seconds")) * time.Second

log := common.SetupLogger(&common.LoggingOpts{
Expand All @@ -81,6 +87,7 @@ func main() {
ListenAddr: listenAddr,
MetricsAddr: metricsAddr,
Log: log,
EnablePprof: enablePprof,

DrainDuration: drainDuration,
GracefulShutdownDuration: 30 * time.Second,
Expand Down
7 changes: 7 additions & 0 deletions httpserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
"github.com/flashbots/go-template/metrics"
"github.com/flashbots/go-utils/httplogger"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"go.uber.org/atomic"
)

type HTTPServerConfig struct {
ListenAddr string
MetricsAddr string
EnablePprof bool
Log *slog.Logger

DrainDuration time.Duration
Expand Down Expand Up @@ -55,6 +57,11 @@ func New(cfg *HTTPServerConfig) (srv *Server, err error) {
mux.With(srv.httpLogger).Get("/drain", srv.handleDrain)
mux.With(srv.httpLogger).Get("/undrain", srv.handleUndrain)

if cfg.EnablePprof {
srv.log.Info("pprof API enabled")
mux.Mount("/debug", middleware.Profiler())
}

srv.srv = &http.Server{
Addr: cfg.ListenAddr,
Handler: mux,
Expand Down
Loading