Skip to content

Commit

Permalink
Merge pull request #2549 from OffchainLabs/das-client-metrics
Browse files Browse the repository at this point in the history
DAS RPC Client Metrics
  • Loading branch information
tsahee authored Sep 30, 2024
2 parents f5fb27b + 86368d4 commit ab22097
Showing 1 changed file with 30 additions and 1 deletion.
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

0 comments on commit ab22097

Please sign in to comment.