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 client using chunks metric #2599

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
54 changes: 38 additions & 16 deletions das/dasRpcClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package das
import (
"context"
"fmt"
"net/url"
"strings"
"time"

Expand All @@ -18,26 +19,32 @@ import (
"github.com/ethereum/go-ethereum/rpc"
"github.com/offchainlabs/nitro/arbstate/daprovider"
"github.com/offchainlabs/nitro/blsSignatures"
"github.com/offchainlabs/nitro/util/metricsutil"
"github.com/offchainlabs/nitro/util/pretty"
"github.com/offchainlabs/nitro/util/signature"
)

const (
clientMetricBase = "arb/das/rpcclient"
)

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)
rpcClientStoreRequestGauge = metrics.NewRegisteredGauge(clientMetricBase+"/store/requests", nil)
rpcClientStoreSuccessGauge = metrics.NewRegisteredGauge(clientMetricBase+"/store/success", nil)
rpcClientStoreFailureGauge = metrics.NewRegisteredGauge(clientMetricBase+"/store/failure", nil)
rpcClientStoreStoredBytesGauge = metrics.NewRegisteredGauge(clientMetricBase+"/store/bytes", nil)
rpcClientStoreDurationHistogram = metrics.NewRegisteredHistogram(clientMetricBase+"/store/duration", nil, metrics.NewBoundedHistogramSample())

rpcClientSendChunkSuccessGauge = metrics.NewRegisteredGauge(clientMetricBase+"/sendchunk/success", nil)
rpcClientSendChunkFailureGauge = metrics.NewRegisteredGauge(clientMetricBase+"/sendchunk/failure", nil)
)

type DASRPCClient struct { // implements DataAvailabilityService
clnt *rpc.Client
url string
signer signature.DataSignerFunc
chunkSize uint64
clnt *rpc.Client
url string
signer signature.DataSignerFunc
chunkSize uint64
metricName string
}

func nilSigner(_ []byte) ([]byte, error) {
Expand All @@ -61,24 +68,38 @@ func NewDASRPCClient(target string, signer signature.DataSignerFunc, maxStoreChu
return nil, fmt.Errorf("max-store-chunk-body-size %d doesn't leave enough room for chunk payload", maxStoreChunkBodySize)
}

url, err := url.Parse(target)
if err != nil {
return nil, err
}

return &DASRPCClient{
clnt: clnt,
url: target,
signer: signer,
chunkSize: uint64(chunkSize),
clnt: clnt,
url: target,
signer: signer,
chunkSize: uint64(chunkSize),
metricName: metricsutil.CanonicalizeMetricName(url.Hostname()),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like CanonicalizeMetricName doesn't filter out periods, which don't seem to be an allowed Prometheus metric name but are of course common in URLs.

Copy link
Member Author

@Tristan-Wilson Tristan-Wilson Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it does replace them. The regex is picking characters that don't match the range, which doesn't include ., and replacing them with _.

// Prometheus metric names must contain only chars [a-zA-Z0-9:_]
func CanonicalizeMetricName(metric string) string {
	invalidPromCharRegex := regexp.MustCompile(`[^a-zA-Z0-9:_]+`)
	return invalidPromCharRegex.ReplaceAllString(metric, "_")

}

If you look at the Nova dashboard, first panel, you can see the dots in domains have been replaced with _.

}, nil
}

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

if legacyStoreUsed {
metrics.GetOrRegisterCounter(clientMetricBase+"/"+c.metricName+"/"+"legacystore/total", nil).Inc(1)
} else {
metrics.GetOrRegisterCounter(clientMetricBase+"/"+c.metricName+"/"+"chunkedstore/total", nil).Inc(1)
}

rpcClientStoreDurationHistogram.Update(time.Since(start).Nanoseconds())
}()

Expand All @@ -100,6 +121,7 @@ func (c *DASRPCClient) Store(ctx context.Context, message []byte, timeout uint64
var startChunkedStoreResult StartChunkedStoreResult
if err := c.clnt.CallContext(ctx, &startChunkedStoreResult, "das_startChunkedStore", hexutil.Uint64(timestamp), hexutil.Uint64(nChunks), hexutil.Uint64(c.chunkSize), hexutil.Uint64(totalSize), hexutil.Uint64(timeout), hexutil.Bytes(startReqSig)); err != nil {
if strings.Contains(err.Error(), "the method das_startChunkedStore does not exist") {
legacyStoreUsed = true
return c.legacyStore(ctx, message, timeout)
}
return nil, err
Expand Down
Loading