From 5e6e9e6187d674ae37a7046e23c013a9ef98f61d Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Tue, 2 Jul 2024 16:24:06 -0400 Subject: [PATCH] feat: adds metrics --- oracle/pkg/updater/metrics.go | 9 +++++++++ oracle/pkg/updater/updater.go | 3 +++ 2 files changed, 12 insertions(+) diff --git a/oracle/pkg/updater/metrics.go b/oracle/pkg/updater/metrics.go index ab1b8d9b7..418e3986d 100644 --- a/oracle/pkg/updater/metrics.go +++ b/oracle/pkg/updater/metrics.go @@ -21,6 +21,7 @@ type metrics struct { BlockTimeCacheHits prometheus.Counter BlockTimeCacheMisses prometheus.Counter LastSentNonce prometheus.Gauge + TxnReceiptRequestDuration prometheus.Histogram } func newMetrics() *metrics { @@ -129,6 +130,14 @@ func newMetrics() *metrics { Help: "Last nonce sent to for settlement", }, ) + m.TxnReceiptRequestDuration = prometheus.NewHistogram( + prometheus.HistogramOpts{ + Namespace: defaultNamespace, + Subsystem: subsystem, + Name: "txn_receipt_request_duration", + Help: "Duration of transaction receipt requests", + }, + ) return m } diff --git a/oracle/pkg/updater/updater.go b/oracle/pkg/updater/updater.go index aedc0d864..893e18e3a 100644 --- a/oracle/pkg/updater/updater.go +++ b/oracle/pkg/updater/updater.go @@ -11,6 +11,7 @@ import ( "strings" "sync" "sync/atomic" + "time" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" @@ -498,10 +499,12 @@ func (u *Updater) getL1Txns(ctx context.Context, blockNum uint64) (map[string]Tx for _, bucket := range buckets { eg.Go(func() error { + start := time.Now() results, err := u.receiptBatcher.BatchReceipts(ctx, bucket) if err != nil { return fmt.Errorf("failed to get batch receipts: %w", err) } + u.metrics.TxnReceiptRequestDuration.Observe(time.Since(start).Seconds()) for _, result := range results { if result.Err != nil { return fmt.Errorf("failed to get receipt for txn: %s", result.Err)