Skip to content

Commit

Permalink
feat(rollup-relayer): add sync height and throughput metrics (#1520)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinlyguo authored Sep 19, 2024
1 parent 736d850 commit 404a625
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime/debug"
)

var tag = "v4.4.61"
var tag = "v4.4.62"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down
12 changes: 12 additions & 0 deletions rollup/internal/controller/relayer/l2_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,18 @@ func (r *Layer2Relayer) ProcessPendingBatches() {
log.Error("UpdateCommitTxHashAndRollupStatus failed", "hash", dbBatch.Hash, "index", dbBatch.Index, "err", err)
return
}

var maxBlockHeight uint64
var totalGasUsed uint64
for _, dbChunk := range dbChunks {
if dbChunk.EndBlockNumber > maxBlockHeight {
maxBlockHeight = dbChunk.EndBlockNumber
}
totalGasUsed += dbChunk.TotalL2TxGas
}
r.metrics.rollupL2RelayerCommitBlockHeight.Set(float64(maxBlockHeight))
r.metrics.rollupL2RelayerCommitThroughput.Add(float64(totalGasUsed))

r.metrics.rollupL2RelayerProcessPendingBatchSuccessTotal.Inc()
log.Info("Sent the commitBatch tx to layer1", "batch index", dbBatch.Index, "batch hash", dbBatch.Hash, "tx hash", txHash.String())
}
Expand Down
11 changes: 11 additions & 0 deletions rollup/internal/controller/relayer/l2_relayer_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type l2RelayerMetrics struct {
rollupL2RelayerProcessPendingBundlesFinalizedSuccessTotal prometheus.Counter
rollupL2BundlesFinalizedConfirmedTotal prometheus.Counter
rollupL2BundlesFinalizedConfirmedFailedTotal prometheus.Counter

rollupL2RelayerCommitBlockHeight prometheus.Gauge
rollupL2RelayerCommitThroughput prometheus.Counter
}

var (
Expand Down Expand Up @@ -123,6 +126,14 @@ func initL2RelayerMetrics(reg prometheus.Registerer) *l2RelayerMetrics {
Name: "rollup_layer2_bundles_finalized_confirmed_failed_total",
Help: "Total number of failed confirmations for finalized bundles on layer2.",
}),
rollupL2RelayerCommitBlockHeight: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
Name: "rollup_l2_relayer_commit_block_height",
Help: "The latest block height committed by the L2 relayer",
}),
rollupL2RelayerCommitThroughput: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Name: "rollup_l2_relayer_commit_throughput",
Help: "The cumulative gas used in blocks committed by the L2 relayer",
}),
}
})
return l2RelayerMetric
Expand Down
23 changes: 23 additions & 0 deletions rollup/internal/controller/watcher/batch_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type BatchProposer struct {

// total number of times that batch proposer stops early due to compressed data compatibility breach
compressedDataCompatibilityBreachTotal prometheus.Counter

batchProposeBlockHeight prometheus.Gauge
batchProposeThroughput prometheus.Counter
}

// NewBatchProposer creates a new BatchProposer instance.
Expand Down Expand Up @@ -134,6 +137,14 @@ func NewBatchProposer(ctx context.Context, cfg *config.BatchProposerConfig, chai
Name: "rollup_propose_batch_estimate_blob_size_time",
Help: "Time taken to estimate blob size for the chunk.",
}),
batchProposeBlockHeight: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
Name: "rollup_batch_propose_block_height",
Help: "The block height of the latest proposed batch",
}),
batchProposeThroughput: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Name: "rollup_batch_propose_throughput",
Help: "The total gas used in proposed batches",
}),
}

return p
Expand Down Expand Up @@ -195,6 +206,18 @@ func (p *BatchProposer) updateDBBatchInfo(batch *encoding.Batch, codecVersion en
p.recordAllBatchMetrics(metrics)
}

if len(batch.Chunks) > 0 && len(batch.Chunks[len(batch.Chunks)-1].Blocks) > 0 {
lastChunk := batch.Chunks[len(batch.Chunks)-1]
lastBlock := lastChunk.Blocks[len(lastChunk.Blocks)-1]
p.batchProposeBlockHeight.Set(float64(lastBlock.Header.Number.Uint64()))
}

