feat: metrics for message pool internal maps#7133
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
WalkthroughAdds shrink-to-fit memory trimming and a Prometheus collector for the message-pool pending map; replaces the map implementation. Also trims HashMap/sets capacity in chain follower hotspots after updates. ChangesPending Pool Memory Management and Metrics
Chain follower capacity trims
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/message_pool/msgpool/pending_store.rs (1)
146-193: 💤 Low valueOptional: collapse the three near-identical gauge blocks into a helper.
The size/len/cap blocks differ only by name, help, unit, and value. A small local closure removes the copy-paste (and the stale
size_metric_encodername reused in the len/cap blocks).♻️ Sketch
let mut encode_gauge = |name: &str, help: &str, unit: Option<&Unit>, value: i64| -> Result<(), std::fmt::Error> { let g: Gauge = Default::default(); g.set(value); let e = encoder.encode_descriptor(name, help, unit, g.metric_type())?; g.encode(e) }; let pending = self.pending.read(); encode_gauge("mpool_pending_size", "...", Some(&Unit::Bytes), pending.allocation_size() as i64)?; encode_gauge("mpool_pending_len", "...", None, pending.len() as i64)?; encode_gauge("mpool_pending_cap", "...", None, pending.capacity() as i64)?;Reading the lock once also gives a consistent snapshot across the three gauges.
🤖 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 `@src/message_pool/msgpool/pending_store.rs` around lines 146 - 193, The three nearly identical Gauge blocks inside InnerMetricsCollector::encode should be collapsed into a small helper/closure to avoid repetition and the stale variable name; read the pending lock once into a local (e.g., let pending = self.pending.read()) to get a consistent snapshot, then create a closure like encode_gauge(name, help, unit, value) that creates a Gauge, sets it, calls encoder.encode_descriptor(...) and then encodes the gauge; call this helper for "mpool_pending_size" (Some(&Unit::Bytes), pending.allocation_size() as i64), "mpool_pending_len" (None, pending.len() as i64) and "mpool_pending_cap" (None, pending.capacity() as i64) within InnerMetricsCollector::encode.
🤖 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.
Inline comments:
In `@src/message_pool/msgpool/pending_store.rs`:
- Around line 154-160: The metric help text for "mpool_pending_size" is
misleading: size_in_bytes is computed from hashbrown::HashMap::allocation_size()
which only measures the map's table/bucket allocation and does not include heap
memory held by MsgSet values; update the descriptor passed to
encoder.encode_descriptor (for "mpool_pending_size") to explicitly state it
measures the hash map's internal table/bucket allocation (not total
pending-message heap) so dashboards/alerts are not misled; keep the metric name
and units unchanged and only change the help string referenced where
size_in_bytes and encoder.encode_descriptor are used.
- Around line 44-53: PendingStore::new currently calls
crate::metrics::register_collector(Box::new(InnerMetricsCollector(inner.shallow_clone())))
unconditionally, which causes duplicate metric registration when multiple
MessagePool::new run; change this so the collector is registered only once (or
use a guarded/conditional registration) — e.g., add a check/once-guard around
register_collector or move registration out of PendingStore::new into a single
initialization path (call site for MessagePool::new), or have
InnerMetricsCollector register itself idempotently (check registry for existing
collector name) before calling register_collector; update references to
PendingStore::new, InnerMetricsCollector, register_collector and
MessagePool::new accordingly to ensure only one collector registration per
process.
---
Nitpick comments:
In `@src/message_pool/msgpool/pending_store.rs`:
- Around line 146-193: The three nearly identical Gauge blocks inside
InnerMetricsCollector::encode should be collapsed into a small helper/closure to
avoid repetition and the stale variable name; read the pending lock once into a
local (e.g., let pending = self.pending.read()) to get a consistent snapshot,
then create a closure like encode_gauge(name, help, unit, value) that creates a
Gauge, sets it, calls encoder.encode_descriptor(...) and then encodes the gauge;
call this helper for "mpool_pending_size" (Some(&Unit::Bytes),
pending.allocation_size() as i64), "mpool_pending_len" (None, pending.len() as
i64) and "mpool_pending_cap" (None, pending.capacity() as i64) within
InnerMetricsCollector::encode.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: c60327c3-583c-4ecf-b24d-1a96a604280d
📒 Files selected for processing (2)
src/message_pool/msgpool/pending_store.rssrc/message_pool/msgpool/reorg.rs
Codecov Report❌ Patch coverage is
Additional details and impacted files
... and 14 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Summary of changes
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes
Other information and links
Change checklist
Outside contributions
Summary by CodeRabbit
New Features
Improvements