Skip to content

Commit dbfee2d

Browse files
authored
Eagerly register invalid counter metrics at startup (#245)
## Motivation Metrics using function-scoped `LazyLock` statics were only registered with Prometheus on first use. Counters that may never be incremented (e.g. invalid attestation counters) were entirely absent from `/metrics` output, causing: 1. **Dashboard gaps**: Panels show "No data" instead of `0` 2. **Alerting blind spots**: PromQL expressions like `rate(lean_attestations_invalid_total[5m]) > 0` silently fail when the metric doesn't exist Flagged by the [leanMetrics](https://github.com/leanEthereum/leanMetrics/) team during devnet-3 metrics review. ## Description Moves **all** blockchain metrics from function-scoped `LazyLock` statics to module-scoped statics, and adds a `metrics::init()` function that eagerly registers every metric at startup via `LazyLock::force()`. ### Changes - **`crates/blockchain/src/metrics.rs`**: All 28 metric statics (14 gauges, 10 counters, 8 histograms) are now at module scope, organized by type (Gauges / Counters / Histograms). The `init()` function forces all of them. Public API functions are now thin wrappers that reference the module-scope statics directly. - **`bin/ethlambda/src/main.rs`**: Calls `metrics::init()` at startup before other metric initialization. ### Why all metrics, not just the invalid counters? Per review feedback from @MegaRedHand — initializing all metrics makes the pattern consistent and ensures the full metric set is visible from the first Prometheus scrape. This also aligns with the module-scope style already used in `state_transition/src/metrics.rs` and `net/p2p/src/metrics.rs`. ## How to Test 1. Start a node: `cargo run` 2. Query the metrics endpoint: `curl localhost:5054/metrics` 3. All metrics should appear immediately, including zero-value counters: ``` lean_attestations_invalid_total 0 lean_pq_sig_aggregated_signatures_invalid_total 0 lean_pq_sig_attestation_signatures_invalid_total 0 lean_fork_choice_reorgs_total 0 ... ```
1 parent c6060d5 commit dbfee2d

File tree

2 files changed

+326
-233
lines changed

2 files changed

+326
-233
lines changed

bin/ethlambda/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ async fn main() -> eyre::Result<()> {
8181

8282
let options = CliOptions::parse();
8383

84-
// Set node info metrics
84+
// Initialize metrics
85+
ethlambda_blockchain::metrics::init();
8586
ethlambda_blockchain::metrics::set_node_info("ethlambda", version::CLIENT_VERSION);
8687
ethlambda_blockchain::metrics::set_node_start_time();
8788
ethlambda_blockchain::metrics::set_attestation_committee_count(

0 commit comments

Comments
 (0)