Skip to content

Service: Prometheus metrics at GET /metrics, gated by MONITORING_TOKEN - #43

Merged
kevinelliott merged 5 commits into
mainfrom
feature/prometheus-metrics
Nov 21, 2026
Merged

kevinelliott merged 5 commits into
mainfrom
feature/prometheus-metrics

Conversation

@kevinelliott

Copy link
Copy Markdown
Contributor

Requested by Kevin · project thread

Summary

Adds a Prometheus scrape endpoint to the coverage service, as part of the monitoring work (Prometheus and Grafana live in airframesio/stack).

This branch is built on top of #42 because #42 changes the health counters this mirrors. Until #42 merges, the diff here includes its four commits. The change that belongs to this PR is the last commit.

What it does

  • GET /metrics at the root of port 3002, Prometheus text format, using prom-client.
  • Port 3002 is public as coverage-api.airframes.io, so the route is gated the same way as api-server's metrics-token.guard.ts: the token comes in Authorization: Bearer <token> or X-Monitoring-Token, is compared in constant time, and the route answers 401 when MONITORING_TOKEN is not set. The public API routes are unchanged.
  • Every value is read at scrape time from the counters /api/v1/health already reports, so the two cannot disagree and the ingest path does no extra work beyond one new counter.

Metrics

Metric Notes
coverage_build_info{version,commit} commit comes from a new GIT_SHA build arg set by the Docker Push job
coverage_nats_connected, coverage_nats_messages_received_total, coverage_nats_messages_parsed_total, coverage_nats_parse_errors_total, coverage_nats_raw_positions_found_total
coverage_events_processed_total{source} source is the radio family: acars, vdl, hfdl, satcom, ais, unknown. New counter in the store, also shown on health as processedBySource
coverage_events_rejected_total{reason} fixed set of reasons
coverage_events_with_position_total, coverage_events_without_position_total
coverage_positions_discarded_total{reason}
coverage_positions_out_of_range_total{source,band} band is near or far, from #42's outOfRange
coverage_stations_tracked, coverage_active_cells{resolution}, coverage_cells_in_memory
coverage_marine_events_total{outcome}, coverage_marine_pending, coverage_marine_tracked_voyages outcome is paired, from_last_position, without_position, unknown_station
coverage_station_sync_last_success_timestamp_seconds 0 until the first success
coverage_snapshot_last_success_timestamp_seconds, coverage_snapshot_duration_seconds 0 until the first successful save
prom-client defaults process_resident_memory_bytes, process_cpu_seconds_total, process_start_time_seconds, nodejs_eventloop_lag_seconds, ...

No station ids, idents or other unbounded labels.

Testing

  • npm run typecheck, npm run build and npm test pass (48 tests, 9 new in test/metrics.test.ts: fails closed without the variable, rejects a missing or wrong token, accepts both header forms, values match /api/v1/health, no double counting across scrapes).
  • Ran the built service locally and scraped it: 401 without the token, full output with it.
  • Not tested: the Docker image build with the new GIT_SHA arg (no Docker in the sandbox; CI's Docker Build job covers it).

To deploy

Set MONITORING_TOKEN on the coverage stack in Dockhand (the same value Prometheus sends). Until it is set the route answers 401 and nothing else changes.


Generated by Claude Code

…mily

With marine coverage live, 7% of events were rejected by the 900 a minute
per-station limit, which was sized for aircraft receivers. Marine stations
now get 6000 a minute. The AIS range limit goes from 70 to 100 km (120 km
with the existing 20% margin). Health now reports rate-limited events by
transport and out-of-range positions by radio family, split into within
twice the limit and beyond it, so the remaining limits can be judged from
production numbers.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PS44Q7WRmAzMJLhi44dzdo
A busy receiver is legitimate, so coverage should not drop its events.
Replaces the higher marine limit from the previous commit.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PS44Q7WRmAzMJLhi44dzdo
Per-station message counts were summed from the H3 cells. A cell's count is
the total of every station that reported into it, so each station sharing a
cell was credited with all of them, and messages without a position were
not counted. Read the counts from the per-station sliding windows instead,
which record every accepted event once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PS44Q7WRmAzMJLhi44dzdo
Stations listed in AREA_FEED_STATIONS (default NCT, the Norwegian coastal
administration's national AIS feed) relay a whole area, not one antenna.
Their positions are kept at any distance and give the station no range or
direction of its own, the same way satellite relays are handled.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PS44Q7WRmAzMJLhi44dzdo
Mirrors the /api/v1/health counters with prom-client (prefix coverage_),
read at scrape time so the two cannot disagree. The port is public, so the
route needs MONITORING_TOKEN as a bearer token or X-Monitoring-Token,
compared in constant time, and answers 401 when the variable is unset.

Adds accepted events by radio family, last-success timestamps for the
station sync and snapshot save, and the build commit in the image.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PS44Q71yEaiXrKpFsgUpg1
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 35 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c27018e7-64db-4894-abfb-f67f4e6f19a2
Commits

Reviewing files that changed from the base of the PR and between a2908c3 and b8e8930.

Files ignored due to path filters: 1

  • service/package-lock.json is excluded by !**/package-lock.json
Files selected for processing: 18

  • .github/workflows/service.yml
  • service/CLAUDE.md
  • service/Dockerfile
  • service/package.json
  • service/src/aggregation/coverage-store.ts
  • service/src/aggregation/station-window.ts
  • service/src/api/routes/health.ts
  • service/src/api/routes/metrics.ts
  • service/src/api/server.ts
  • service/src/compute/signal-analysis.ts
  • service/src/config.ts
  • service/src/data/persistence.ts
  • service/src/metrics/job-status.ts
  • service/src/metrics/metrics.ts
  • service/src/sync/station-sync.ts
  • service/src/validation/rate-limiter.ts
  • service/test/ingest.test.ts
  • service/test/metrics.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@kevinelliott kevinelliott self-assigned this Nov 20, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying airframes-coverage with  Cloudflare Pages  Cloudflare Pages

Latest commit: b8e8930
Status: ✅  Deploy successful!
Preview URL: https://699e52ce.airframes-coverage.pages.dev
Branch Preview URL: https://feature-prometheus-metrics.airframes-coverage.pages.dev

View logs

@kevinelliott
kevinelliott merged commit f1a7052 into main Nov 21, 2026
9 checks passed
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