Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

- [\#346](https://github.com/cosmos/evm/pull/346) Add eth_createAccessList method and implementation
- [\#502](https://github.com/cosmos/evm/pull/502) Add block time in derived logs.
- [\#588](https://github.com/cosmos/evm/pull/588) go-ethereum metrics are now available in Cosmos SDK's telemetry server at host:port/geth/metrics (default localhost:1317/geth/metrics).
- [\#633](https://github.com/cosmos/evm/pull/633) go-ethereum metrics are now emitted on a separate server. default address: 127.0.0.1:8080.

### STATE BREAKING

Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ require (
github.com/onsi/ginkgo/v2 v2.23.4
github.com/onsi/gomega v1.38.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.22.0
github.com/rs/cors v1.11.1
github.com/spf13/cast v1.9.2
github.com/spf13/cobra v1.9.1
Expand Down Expand Up @@ -181,7 +180,6 @@ require (
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
Expand All @@ -207,6 +205,7 @@ require (
github.com/pion/transport/v3 v3.0.1 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.22.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.63.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
Expand Down
56 changes: 56 additions & 0 deletions metrics/geth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package metrics

import (
"context"
"errors"
"net/http"
"time"

gethmetrics "github.com/ethereum/go-ethereum/metrics"
gethprom "github.com/ethereum/go-ethereum/metrics/prometheus"

"cosmossdk.io/log"
)

// StartGethMetricServer starts the geth metrics server on the specified address.
func StartGethMetricServer(ctx context.Context, log log.Logger, addr string) error {
mux := http.NewServeMux()
mux.Handle("/metrics", gethprom.Handler(gethmetrics.DefaultRegistry))

server := &http.Server{

Check failure on line 20 in metrics/geth.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server (gosec)
Addr: addr,
Handler: mux,
}

errCh := make(chan error, 1)

go func() {
log.Info("starting geth metrics server...", "address", addr)
errCh <- server.ListenAndServe()
}()

// Start a blocking select to wait for an indication to stop the server or that
// the server failed to start properly.
select {
case <-ctx.Done():
// The calling process canceled or closed the provided context, so we must
// gracefully stop the metrics server.
log.Info("stopping geth metrics server...", "address", addr)

shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

if err := server.Shutdown(shutdownCtx); err != nil {
log.Error("geth metrics server shutdown error", "err", err)
return err
}
return nil

case err := <-errCh:
if err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Error("failed to start geth metrics server", "err", err)
return err
}
return nil
}
}
11 changes: 11 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"errors"
"fmt"
"net/netip"
"path"
"time"

Expand Down Expand Up @@ -69,6 +70,9 @@ const (
// DefaultEVMMinTip is the default minimum priority fee for the mempool
DefaultEVMMinTip = 0

// DefaultGethMetricsAddr is the default port for the geth metrics server.
DefaultGethMetricsAddr = `"127.0.0.1:8080"`

// DefaultGasCap is the default cap on gas that can be used in eth_call/estimateGas
DefaultGasCap uint64 = 25_000_000

Expand Down Expand Up @@ -148,6 +152,8 @@ type EVMConfig struct {
EVMChainID uint64 `mapstructure:"evm-chain-id"`
// MinTip defines the minimum priority fee for the mempool
MinTip uint64 `mapstructure:"min-tip"`
// GethMetricsAddr is the address the geth metrics server will bind to. Default 127.0.0.1:8080
GethMetricsAddr string `mapstructure:"geth-metrics-addr"`
}

// JSONRPCConfig defines configuration for the EVM RPC server.
Expand Down Expand Up @@ -218,6 +224,7 @@ func DefaultEVMConfig() *EVMConfig {
EVMChainID: DefaultEVMChainID,
EnablePreimageRecording: DefaultEnablePreimageRecording,
MinTip: DefaultEVMMinTip,
GethMetricsAddr: DefaultGethMetricsAddr,
}
}

Expand All @@ -227,6 +234,10 @@ func (c EVMConfig) Validate() error {
return fmt.Errorf("invalid tracer type %s, available types: %v", c.Tracer, evmTracers)
}

if _, err := netip.ParseAddrPort(c.GethMetricsAddr); err != nil {
return fmt.Errorf("invalid geth metrics address %q: %w", c.GethMetricsAddr, err)
}

return nil
}

Expand Down
3 changes: 3 additions & 0 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ evm-chain-id = {{ .EVM.EVMChainID }}
# MinTip defines the minimum priority fee for the mempool.
min-tip = {{ .EVM.MinTip }}

# GethMetricsAddr defines the addr to bind the geth metrics server to. Default 127.0.0.1:8080.
geth-metrics-addr = {{ .EVM.GethMetricsAddr }}

###############################################################################
### JSON RPC Configuration ###
###############################################################################
Expand Down
1 change: 1 addition & 0 deletions server/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const (
EVMEnablePreimageRecording = "evm.cache-preimage"
EVMChainID = "evm.evm-chain-id"
EVMMinTip = "evm.min-tip"
EvmGethMetricsAddr = "evm.geth-metrics-addr"
)

// TLS flags
Expand Down
11 changes: 7 additions & 4 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
"path/filepath"
"runtime/pprof"

gethmetrics "github.com/ethereum/go-ethereum/metrics"
evmmetrics "github.com/cosmos/evm/metrics"

Check failure on line 12 in server/start.go

View workflow job for this annotation

GitHub Actions / Run golangci-lint

File is not properly formatted (gci)
ethmetricsexp "github.com/ethereum/go-ethereum/metrics/exp"
gethprom "github.com/ethereum/go-ethereum/metrics/prometheus"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
Expand Down Expand Up @@ -222,6 +221,7 @@
cmd.Flags().Bool(srvflags.EVMEnablePreimageRecording, cosmosevmserverconfig.DefaultEnablePreimageRecording, "Enables tracking of SHA3 preimages in the EVM (not implemented yet)") //nolint:lll
cmd.Flags().Uint64(srvflags.EVMChainID, cosmosevmserverconfig.DefaultEVMChainID, "the EIP-155 compatible replay protection chain ID")
cmd.Flags().Uint64(srvflags.EVMMinTip, cosmosevmserverconfig.DefaultEVMMinTip, "the minimum priority fee for the mempool")
cmd.Flags().String(srvflags.EvmGethMetricsAddr, cosmosevmserverconfig.DefaultGethMetricsAddr, "the address to bind the geth metrics server to")

cmd.Flags().String(srvflags.TLSCertPath, "", "the cert.pem file path for the server TLS configuration")
cmd.Flags().String(srvflags.TLSKeyPath, "", "the key.pem file path for the server TLS configuration")
Expand Down Expand Up @@ -504,7 +504,7 @@
defer grpcSrv.GracefulStop()
}

startAPIServer(ctx, svrCtx, clientCtx, g, config.Config, app, grpcSrv, metrics)
startAPIServer(ctx, svrCtx, clientCtx, g, config.Config, app, grpcSrv, metrics, config.EVM.GethMetricsAddr)

if config.JSONRPC.Enable {
txApp, ok := app.(AppWithPendingTxStream)
Expand Down Expand Up @@ -675,6 +675,7 @@
app types.Application,
grpcSrv *grpc.Server,
metrics *telemetry.Metrics,
gethMetricsAddr string,
) {
if !svrCfg.API.Enable {
return
Expand All @@ -685,7 +686,9 @@

if svrCfg.Telemetry.Enabled {
apiSrv.SetTelemetry(metrics)
apiSrv.Router.Handle("/geth/metrics", gethprom.Handler(gethmetrics.DefaultRegistry))
g.Go(func() error {
return evmmetrics.StartGethMetricServer(ctx, svrCtx.Logger.With("server", "geth_metrics"), gethMetricsAddr)
})
}

g.Go(func() error {
Expand Down
Loading