Skip to content

Commit

Permalink
feat: pprof support config host (uber#5601)
Browse files Browse the repository at this point in the history
  • Loading branch information
zedongh authored Feb 16, 2024
1 parent 20ffcf4 commit 20598ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ type (
PProf struct {
// Port is the port on which the PProf will bind to
Port int `yaml:"port"`
// Host is the host on which the PProf will bind to, default to `localhost`
Host string `yaml:"host"`
}

// RPC contains the rpc config items
Expand Down
10 changes: 8 additions & 2 deletions common/config/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package config

import (
"fmt"
"net"
"net/http"
"sync/atomic"

Expand Down Expand Up @@ -65,10 +66,15 @@ func (initializer *PProfInitializerImpl) Start() error {
return nil
}

host := initializer.PProf.Host
if host == "" {
host = "localhost"
}

if atomic.CompareAndSwapInt32(&pprofStatus, pprofNotInitialized, pprofInitialized) {
go func() {
initializer.Logger.Info("PProf listen on ", tag.Port(port))
err := http.ListenAndServe(fmt.Sprintf("localhost:%d", port), nil)
initializer.Logger.Info("PProf listen on ", tag.Dynamic("pprof-host", host), tag.Port(port))
err := http.ListenAndServe(net.JoinHostPort(host, fmt.Sprint(port)), nil)
if err != nil {
initializer.Logger.Error("listen and serve err", tag.Error(err))
}
Expand Down

0 comments on commit 20598ca

Please sign in to comment.