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

fix(cmd): add pprof as default in http server #1511

Merged
merged 1 commit into from
Sep 28, 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
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
Loading