Skip to content

Commit

Permalink
Merge pull request #313 from Shopify/enable-pprof-conditionally
Browse files Browse the repository at this point in the history
Enable pprof conditionally
  • Loading branch information
shuhaowu authored Oct 6, 2021
2 parents 89ae875 + c8039cf commit a336eb2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (c *DatabaseConfig) MySQLConfig() (*mysql.Config, error) {
return nil, fmt.Errorf("failed to build TLS config: %v", err)
}

cfgName := fmt.Sprintf("%s@%s:%s", c.User, c.Host, c.Port)
cfgName := fmt.Sprintf("%s@%s:%d", c.User, c.Host, c.Port)

err = mysql.RegisterTLSConfig(cfgName, tlsConfig)
if err != nil {
Expand Down Expand Up @@ -764,6 +764,9 @@ type Config struct {
// The ghostferry target user should have SUPER permissions to actually write to the target DB,
// if ghostferry is ran with AllowSuperUserOnReadOnly = true and the target DB is set to read_only.
AllowSuperUserOnReadOnly bool

// If true, net/http/pprof will be enabled on port 6060.
EnablePProf bool
}

func (c *Config) ValidateConfig() error {
Expand Down
11 changes: 11 additions & 0 deletions ferry.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (

sql "github.com/Shopify/ghostferry/sqlwrapper"

_ "net/http/pprof"

siddontangmysql "github.com/go-mysql-org/go-mysql/mysql"
"github.com/go-sql-driver/mysql"
siddontanglog "github.com/siddontang/go-log/log"
Expand Down Expand Up @@ -611,6 +613,15 @@ func (f *Ferry) Run() {
f.logger.Info("starting ferry run")
f.OverallState.Store(StateCopying)

if f.Config.EnablePProf {
go func() {
err := http.ListenAndServe("localhost:6060", nil)
if err != nil {
f.logger.WithError(err).Warn("pprof server finished")
}
}()
}

ctx, shutdown := context.WithCancel(context.Background())

handleError := func(name string, err error) {
Expand Down

0 comments on commit a336eb2

Please sign in to comment.