Skip to content

feat(cli): the public gateway serves its metrics on a loopback listener - #2611

Merged
thiras merged 2 commits into
mainfrom
feat/gateway-metrics
Oct 24, 2026
Merged

thiras merged 2 commits into
mainfrom
feat/gateway-metrics

Conversation

@thiras

@thiras thiras commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What

The public gateway exposes metrics (#2593, PR 4 of the plan): --metrics-listen <loopback addr> serves Prometheus text at GET /metrics on a second listener, for the operator's scraper only.

  • gateway/metrics.rs: hand-rolled text exposition, as sponsord's is (a registry crate would add its own shape for eight series). One unlabeled sibling counter per outcome, per appendix-observability § Reason splits; every series exports from the start at zero.
  • Series: decdn_gateway_bytes_served_total, decdn_gateway_requests_{ok,not_found,refused,allowance_exhausted}_total, decdn_gateway_pull_failures_{funding,other}_total, decdn_gateway_pulls_active (gauge). Counted at the final status in handle, per frame in next_frame, and by the pull guard for pulls in flight.
  • adr/appendix-gateway.md is new: the gateway's hosts, allowance, ranges and metric names, in STE. Registered in the ADR book list and the architecture appendix list; the observability appendix points to it outside its registry tables (the node's adr_registry_names_are_exported test still passes).

Stacked on #2610 (feat/gateway-range); the diff shown is against that branch. Part of #2593; the pointer PR follows.

Reviewer notes

metrics.rs is the whole module; the wiring in gateway.rs is handle (now a counting wrapper around answer), one line in next_frame, PullGuard::new/Drop, and serve_metrics. The flag requires --public-url and refuses a non-loopback address at startup.

Verification

Always:

  • pre-commit run on commit (all hooks passed; cargo deny findings are the known warn-only advisories)
  • CARGO_BUILD_WARNINGS=deny cargo clippy -p decdn-cli -p decdn-common -p decdn-e2e --all-targets --all-features: clean
  • cargo nextest run -p decdn-cli -p decdn-common -p decdn-e2e: 1520 passed
  • PR title uses an allowed type and the subject does not start with an uppercase letter

Only if touched:

  • adr/: make -C adr check-refs check-book-list passes, adr/architecture.md appendix list updated
  • A metric name: the names live in adr/appendix-gateway.md § Metrics; no dashboard in decdn/devops yet (the gateway has no deployment there; a follow-up once it does)
  • anvil e2e: cargo nextest run -p decdn-e2e --features anvil-e2e -E 'binary(gateway_public)' passes, now scraping the live listener (bytes served, one 402, refusals, zero pulls in flight)
  • CHANGELOG.md entry added by hand

🤖 Generated with Claude Code

@thiras thiras added kind:feature New capability or a change to current behavior area:cli decdn binary: get, gateway, pool, publish, origin, setup labels Oct 24, 2026
@thiras thiras self-assigned this Oct 24, 2026
thiras added a commit that referenced this pull request Oct 24, 2026
@thiras
thiras force-pushed the feat/gateway-range branch 2 times, most recently from 83d17a1 to 0332fe4 Compare October 24, 2026 18:11
Base automatically changed from feat/gateway-range to main October 24, 2026 18:11
thiras and others added 2 commits October 24, 2026 21:11
`--metrics-listen <addr>` serves Prometheus text at `GET /metrics` on a
loopback address: content bytes served, answers by outcome (ok, not found,
refused, allowance exhausted, pool cannot pay, upstream failed) as one
unlabeled sibling counter each, and pulls in flight as a gauge. Every
series exports from the start. The exposition is for the operator's
scraper; the listener takes a loopback address only, and nothing is served
without the flag. `adr/appendix-gateway.md` is the gateway's appendix: the
hosts it serves, the allowance, ranges, and the metric names; the
observability appendix points to it. Part of #2593.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@thiras
thiras force-pushed the feat/gateway-metrics branch from 2028cd5 to 6580cda Compare October 24, 2026 18:13
@thiras
thiras marked this pull request as ready for review October 24, 2026 18:13
Copilot AI balanced review requested due to automatic review settings October 24, 2026 18:13
@thiras
thiras merged commit d306fab into main Oct 24, 2026
1 check passed
@thiras
thiras deleted the feat/gateway-metrics branch October 24, 2026 18:13
thiras added a commit that referenced this pull request Oct 24, 2026
…2613)

The metrics entry and the `Range` entry (#2612) stand once each.

Co-authored-by: Claude Fable 5.1 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Served-byte and active-pull accounting misreport activity, and the changelog contains unresolved merge-conflict markers.

3 open issues
What changed in this PR

Adds an operator-only Prometheus endpoint to the public HTTP gateway, separate from its public content listener.

Changes:

  • Adds --metrics-listen, requiring public mode and a loopback address.
  • Instruments request outcomes, served bytes, pull failures, and active pulls, with unit and end-to-end coverage.
  • Documents gateway behavior, metric names, and container usage.
File Description
docker/​README.decdn.md Adds metrics configuration to the container example.
crates/​e2e/​tests/​gateway_public.rs Scrapes the live gateway and checks metrics.
crates/​common/​src/​cli/​gateway/​tests.rs Tests metrics flag parsing and public-mode requirement.
crates/​common/​src/​cli/​gateway.rs Defines --metrics-listen.
crates/​cli/​src/​commands/​gateway/​tests.rs Tests outcome counters and the metrics endpoint.
crates/​cli/​src/​commands/​gateway/​metrics/​tests.rs Tests initial exposition and counter updates.
crates/​cli/​src/​commands/​gateway/​metrics.rs Implements eight Prometheus series.
crates/​cli/​src/​commands/​gateway.rs Wires the loopback listener and activity accounting.
CHANGELOG.md Adds the metrics release note.
adr/​Makefile Includes the gateway appendix in the ADR book.
adr/​architecture.md Links the gateway appendix.
adr/​appendix-observability.md Points to the gateway metric definitions.
adr/​appendix-gateway.md Documents gateway behavior and metrics.

Review effort: Balanced

Comment on lines +1936 to +1938
if let Some(public) = &gateway.public {
public.metrics.bytes(chunk.len());
}
Comment on lines +2015 to +2016
if let Some(public) = &self.gateway.public {
public.metrics.pull_ended();
Comment thread CHANGELOG.md
Comment on lines +4092 to +4104
<<<<<<< HEAD
- **CLI: the gateway answers `Range` on a sized bundle entry (#2612).** An
=======
- **CLI: the public gateway serves its metrics on a loopback listener
(#2611).** `decdn gateway --public-url … --metrics-listen <addr>` serves
Prometheus text at `GET /metrics`: content bytes served, answers by outcome
(ok, not found, refused, allowance exhausted, pool cannot pay, upstream
failed) as one unlabeled sibling counter each, and pulls in flight as a
gauge. The listener takes a loopback address only. The series are listed in
`adr/appendix-gateway.md`, the gateway's new appendix. Part of #2593.

- **CLI: the gateway answers `Range` on a sized bundle entry (#2610).** An
>>>>>>> 2028cd53 (docs(changelog): note the gateway's metrics listener (#2611))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli decdn binary: get, gateway, pool, publish, origin, setup kind:feature New capability or a change to current behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants