Skip to content
This repository was archived by the owner on Apr 4, 2024. It is now read-only.

Commit 1f2cb83

Browse files
committed
imp(rpc) Add support for EVM RPC metrics
- Support --metrics flag - Add EVM rpc metrics server config
1 parent 054723a commit 1f2cb83

File tree

6 files changed

+23
-1
lines changed

6 files changed

+23
-1
lines changed

.github/workflows/semgrep.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
go.mod
3333
go.sum
3434
- uses: actions/checkout@v3
35-
- run: semgrep scan --sarif --output=semgrep.sarif
35+
- run: semgrep scan --sarif --output=semgrep.sarif --config auto
3636
env:
3737
# Upload findings to GitHub Advanced Security Dashboard [step 1/2]
3838
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
6060
* (ledger) [#1277](https://github.com/evmos/ethermint/pull/1277) Add Ledger preprocessing transaction hook for EIP-712-signed Cosmos payloads.
6161
* (rpc) [#1296](https://github.com/evmos/ethermint/pull/1296) Add RPC Backend unit tests.
6262
* (rpc) [#1352](https://github.com/evmos/ethermint/pull/1352) Make the grpc queries run concurrently, don't block the consensus state machine.
63+
* (rpc) [#1378](https://github.com/evmos/ethermint/pull/1378) Add support for EVM RPC metrics
6364

6465
### Bug Fixes
6566

server/config/config.go

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const (
2525
// DefaultJSONRPCWsAddress is the default address the JSON-RPC WebSocket server binds to.
2626
DefaultJSONRPCWsAddress = "0.0.0.0:8546"
2727

28+
// DefaultJsonRPCMetricsAddress is the default address the JSON-RPC Metrics server binds to.
29+
DefaultJSONRPCMetricsAddress = "0.0.0.0:6065"
30+
2831
// DefaultEVMTracer is the default vm.Tracer type
2932
DefaultEVMTracer = ""
3033

@@ -110,6 +113,8 @@ type JSONRPCConfig struct {
110113
MaxOpenConnections int `mapstructure:"max-open-connections"`
111114
// EnableIndexer defines if enable the custom indexer service.
112115
EnableIndexer bool `mapstructure:"enable-indexer"`
116+
// MetricsAddress defines the metrics server to listen on
117+
MetricsAddress string `mapstructure:"metrics-address"`
113118
}
114119

115120
// TLSConfig defines the certificate and matching private key for the server.
@@ -211,6 +216,7 @@ func DefaultJSONRPCConfig() *JSONRPCConfig {
211216
AllowUnprotectedTxs: DefaultAllowUnprotectedTxs,
212217
MaxOpenConnections: DefaultMaxOpenConnections,
213218
EnableIndexer: false,
219+
MetricsAddress: DefaultJSONRPCMetricsAddress,
214220
}
215221
}
216222

@@ -319,6 +325,7 @@ func GetConfig(v *viper.Viper) (Config, error) {
319325
HTTPIdleTimeout: v.GetDuration("json-rpc.http-idle-timeout"),
320326
MaxOpenConnections: v.GetInt("json-rpc.max-open-connections"),
321327
EnableIndexer: v.GetBool("json-rpc.enable-indexer"),
328+
MetricsAddress: v.GetString("json-rpc.metrics-address"),
322329
},
323330
TLS: TLSConfig{
324331
CertificatePath: v.GetString("tls.certificate-path"),

server/config/toml.go

+4
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ max-open-connections = {{ .JSONRPC.MaxOpenConnections }}
7373
# EnableIndexer enables the custom transaction indexer for the EVM (ethereum transactions).
7474
enable-indexer = {{ .JSONRPC.EnableIndexer }}
7575
76+
# MetricsAddress defines the EVM Metrics server address to bind to. Pass --metrics in CLI to enable
77+
# Prometheus metrics path: /debug/metrics/prometheus
78+
metrics-address = "{{ .JSONRPC.MetricsAddress }}"
79+
7680
###############################################################################
7781
### TLS Configuration ###
7882
###############################################################################

server/flags/flags.go

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const (
4949
JSONRPCAllowUnprotectedTxs = "json-rpc.allow-unprotected-txs"
5050
JSONRPCMaxOpenConnections = "json-rpc.max-open-connections"
5151
JSONRPCEnableIndexer = "json-rpc.enable-indexer"
52+
JSONRPCEnableMetrics = "metrics"
5253
)
5354

5455
// EVM flags

server/start.go

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import (
3333
"github.com/cosmos/cosmos-sdk/server/rosetta"
3434
crgserver "github.com/cosmos/cosmos-sdk/server/rosetta/lib/server"
3535

36+
ethmetrics "github.com/ethereum/go-ethereum/metrics"
37+
ethmetricsexp "github.com/ethereum/go-ethereum/metrics/exp"
38+
3639
"github.com/cosmos/cosmos-sdk/client"
3740
"github.com/cosmos/cosmos-sdk/client/flags"
3841
pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types"
@@ -171,6 +174,7 @@ which accepts a path for the resulting pprof file.
171174
cmd.Flags().Int32(srvflags.JSONRPCBlockRangeCap, config.DefaultBlockRangeCap, "Sets the max block range allowed for `eth_getLogs` query")
172175
cmd.Flags().Int(srvflags.JSONRPCMaxOpenConnections, config.DefaultMaxOpenConnections, "Sets the maximum number of simultaneous connections for the server listener") //nolint:lll
173176
cmd.Flags().Bool(srvflags.JSONRPCEnableIndexer, false, "Enable the custom tx indexer for json-rpc")
177+
cmd.Flags().Bool(srvflags.JSONRPCEnableMetrics, false, "Define if EVM rpc metrics server should be enabled")
174178

175179
cmd.Flags().String(srvflags.EVMTracer, config.DefaultEVMTracer, "the EVM tracer type to collect execution traces from the EVM transaction execution (json|struct|access_list|markdown)") //nolint:lll
176180
cmd.Flags().Uint64(srvflags.EVMMaxTxGasWanted, config.DefaultMaxTxGasWanted, "the gas wanted for each eth tx returned in ante handler in check tx mode") //nolint:lll
@@ -340,6 +344,11 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
340344
app.RegisterTendermintService(clientCtx)
341345
}
342346

347+
if ctx.Viper.GetBool(srvflags.JSONRPCEnableMetrics) {
348+
ethmetrics.Enabled = true
349+
ethmetricsexp.Setup(config.JSONRPC.MetricsAddress)
350+
}
351+
343352
var idxer ethermint.EVMTxIndexer
344353
if config.JSONRPC.EnableIndexer {
345354
idxDB, err := OpenIndexerDB(home, server.GetAppDBBackend(ctx.Viper))

0 commit comments

Comments
 (0)