feat: initialize metrics on startup#1812
Conversation
📝 WalkthroughWalkthroughConstructors now seed rollup Prometheus gauges from persisted database or resumed watcher state. A committed-batch lookup supports relayer initialization, and the internal version tag advances to ChangesStartup metric initialization
Version update
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
rollup/internal/controller/watcher/chunk_proposer.go (1)
135-148: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueIgnore
gorm.ErrRecordNotFoundto prevent startup warnings on a fresh database.Like
BatchProposer.initializeMetrics, consider explicitly ignoringgorm.ErrRecordNotFound. Without this check, starting the service with an empty database will trigger a warning log sinceGetLatestChunkreturnsErrRecordNotFoundwhen no chunks exist yet.♻️ Proposed refactor
func (p *ChunkProposer) initializeMetrics(ctx context.Context) { latestChunk, err := p.chunkOrm.GetLatestChunk(ctx) if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return // no chunks proposed yet, nothing to seed + } log.Warn("failed to initialize chunk propose block height metric", "err", err) return }Ensure the
"errors"and"gorm.io/gorm"packages are imported at the top of the file if you apply this fix.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rollup/internal/controller/watcher/chunk_proposer.go` around lines 135 - 148, Update ChunkProposer.initializeMetrics to treat gorm.ErrRecordNotFound from GetLatestChunk as an expected empty-database condition: detect it with errors.Is and return without logging, while preserving the warning for other errors and the metric update for an existing latestChunk. Add the required errors and gorm imports.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@rollup/internal/controller/watcher/chunk_proposer.go`:
- Around line 135-148: Update ChunkProposer.initializeMetrics to treat
gorm.ErrRecordNotFound from GetLatestChunk as an expected empty-database
condition: detect it with errors.Is and return without logging, while preserving
the warning for other errors and the metric update for an existing latestChunk.
Add the required errors and gorm imports.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2cda3dd4-02e1-4b88-9350-e9276d4756f9
📒 Files selected for processing (7)
common/version/version.gorollup/internal/controller/relayer/l2_relayer.gorollup/internal/controller/watcher/batch_proposer.gorollup/internal/controller/watcher/chunk_proposer.gorollup/internal/controller/watcher/l1_watcher.gorollup/internal/controller/watcher/l2_watcher.gorollup/internal/orm/batch.go
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #1812 +/- ##
===========================================
+ Coverage 35.42% 35.44% +0.02%
===========================================
Files 262 262
Lines 22523 22596 +73
===========================================
+ Hits 7979 8010 +31
- Misses 13712 13748 +36
- Partials 832 838 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Several Prometheus block-height gauges (batch/chunk propose height, L2 relayer commit height, L1/L2 watcher processed height) reset to 0 on restart, so lag alerts fired until the next event repopulated them. This seeds each gauge from the DB at startup so it reflects the real height immediately.
An orthogonal fix is to add a
> 0condition to the alert rules. But initializing the metrics here seems more correct.Summary by CodeRabbit
New Features
Bug Fixes