Skip to content

Commit

Permalink
InstrumentedClient having rpcCallsCollector as mandatory (#378)
Browse files Browse the repository at this point in the history
Co-authored-by: tomasarrachea <[email protected]>
Co-authored-by: Tomás Grüner <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent 5af43b4 commit 3389c12
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion chainio/clients/elcontracts/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"math/big"
"os"
"testing"
"time"

"github.com/Layr-Labs/eigensdk-go/chainio/clients"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/elcontracts"
Expand Down Expand Up @@ -57,7 +58,7 @@ func TestRegisterOperator(t *testing.T) {
context.Background(),
[]string{"cast",
"send",
"0x408EfD9C90d59298A9b32F4441aC9Df6A2d8C3E1",
fundedAccount,
"--value",
"5ether",
"--private-key",
Expand All @@ -66,6 +67,7 @@ func TestRegisterOperator(t *testing.T) {
)
assert.NoError(t, err)
assert.Equal(t, 0, code)
time.Sleep(500 * time.Millisecond) // wait for the account to be funded

ecdsaPrivateKey, err := crypto.HexToECDSA(fundedPrivateKeyHex)
require.NoError(t, err)
Expand Down
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

0 comments on commit 3389c12

Please sign in to comment.