Skip to content

Add Prometheus metrics and /metrics endpoint per leanMetrics spec#444

Open
ch4r10t33r wants to merge 4 commits intoleanEthereum:mainfrom
ch4r10t33r:metrics
Open

Add Prometheus metrics and /metrics endpoint per leanMetrics spec#444
ch4r10t33r wants to merge 4 commits intoleanEthereum:mainfrom
ch4r10t33r:metrics

Conversation

@ch4r10t33r
Copy link
Collaborator

Implements the metrics defined in leanEthereum/leanMetrics:

  • Metrics module (lean_spec.subspecs.metrics): Prometheus counters, gauges, and histograms for node info, head/safe/justified/finalized slots, state transition and attestation validation timing, reorgs, attestation validity, current slot, connected peers, and validator count.
  • API: /metrics endpoint on the existing API server (default port 5052, configurable via --api-port, use 0 to disable).
  • Instrumentation: Forkchoice store (block processing, state transition time, reorg depth), sync service (attestation validation), and node (periodic gauge updates from clock, store, peer manager, validator registry).

Dependencies: prometheus-client added; metrics are optional (guarded by import and runtime flag) so the node runs without them if unavailable.

@ch4r10t33r ch4r10t33r marked this pull request as ready for review March 10, 2026 11:34
@ch4r10t33r ch4r10t33r requested review from tcoratger and unnawut March 10, 2026 11:34
tcoratger and others added 2 commits March 10, 2026 23:24
…ockLookup class

- Convert BlockLookup from type alias to proper dict subclass with
  ancestors() generator and reorg_depth() method
- Replace module-level mutable globals in metrics registry with
  MetricsRegistry class using null object pattern (_NoOpMetric stubs)
- Eliminate all try/except ImportError guards and noqa: I001 suppressions
- Move _record_metrics_after_block into Store._record_metrics method
- Remove unused old_safe parameter from metrics recording
- Delete init_metrics backward compat wrapper, use metrics.init() directly
- Add comprehensive tests for BlockLookup (20 tests) and _record_metrics (12 tests)
- Update all consumers (store, sync/service, node, __main__) to use
  qualified metrics access

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dict.__or__ returns a plain dict, losing the BlockLookup type when
used in Pydantic model_copy(update={"blocks": self.blocks | {...}}).
Override returns BlockLookup so reorg_depth and ancestors remain
available after store updates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants