From 683743585624dcb35a029bbd7a52b6206a2bd6fc Mon Sep 17 00:00:00 2001 From: curryxbo Date: Tue, 7 May 2024 16:34:00 +0800 Subject: [PATCH 1/2] update derivation metrics --- node/derivation/derivation.go | 6 +++++- node/derivation/metrics.go | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/node/derivation/derivation.go b/node/derivation/derivation.go index 19831f253..cd31e6353 100644 --- a/node/derivation/derivation.go +++ b/node/derivation/derivation.go @@ -174,11 +174,14 @@ func (d *Derivation) derivationBlock(ctx context.Context) { d.logger.Error("eth_getLogs failed", "err", err) return } - latestBatchIndex, err := d.rollup.LastCommittedBatchIndex(nil) + latestBatchIndex, err := d.rollup.LastCommittedBatchIndex(&bind.CallOpts{ + BlockNumber: big.NewInt(int64(latest)), + }) if err != nil { d.logger.Error("query rollup latestCommitted batch Index failed", "err", err) return } + d.metrics.SetLatestBatchIndex(latestBatchIndex.Uint64()) d.logger.Info("fetched rollup tx", "txNum", len(logs), "latestBatchIndex", latestBatchIndex) for _, lg := range logs { @@ -208,6 +211,7 @@ func (d *Derivation) derivationBlock(ctx context.Context) { // only last block of batch d.logger.Info("batch derivation complete", "batch_index", batchInfo.batchIndex, "currentBatchEndBlock", lastHeader.Number.Uint64()) d.metrics.SetL2DeriveHeight(lastHeader.Number.Uint64()) + d.metrics.SetSyncedBatchIndex(batchInfo.batchIndex) withdrawalRoot, err := d.L2ToL1MessagePasser.MessageRoot(&bind.CallOpts{ BlockNumber: lastHeader.Number, }) diff --git a/node/derivation/metrics.go b/node/derivation/metrics.go index 9003db632..7238f3fc6 100644 --- a/node/derivation/metrics.go +++ b/node/derivation/metrics.go @@ -18,10 +18,12 @@ const ( ) type Metrics struct { - L1SyncHeight metrics.Gauge - RollupL2Height metrics.Gauge - DeriveL2Height metrics.Gauge - BatchStatus metrics.Gauge + L1SyncHeight metrics.Gauge + RollupL2Height metrics.Gauge + DeriveL2Height metrics.Gauge + BatchStatus metrics.Gauge + LatestBatchIndex metrics.Gauge + SyncedBatchIndex metrics.Gauge } func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { @@ -73,6 +75,14 @@ func (m *Metrics) SetBatchStatus(status uint64) { m.BatchStatus.Set(float64(status)) } +func (m *Metrics) SetLatestBatchIndex(batchIndex uint64) { + m.LatestBatchIndex.Set(float64(batchIndex)) +} + +func (m *Metrics) SetSyncedBatchIndex(batchIndex uint64) { + m.SyncedBatchIndex.Set(float64(batchIndex)) +} + func (m *Metrics) Serve(hostname string, port uint64) (*http.Server, error) { mux := http.NewServeMux() mux.Handle("/metrics", promhttp.Handler()) From e9c4338d0fb8bdce9551da14e0ceedb87ab150a8 Mon Sep 17 00:00:00 2001 From: curryxbo Date: Wed, 8 May 2024 10:43:50 +0800 Subject: [PATCH 2/2] fix PrometheusMetrics --- node/derivation/metrics.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/node/derivation/metrics.go b/node/derivation/metrics.go index 7238f3fc6..da5e8937d 100644 --- a/node/derivation/metrics.go +++ b/node/derivation/metrics.go @@ -56,6 +56,18 @@ func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics { Name: "batch_root_exception", Help: "", }, labels).With(labelsAndValues...), + LatestBatchIndex: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Namespace: namespace, + Subsystem: metricsSubsystem, + Name: "latest_batch_index", + Help: "", + }, labels).With(labelsAndValues...), + SyncedBatchIndex: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{ + Namespace: namespace, + Subsystem: metricsSubsystem, + Name: "synced_batch_index", + Help: "", + }, labels).With(labelsAndValues...), } }