Commit dbfee2d
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- bin/ethlambda/src
- crates/blockchain/src
2 files changed
+326
-233
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
0 commit comments