var totalGasUsed uint64
for _, chunk := range batch.Chunks {
totalGasUsed += chunk.L2GasUsed()
}
p.batchProposeThroughput.Add(float64(totalGasUsed))

p.proposeBatchUpdateInfoTotal.Inc()
err := p.db.Transaction(func(dbTX *gorm.DB) error {
dbBatch, dbErr := p.batchOrm.InsertBatch(p.ctx, batch, codecConfig, *metrics, dbTX)
Expand Down
16 changes: 16 additions & 0 deletions rollup/internal/controller/watcher/chunk_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ type ChunkProposer struct {

// total number of times that chunk proposer stops early due to compressed data compatibility breach
compressedDataCompatibilityBreachTotal prometheus.Counter

chunkProposeBlockHeight prometheus.Gauge
chunkProposeThroughput prometheus.Counter
}

// NewChunkProposer creates a new ChunkProposer instance.
Expand Down Expand Up @@ -150,6 +153,14 @@ func NewChunkProposer(ctx context.Context, cfg *config.ChunkProposerConfig, chai
Name: "rollup_propose_chunk_estimate_blob_size_time",
Help: "Time taken to estimate blob size for the chunk.",
}),
chunkProposeBlockHeight: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
Name: "rollup_chunk_propose_block_height",
Help: "The block height of the latest proposed chunk",
}),
chunkProposeThroughput: promauto.With(reg).NewCounter(prometheus.CounterOpts{
Name: "rollup_chunk_propose_throughput",
Help: "The total gas used in proposed chunks",
}),
}

return p
Expand Down Expand Up @@ -214,6 +225,11 @@ func (p *ChunkProposer) updateDBChunkInfo(chunk *encoding.Chunk, codecVersion en
p.recordAllChunkMetrics(metrics)
}

if len(chunk.Blocks) > 0 {
p.chunkProposeBlockHeight.Set(float64(chunk.Blocks[len(chunk.Blocks)-1].Header.Number.Uint64()))
}
p.chunkProposeThroughput.Add(float64(chunk.L2GasUsed()))

p.proposeChunkUpdateInfoTotal.Inc()
err := p.db.Transaction(func(dbTX *gorm.DB) error {
dbChunk, err := p.chunkOrm.InsertChunk(p.ctx, chunk, codecConfig, *metrics, dbTX)
Expand Down
1 change: 1 addition & 0 deletions rollup/internal/controller/watcher/l2_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func (w *L2WatcherClient) getAndStoreBlocks(ctx context.Context, from, to uint64
return fmt.Errorf("failed to estimate block L1 commit calldata size: %v", err)
}
w.metrics.rollupL2BlockL1CommitCalldataSize.Set(float64(blockL1CommitCalldataSize))
w.metrics.rollupL2WatcherSyncThroughput.Add(float64(block.Header.GasUsed))
}
if err := w.l2BlockOrm.InsertL2Blocks(w.ctx, blocks); err != nil {
return fmt.Errorf("failed to batch insert BlockTraces: %v", err)
Expand Down
6 changes: 6 additions & 0 deletions rollup/internal/controller/watcher/l2_watcher_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type l2WatcherMetrics struct {
rollupL2BlocksFetchedGap prometheus.Gauge
rollupL2BlockL1CommitCalldataSize prometheus.Gauge
fetchNilRowConsumptionBlockTotal prometheus.Counter

rollupL2WatcherSyncThroughput prometheus.Counter
}

var (
Expand Down Expand Up @@ -43,6 +45,10 @@ func initL2WatcherMetrics(reg prometheus.Registerer) *l2WatcherMetrics {
Name: "rollup_l2_watcher_fetch_nil_row_consumption_block_total",
Help: "The total number of occurrences where a fetched block has nil RowConsumption",
}),
rollupL2WatcherSyncThroughput: prometheus.NewCounter(prometheus.CounterOpts{
Name: "rollup_l2_watcher_sync_throughput",
Help: "The cumulative gas used in blocks that L2 watcher sync",
}),
}
})
return l2WatcherMetric
Expand Down

0 comments on commit 404a625

Please sign in to comment.