Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InstrumentedClient having rpcCallsCollector as mandatory #378

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
9 changes: 6 additions & 3 deletions chainio/clients/eth/instrumented_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
// see https://github.com/ethereum/go-ethereum/issues/28267
type InstrumentedClient struct {
client *ethclient.Client
rpcCallsCollector *rpccalls.Collector
rpcCallsCollector rpccalls.CollectorInterface
// we store both client and version because that's what the web3_clientVersion jsonrpc call returns
// https://ethereum.org/en/developers/docs/apis/json-rpc/#web3_clientversion
clientAndVersion string
Expand All @@ -30,7 +30,10 @@ type InstrumentedClient struct {
var _ HttpBackend = (*InstrumentedClient)(nil)
var _ WsBackend = (*InstrumentedClient)(nil)

func NewInstrumentedClient(rpcAddress string, rpcCallsCollector *rpccalls.Collector) (*InstrumentedClient, error) {
func NewInstrumentedClient(
rpcAddress string,
rpcCallsCollector rpccalls.CollectorInterface,
) (*InstrumentedClient, error) {
client, err := ethclient.Dial(rpcAddress)
if err != nil {
return nil, err
Expand All @@ -41,7 +44,7 @@ func NewInstrumentedClient(rpcAddress string, rpcCallsCollector *rpccalls.Collec

func NewInstrumentedClientFromClient(
client *ethclient.Client,
rpcCallsCollector *rpccalls.Collector,
rpcCallsCollector rpccalls.CollectorInterface,
) *InstrumentedClient {
clientAndVersion := getClientAndVersion(client)
return &InstrumentedClient{
Expand Down
5 changes: 5 additions & 0 deletions metrics/collectors/rpc_calls/rpc_calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
)

type CollectorInterface interface {
ObserveRPCRequestDurationSeconds(duration float64, method, clientVersion string)
AddRPCRequestTotal(method, clientVersion string)
}

// Collector contains instrumented metrics that should be incremented by the avs node using the methods below
// it is used by the eigensdk's instrumented_client, but can also be used by avs teams to instrument their own client
// if it differs from ours.
Expand Down
Loading