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

Commit

Permalink
imp(rpc) Add support for EVM RPC metrics
Browse files Browse the repository at this point in the history
- Support --metrics flag
- Add EVM rpc metrics server config
  • Loading branch information
v-homsi committed Oct 13, 2022
1 parent 054723a commit 1f2cb83
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
go.mod
go.sum
- uses: actions/checkout@v3
- run: semgrep scan --sarif --output=semgrep.sarif
- run: semgrep scan --sarif --output=semgrep.sarif --config auto
env:
# Upload findings to GitHub Advanced Security Dashboard [step 1/2]
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (ledger) [#1277](https://github.com/evmos/ethermint/pull/1277) Add Ledger preprocessing transaction hook for EIP-712-signed Cosmos payloads.
* (rpc) [#1296](https://github.com/evmos/ethermint/pull/1296) Add RPC Backend unit tests.
* (rpc) [#1352](https://github.com/evmos/ethermint/pull/1352) Make the grpc queries run concurrently, don't block the consensus state machine.
* (rpc) [#1378](https://github.com/evmos/ethermint/pull/1378) Add support for EVM RPC metrics

### Bug Fixes

Expand Down
7 changes: 7 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const (
// DefaultJSONRPCWsAddress is the default address the JSON-RPC WebSocket server binds to.
DefaultJSONRPCWsAddress = "0.0.0.0:8546"

// DefaultJsonRPCMetricsAddress is the default address the JSON-RPC Metrics server binds to.
DefaultJSONRPCMetricsAddress = "0.0.0.0:6065"

// DefaultEVMTracer is the default vm.Tracer type
DefaultEVMTracer = ""

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

// TLSConfig defines the certificate and matching private key for the server.
Expand Down Expand Up @@ -211,6 +216,7 @@ func DefaultJSONRPCConfig() *JSONRPCConfig {
AllowUnprotectedTxs: DefaultAllowUnprotectedTxs,
MaxOpenConnections: DefaultMaxOpenConnections,
EnableIndexer: false,
MetricsAddress: DefaultJSONRPCMetricsAddress,
}
}

Expand Down Expand Up @@ -319,6 +325,7 @@ func GetConfig(v *viper.Viper) (Config, error) {
HTTPIdleTimeout: v.GetDuration("json-rpc.http-idle-timeout"),
MaxOpenConnections: v.GetInt("json-rpc.max-open-connections"),
EnableIndexer: v.GetBool("json-rpc.enable-indexer"),
MetricsAddress: v.GetString("json-rpc.metrics-address"),
},
TLS: TLSConfig{
CertificatePath: v.GetString("tls.certificate-path"),
Expand Down
4 changes: 4 additions & 0 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ max-open-connections = {{ .JSONRPC.MaxOpenConnections }}
# EnableIndexer enables the custom transaction indexer for the EVM (ethereum transactions).
enable-indexer = {{ .JSONRPC.EnableIndexer }}
# MetricsAddress defines the EVM Metrics server address to bind to. Pass --metrics in CLI to enable
# Prometheus metrics path: /debug/metrics/prometheus
metrics-address = "{{ .JSONRPC.MetricsAddress }}"
###############################################################################
### TLS 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 @@ -49,6 +49,7 @@ const (
JSONRPCAllowUnprotectedTxs = "json-rpc.allow-unprotected-txs"
JSONRPCMaxOpenConnections = "json-rpc.max-open-connections"
JSONRPCEnableIndexer = "json-rpc.enable-indexer"
JSONRPCEnableMetrics = "metrics"
)

// EVM flags
Expand Down
9 changes: 9 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ import (
"github.com/cosmos/cosmos-sdk/server/rosetta"
crgserver "github.com/cosmos/cosmos-sdk/server/rosetta/lib/server"

ethmetrics "github.com/ethereum/go-ethereum/metrics"
ethmetricsexp "github.com/ethereum/go-ethereum/metrics/exp"

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

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
cmd.Flags().Uint64(srvflags.EVMMaxTxGasWanted, config.DefaultMaxTxGasWanted, "the gas wanted for each eth tx returned in ante handler in check tx mode") //nolint:lll
Expand Down Expand Up @@ -340,6 +344,11 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, appCreator ty
app.RegisterTendermintService(clientCtx)
}

if ctx.Viper.GetBool(srvflags.JSONRPCEnableMetrics) {
ethmetrics.Enabled = true
ethmetricsexp.Setup(config.JSONRPC.MetricsAddress)
}

var idxer ethermint.EVMTxIndexer
if config.JSONRPC.EnableIndexer {
idxDB, err := OpenIndexerDB(home, server.GetAppDBBackend(ctx.Viper))
Expand Down

0 comments on commit 1f2cb83

Please sign in to comment.