Skip to content

feat: add metrics, health endpoint, and structured logging (#441)#447

Open
morelucks wants to merge 1 commit intoleanEthereum:mainfrom
morelucks:feat/node-observability
Open

feat: add metrics, health endpoint, and structured logging (#441)#447
morelucks wants to merge 1 commit intoleanEthereum:mainfrom
morelucks:feat/node-observability

Conversation

@morelucks
Copy link

Implements #441 — adds Prometheus metrics, a health endpoint, and structured JSON logging to leanspec-node.

Changes

Prometheus Metrics (/metrics)

Exposes 7 metrics in Prometheus text exposition format:

Metric Type Source
leanspec_slot_current Gauge Periodic logging loop
leanspec_epoch_current Gauge slot // JUSTIFICATION_LOOKBACK_SLOTS
leanspec_peers_connected Gauge Periodic logging loop
leanspec_blocks_imported_total Counter SyncService._process_block_wrapper
leanspec_attestations_processed_total Counter SyncService attestation handlers
leanspec_sync_distance Gauge Network finalized vs local head
leanspec_process_start_time_seconds Gauge Set at startup

Each Metrics instance uses its own CollectorRegistry to avoid global state collisions in tests.

Health Endpoint (GET /health)

Returns {"status": "ok", "slot": N, "synced": bool} with:

  • 200 when synced
  • 503 when not synced

Sync status determined by SyncService.state.is_synced — suitable for Docker/Kubernetes readiness probes.

Structured Logging

  • --log-format json enables JSON output via python-json-logger
  • Includes slot, epoch, peers, peer_id as structured fields
  • --log-level CLI flag (defaults to LEANSPEC_LOG_LEVEL env var)

Docker & Deployment

  • EXPOSE 8008 in Dockerfile node stage
  • docker-compose.observability.yml with Prometheus + Grafana sidecar
  • observability/prometheus.yml and observability/grafana/dashboard.json
  • DOCKER_QUICKSTART.md updated with metrics & observability docs

CLI Flags

Flag Description
--metrics-port PORT Enable metrics/health server on given port
--log-format {text,json} Log output format (default: text)
--log-level LEVEL Log level (default: INFO or LEANSPEC_LOG_LEVEL)

Acceptance Criteria

  • /metrics endpoint returns valid Prometheus text exposition format
  • /health endpoint returns correct synced field based on sync state
  • Structured JSON log output when --log-format json is set
  • Metrics port configurable via --metrics-port CLI flag
  • Dockerfile node stage exposes the metrics port
  • At least one example Grafana dashboard JSON included

closes #441

…eum#441)

- Prometheus metrics: slot_current, epoch_current, peers_connected,
  blocks_imported_total, attestations_processed_total, sync_distance,
  process_start_time_seconds exposed via /metrics endpoint
- Health endpoint: GET /health returns {status, slot, synced} with
  200 when synced, 503 otherwise (K8s readiness probe compatible)
- Structured JSON logging via --log-format json with slot, epoch,
  peer_id fields; log level via --log-level / LEANSPEC_LOG_LEVEL
- CLI: --metrics-port flag to enable metrics/health server
- Docker: EXPOSE 8008, docker-compose with Prometheus + Grafana
- Docs: DOCKER_QUICKSTART.md updated with observability section
- Grafana dashboard JSON included in observability/
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.

node: add metrics and observability

1 participant