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

DAS RPC Client Metrics #2549

Merged
merged 6 commits into from
Sep 30, 2024
Merged
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
31 changes: 30 additions & 1 deletion das/dasRpcClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"golang.org/x/sync/errgroup"

"github.com/ethereum/go-ethereum/rpc"
Expand All @@ -21,6 +22,17 @@ import (
"github.com/offchainlabs/nitro/util/signature"
)

var (
rpcClientStoreRequestGauge = metrics.NewRegisteredGauge("arb/das/rpcclient/store/requests", nil)
rpcClientStoreSuccessGauge = metrics.NewRegisteredGauge("arb/das/rpcclient/store/success", nil)
rpcClientStoreFailureGauge = metrics.NewRegisteredGauge("arb/das/rpcclient/store/failure", nil)
rpcClientStoreStoredBytesGauge = metrics.NewRegisteredGauge("arb/das/rpcclient/store/bytes", nil)
rpcClientStoreDurationHistogram = metrics.NewRegisteredHistogram("arb/das/rpcclient/store/duration", nil, metrics.NewBoundedHistogramSample())

rpcClientSendChunkSuccessGauge = metrics.NewRegisteredGauge("arb/das/rpcclient/sendchunk/success", nil)
rpcClientSendChunkFailureGauge = metrics.NewRegisteredGauge("arb/das/rpcclient/sendchunk/failure", nil)
)

type DASRPCClient struct { // implements DataAvailabilityService
clnt *rpc.Client
url string
Expand Down Expand Up @@ -58,8 +70,20 @@ func NewDASRPCClient(target string, signer signature.DataSignerFunc, maxStoreChu
}

func (c *DASRPCClient) Store(ctx context.Context, message []byte, timeout uint64) (*daprovider.DataAvailabilityCertificate, error) {
rpcClientStoreRequestGauge.Inc(1)
start := time.Now()
success := false
defer func() {
if success {
rpcClientStoreSuccessGauge.Inc(1)
} else {
rpcClientStoreFailureGauge.Inc(1)
}
rpcClientStoreDurationHistogram.Update(time.Since(start).Nanoseconds())
}()

// #nosec G115
timestamp := uint64(time.Now().Unix())
timestamp := uint64(start.Unix())
nChunks := uint64(len(message)) / c.chunkSize
lastChunkSize := uint64(len(message)) % c.chunkSize
if lastChunkSize > 0 {
Expand Down Expand Up @@ -116,6 +140,9 @@ func (c *DASRPCClient) Store(ctx context.Context, message []byte, timeout uint64
return nil, err
}

rpcClientStoreStoredBytesGauge.Inc(int64(len(message)))
success = true

return &daprovider.DataAvailabilityCertificate{
DataHash: common.BytesToHash(storeResult.DataHash),
Timeout: uint64(storeResult.Timeout),
Expand All @@ -133,8 +160,10 @@ func (c *DASRPCClient) sendChunk(ctx context.Context, batchId, i uint64, chunk [
}

if err := c.clnt.CallContext(ctx, nil, "das_sendChunk", hexutil.Uint64(batchId), hexutil.Uint64(i), hexutil.Bytes(chunk), hexutil.Bytes(chunkReqSig)); err != nil {
rpcClientSendChunkFailureGauge.Inc(1)
return err
}
rpcClientSendChunkSuccessGauge.Inc(1)
return nil
}

Expand Down
Loading