Skip to content

Commit

Permalink
Add pprof to relay server (Layr-Labs#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmanc authored Feb 19, 2025
1 parent 6d04a82 commit f33bcf9
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 15 deletions.
2 changes: 1 addition & 1 deletion inabox/deploy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ func (env *Config) generateControllerVars(
CONTROLLER_AVAILABLE_RELAYS: "0,1,2,3",
CONTROLLER_DISPATCHER_PULL_INTERVAL: "3s",
CONTROLLER_NODE_REQUEST_TIMEOUT: "5s",
CONTROLLER_NUM_CONNECTIONS_TO_NODES: "10",
CONTROLLER_CHAIN_RPC: "",
CONTROLLER_PRIVATE_KEY: "123",
CONTROLLER_NUM_CONFIRMATIONS: "0",
Expand Down Expand Up @@ -378,6 +377,7 @@ func (env *Config) generateRelayVars(ind int, graphUrl, grpcPort string) RelayVa
RELAY_MAX_CONCURRENT_GET_CHUNK_OPS_CLIENT: "10",
RELAY_MAX_GET_CHUNK_BYTES_PER_SECOND_CLIENT: "100000000",
RELAY_AUTHENTICATION_DISABLED: "false",
RELAY_ENABLE_METRICS: "true",
}
env.applyDefaults(&v, "RELAY", "relay", ind)

Expand Down
24 changes: 16 additions & 8 deletions inabox/deploy/env_vars.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion relay/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ func NewConfig(ctx *cli.Context) (Config, error) {
InternalGetProofsTimeout: ctx.Duration(flags.InternalGetProofsTimeoutFlag.Name),
InternalGetCoefficientsTimeout: ctx.Duration(flags.InternalGetCoefficientsTimeoutFlag.Name),
},
MetricsPort: ctx.Int(flags.MetricsPortFlag.Name),
MetricsPort: ctx.Int(flags.MetricsPortFlag.Name),
EnableMetrics: ctx.Bool(flags.EnableMetricsFlag.Name),
EnablePprof: ctx.Bool(flags.EnablePprofFlag.Name),
PprofHttpPort: ctx.Int(flags.PprofHttpPortFlag.Name),
},
EthClientConfig: geth.ReadEthClientConfigRPCOnly(ctx),
BLSOperatorStateRetrieverAddr: ctx.String(flags.BlsOperatorStateRetrieverAddrFlag.Name),
Expand Down
23 changes: 23 additions & 0 deletions relay/cmd/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/Layr-Labs/eigenda/common/aws"
"github.com/Layr-Labs/eigenda/common/geth"
"github.com/Layr-Labs/eigenda/core/thegraph"
"github.com/docker/go-units"

Check failure on line 12 in relay/cmd/flags/flags.go

View workflow job for this annotation

GitHub Actions / Linter

units redeclared in this block

Check failure on line 12 in relay/cmd/flags/flags.go

View workflow job for this annotation

GitHub Actions / Linter

"github.com/docker/go-units" imported as units and not used (typecheck)

Check failure on line 12 in relay/cmd/flags/flags.go

View workflow job for this annotation

GitHub Actions / Linter

units redeclared in this block

Check failure on line 12 in relay/cmd/flags/flags.go

View workflow job for this annotation

GitHub Actions / Linter

"github.com/docker/go-units" imported as units and not used) (typecheck)

Check failure on line 12 in relay/cmd/flags/flags.go

View workflow job for this annotation

GitHub Actions / Linter

