Skip to content

feat(metrics): expose ingestion-lag gauge at /metrics (Closes #237) - #453

Merged
khaylebfortune merged 2 commits into
sorotrail:mainfrom
codenerde:teste4567
Aug 3, 2026
Merged

feat(metrics): expose ingestion-lag gauge at /metrics (Closes #237)#453
khaylebfortune merged 2 commits into
sorotrail:mainfrom
codenerde:teste4567

Conversation

@codenerde

Copy link
Copy Markdown
Contributor

Summary

Completes #237 — the ingestion-lag gauge (sorotrail_ingestion_lag_ledgers) is now actually served at the /metrics endpoint and covered by table-driven tests.

The gauge itself (latest_rpc_ledger − last_ingested_ledger) is already tracked by the ingester via setIngestionLag, called after every poll pass that knows the chain head. What was missing:

  1. Exposure at /metrics — the API server's /metrics handler (HTTPMetrics.Handler) only gathered its per-server histogram registry, so the globally-registered sorotrail_ingestion_lag_ledgers gauge was never exported. It now gathers prometheus.DefaultGatherer alongside the per-server registry, so a single scrape sees the whole picture.
  2. Repair of a pre-existing compile breakHandler() in internal/metrics/metrics.go was missing its closing brace (leftover from an earlier bad merge), so the package did not compile. Fixed here.
  3. Tests — table-driven coverage of the gauge value and the /metrics export path.

Tests

  • internal/metrics/metrics_test.goTestIngestionLagGauge_ExportedAtMetrics: asserts the exact chain-head-minus-last-ingested value is exported at /metrics (caught up, small lag, deep lag, nothing-ingested-yet).
  • internal/ingester/ingester_test.goTestSetIngestionLag: asserts setIngestionLag computes chainHead − lastIngested exactly, is a no-op when either side is unknown (≤ 0), and preserves negative lag when a replay runs ahead of the reported head.
  • internal/api/server_test.goTestMetrics_ExposesIngestionLagGauge: end-to-end assertion that the API /metrics endpoint serves the gauge.

All new tests pass locally.

Validation

  • go build ./...
  • go vet ./...
  • golangci-lint run — no new issues from this change; the command currently reports pre-existing findings in unrelated in-flight work (cmd/sorotrail/main.go, internal/api/*, internal/ingester/ingester.go unused symbols / goimports).
  • go test ./... — the packages touched by this change pass; the full suite has pre-existing failures in unrelated WIP code (two TestEventsIngestedTotal_* cases and pkg/docs openapi drift) that predate this PR and are out of scope for Add an ingestion-lag gauge #237.

Scope

4 files changed, +91/−18. Purely observability: no changes to endpoints, config, or schema.

Closes #237

@khaylebfortune
khaylebfortune merged commit a73fe36 into sorotrail:main Aug 3, 2026
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.

Add an ingestion-lag gauge

3 participants