Skip to content

Commit

Permalink
fix(cmd): add pprof as default in http server (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ja7ad authored Sep 28, 2024
1 parent 36c88b3 commit 9de9f41
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
18 changes: 0 additions & 18 deletions cmd/daemon/start.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package main

import (
"net/http"
_ "net/http/pprof" // #nosec
"os"
"path/filepath"
"time"

"github.com/gofrs/flock"
"github.com/pactus-project/pactus/cmd"
Expand All @@ -27,9 +24,6 @@ func buildStartCmd(parentCmd *cobra.Command) {
passwordOpt := startCmd.Flags().StringP("password", "p", "",
"the wallet password")

pprofOpt := startCmd.Flags().String("pprof", "",
"pprof server address (for debugging)")

startCmd.Run = func(_ *cobra.Command, _ []string) {
workingDir, _ := filepath.Abs(*workingDirOpt)
// change working directory
Expand All @@ -49,18 +43,6 @@ func buildStartCmd(parentCmd *cobra.Command) {
return
}

if *pprofOpt != "" {
cmd.PrintWarnMsgf("Starting Debug pprof server on: http://%s/debug/pprof/", *pprofOpt)
server := &http.Server{
Addr: *pprofOpt,
ReadHeaderTimeout: 3 * time.Second,
}
go func() {
err := server.ListenAndServe()
cmd.FatalErrorCheck(err)
}()
}

passwordFetcher := func(wlt *wallet.Wallet) (string, bool) {
if !wlt.IsEncrypted() {
return "", true
Expand Down
4 changes: 4 additions & 0 deletions www/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package http
import (
"bytes"
"context"
"expvar"
"fmt"
"io"
"net"
"net/http"
"net/http/pprof"
"strings"
"time"

Expand Down Expand Up @@ -85,6 +87,8 @@ func (s *Server) StartServer(grpcServer string) error {
s.router.HandleFunc("/validator/address/{address}", s.GetValidatorHandler)
s.router.HandleFunc("/validator/number/{number}", s.GetValidatorByNumberHandler)
s.router.HandleFunc("/metrics/prometheus", promhttp.Handler().ServeHTTP)
s.router.HandleFunc("/debug/pprof/", pprof.Index)
s.router.Handle("/debug/vars", expvar.Handler())

if s.enableAuth {
http.Handle("/", handlers.RecoveryHandler()(basicAuth(s.router)))
Expand Down

0 comments on commit 9de9f41

Please sign in to comment.