units redeclared in this block
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -291,6 +292,25 @@ var (
EnvVar: common.PrefixEnvVar(envVarPrefix, "METRICS_PORT"),
Value: 9101,
}
EnableMetricsFlag = cli.BoolFlag{
Name: common.PrefixFlag(FlagPrefix, "enable-metrics"),
Usage: "Enable prometheus metrics collection",
Required: true,
EnvVar: common.PrefixEnvVar(envVarPrefix, "ENABLE_METRICS"),
}
EnablePprofFlag = cli.BoolFlag{
Name: common.PrefixFlag(FlagPrefix, "enable-pprof"),
Usage: "Enable pprof profiling",
Required: false,
EnvVar: common.PrefixEnvVar(envVarPrefix, "ENABLE_PPROF"),
}
PprofHttpPortFlag = cli.IntFlag{
Name: common.PrefixFlag(FlagPrefix, "pprof-port"),
Usage: "Port to listen on for pprof",
Required: false,
EnvVar: common.PrefixEnvVar(envVarPrefix, "PPROF_PORT"),
Value: 6060,
}
)

var requiredFlags = []cli.Flag{
Expand All @@ -300,6 +320,7 @@ var requiredFlags = []cli.Flag{
RelayKeysFlag,
BlsOperatorStateRetrieverAddrFlag,
EigenDAServiceManagerAddrFlag,
EnableMetricsFlag,
}

var optionalFlags = []cli.Flag{
Expand Down Expand Up @@ -337,6 +358,8 @@ var optionalFlags = []cli.Flag{
InternalGetCoefficientsTimeoutFlag,
OnchainStateRefreshIntervalFlag,
MetricsPortFlag,
EnablePprofFlag,
PprofHttpPortFlag,
}

var Flags []cli.Flag
Expand Down
12 changes: 11 additions & 1 deletion relay/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package relay

import (
"time"

v2 "github.com/Layr-Labs/eigenda/core/v2"
"github.com/Layr-Labs/eigenda/relay/limiter"
"time"
)

// Config is the configuration for the relay Server.
Expand Down Expand Up @@ -64,4 +65,13 @@ type Config struct {

// MetricsPort is the port that the relay metrics server listens on.
MetricsPort int

// EnableMetrics enables the metrics HTTP server for prometheus metrics collection
EnableMetrics bool

// EnablePprof enables the pprof HTTP server for profiling
EnablePprof bool

// PprofHttpPort is the port that the pprof HTTP server listens on
PprofHttpPort int
}
22 changes: 18 additions & 4 deletions relay/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/Layr-Labs/eigenda/api"
pb "github.com/Layr-Labs/eigenda/api/grpc/relay"
"github.com/Layr-Labs/eigenda/common/healthcheck"
"github.com/Layr-Labs/eigenda/common/pprof"
"github.com/Layr-Labs/eigenda/core"
v2 "github.com/Layr-Labs/eigenda/core/v2"
"github.com/Layr-Labs/eigenda/disperser/common/v2/blobstore"
Expand Down Expand Up @@ -489,7 +490,18 @@ func buildInsufficientGetChunksBandwidthError(

// Start starts the server listening for requests. This method will block until the server is stopped.
func (s *Server) Start(ctx context.Context) error {
s.metrics.Start()
// Start metrics server if enabled
if s.config.EnableMetrics {
s.metrics.Start()
s.logger.Info("Enabled metrics for relay server", "port", s.config.MetricsPort)
}

// Start pprof server if enabled
if s.config.EnablePprof {
pprofProfiler := pprof.NewPprofProfiler(fmt.Sprintf("%d", s.config.PprofHttpPort), s.logger)
go pprofProfiler.Start()
s.logger.Info("Enabled pprof for relay server", "port", s.config.PprofHttpPort)
}

if s.chainReader != nil && s.metadataProvider != nil {
go func() {
Expand Down Expand Up @@ -548,9 +560,11 @@ func (s *Server) Stop() error {
s.grpcServer.GracefulStop()
}

err := s.metrics.Stop()
if err != nil {
return fmt.Errorf("error stopping metrics server: %w", err)
if s.config.EnableMetrics {
err := s.metrics.Stop()
if err != nil {
return fmt.Errorf("error stopping metrics server: %w", err)
}
}

return nil
Expand Down

0 comments on commit f33bcf9

Please sign in to comment.