Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -36,7 +36,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:8100.

### STATE BREAKING

Expand Down
2 changes: 1 addition & 1 deletion contrib/images/evmd-env/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN addgroup -g 1025 nonroot
RUN adduser -D nonroot -u 1025 -G nonroot

# Set up the runtime environment
EXPOSE 26656 26657 1317 9090
EXPOSE 26656 26657 1317 9090 26660 8545 8100
STOPSIGNAL SIGTERM
VOLUME /evmd
WORKDIR /evmd
Expand Down
8 changes: 5 additions & 3 deletions evmd/cmd/evmd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,10 @@ func initTestnetFiles(
sdkGRPCPort = 9090

// evmGRPC = 9900 // TODO: maybe need this? idk.
evmJSONRPC = 8545
evmJSONRPCWS = 8546
evmJSONRPCMetrics = 6065
evmJSONRPC = 8545
evmJSONRPCWS = 8546
evmJSONRPCMetrics = 6065
evmGethMetricsPort = 8100
)
p2pPortStart := 26656

Expand All @@ -317,6 +318,7 @@ func initTestnetFiles(
evmCfg.JSONRPC.Address = fmt.Sprintf("127.0.0.1:%d", evmJSONRPC+evmPortOffset)
evmCfg.JSONRPC.MetricsAddress = fmt.Sprintf("127.0.0.1:%d", evmJSONRPCMetrics+evmPortOffset)
evmCfg.JSONRPC.WsAddress = fmt.Sprintf("127.0.0.1:%d", evmJSONRPCWS+evmPortOffset)
evmCfg.EVM.GethMetricsAddress = fmt.Sprintf("127.0.0.1:%d", evmGethMetricsPort+evmPortOffset)
} else {
evmCfg.JSONRPC.WsAddress = fmt.Sprintf("0.0.0.0:%d", evmJSONRPCWS)
evmCfg.JSONRPC.Address = fmt.Sprintf("0.0.0.0:%d", evmJSONRPC)
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
59 changes: 59 additions & 0 deletions metrics/geth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
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{
Addr: addr,
Handler: mux,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
ReadHeaderTimeout: 10 * time.Second,
}

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 @@ -66,6 +67,9 @@ const (
// DefaultEVMMinTip is the default minimum priority fee for the mempool
DefaultEVMMinTip = 0

// DefaultGethMetricsAddress is the default port for the geth metrics server.
DefaultGethMetricsAddress = "127.0.0.1:8100"

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

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

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

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

if _, err := netip.ParseAddrPort(c.GethMetricsAddress); err != nil {
return fmt.Errorf("invalid geth metrics address %q: %w", c.GethMetricsAddress, 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 }}

# GethMetricsAddress defines the addr to bind the geth metrics server to. Default 127.0.0.1:8100.
geth-metrics-address = "{{ .EVM.GethMetricsAddress }}"

###############################################################################
### 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 @@ -70,6 +70,7 @@ const (
EVMEnablePreimageRecording = "evm.cache-preimage"
EVMChainID = "evm.evm-chain-id"
EVMMinTip = "evm.min-tip"
EvmGethMetricsAddress = "evm.geth-metrics-address"
)

// 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,7 @@ import (
"path/filepath"
"runtime/pprof"

gethmetrics "github.com/ethereum/go-ethereum/metrics"
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 All @@ -31,6 +29,7 @@ import (
dbm "github.com/cosmos/cosmos-db"
"github.com/cosmos/evm/indexer"
evmmempool "github.com/cosmos/evm/mempool"
evmmetrics "github.com/cosmos/evm/metrics"
ethdebug "github.com/cosmos/evm/rpc/namespaces/ethereum/debug"
cosmosevmserverconfig "github.com/cosmos/evm/server/config"
srvflags "github.com/cosmos/evm/server/flags"
Expand Down Expand Up @@ -222,6 +221,7 @@ which accepts a path for the resulting pprof file.
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.EvmGethMetricsAddress, cosmosevmserverconfig.DefaultGethMetricsAddress, "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 @@ func startInProcess(svrCtx *server.Context, clientCtx client.Context, opts Start
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.GethMetricsAddress)

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

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"), gethMetricsAddress)
})
}

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