From 62e7f9e5401670aff6d2a5fddc8e0e3968cfda98 Mon Sep 17 00:00:00 2001 From: peter <1674920+peterbitfly@users.noreply.github.com> Date: Mon, 9 Jan 2023 06:39:14 +0100 Subject: [PATCH] add optional pprof endpoint to FDU for profiling --- cmd/frontend-data-updater/main.go | 18 ++++++++++-------- types/config.go | 4 ++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/cmd/frontend-data-updater/main.go b/cmd/frontend-data-updater/main.go index 4149da4249..3a91ac5651 100644 --- a/cmd/frontend-data-updater/main.go +++ b/cmd/frontend-data-updater/main.go @@ -12,6 +12,9 @@ import ( _ "github.com/jackc/pgx/v4/stdlib" "github.com/sirupsen/logrus" + + "net/http" + _ "net/http/pprof" ) func main() { @@ -26,14 +29,13 @@ func main() { utils.Config = cfg logrus.WithField("config", *configPath).WithField("version", version.Version).WithField("chainName", utils.Config.Chain.Config.ConfigName).Printf("starting") - // ctx, done := context.WithTimeout(context.Background(), time.Second*30) - // defer done() - // db.MustInitBigtableAdmin(ctx, cfg.Bigtable.Project, cfg.Bigtable.Instance) - - // err = db.BigAdminClient.SetupBigtableCache() - // if err != nil { - // logrus.Fatalf("error setting up bigtable cache err: %v", err) - // } + // enable pprof endpoint if requested + if utils.Config.Pprof.Enabled { + go func() { + logrus.Infof("starting pprof http server on port %s", utils.Config.Pprof.Port) + logrus.Info(http.ListenAndServe(fmt.Sprintf("localhost:%s", utils.Config.Pprof.Port), nil)) + }() + } _, err = db.InitBigtable(cfg.Bigtable.Project, cfg.Bigtable.Instance, fmt.Sprintf("%d", utils.Config.Chain.Config.DepositChainID)) if err != nil { diff --git a/types/config.go b/types/config.go index 4040b70c5a..ff8bdbd230 100644 --- a/types/config.go +++ b/types/config.go @@ -170,6 +170,10 @@ type Config struct { MevBoostRelayExporter struct { Enabled bool `yaml:"enabled" envconfig:"MEVBOOSTRELAY_EXPORTER_ENABLED"` } `yaml:"mevBoostRelayExporter"` + Pprof struct { + Enabled bool `yaml:"enabled" envconfig:"PPROF_ENABLED"` + Port string `yaml:"port" envconfig:"PPROF_PORT"` + } `yaml:"pprof"` } type DatabaseConfig struct {