Skip to content

feat(metrics): add HTTP request and payment settlement metrics - #207

Open
Hahfyeex wants to merge 3 commits into
StellarGateLabs:mainfrom
Hahfyeex:feat/issue-133-metrics-endpoint
Open

feat(metrics): add HTTP request and payment settlement metrics#207
Hahfyeex wants to merge 3 commits into
StellarGateLabs:mainfrom
Hahfyeex:feat/issue-133-metrics-endpoint

Conversation

@Hahfyeex

Copy link
Copy Markdown
Contributor

Summary

  • /metrics only exposed webhook delivery and auth outcome counters (AuthMetrics from fix(auth): log and count auth middleware decisions #206) — operators had no way to see request throughput/error rates or settlement latency without parsing logs, so the acceptance criteria (request + settlement + webhook metrics) wasn't met yet.
  • Adds RequestMetrics: HTTP requests counted by (method, matched route template, status) — the route is MatchedPath, not the raw path, so /payments/:id-style routes don't blow up cardinality — plus a latency histogram. Wired as the outermost middleware layer so it captures the final status (including a 408 from the timeout layer) and full request latency.
  • Adds SettlementMetrics: completed/overpaid/underpaid/expired counters plus a created-to-settled latency histogram, recorded at the two points a payment reaches a terminal state (horizon::settle() and expiry::sweep_once()). underpaid is counted but excluded from the latency histogram since the intent is still open; its eventual top-up records the real end-to-end latency.
  • Moves the time crate from dev- to regular dependencies to compute settlement latency from the stored RFC 3339 created_at.

Closes #133

Note: stacked on #206 (auth logging/metrics) and #205 (redrive backoff config), since it builds on the AuthMetrics render() pattern and the main.rs/task_health build fix from those. Diff will shrink to just this PR's changes as the earlier ones merge.

Test plan

  • cargo test — full suite passes (171 tests), including new tests asserting /metrics exposes route-labeled request counts + latency, and that a completed settlement is counted with a latency observation
  • cargo clippy --all-targets — clean (no new warnings)

Hahfyeex added 3 commits July 23, 2026 23:08
…#144)

WEBHOOK_REDRIVE_GRACE_SECS was a flat idle window, not the bounded
exponential backoff TODO.md Step 6 called for. Add
WEBHOOK_REDRIVE_BACKOFF_INITIAL_SECS / _MAX_SECS: a delivery that has
failed at least once now waits initial * 2^(attempts-1), capped at
max, before the redrive worker retries it. grace_secs remains a floor
so a row never touched (crash before its first send) isn't penalized.

Also repairs the build, which was broken on main: a bad merge
(13b49a2) duplicated the shutdown join_task! calls in main.rs, and
main.rs/expiry.rs's test fixture were missing the task_health field
added by an earlier PR.
auth_middleware returned 401 for missing/invalid keys with no structured
log, so credential-stuffing or a misconfigured client was invisible.
Every outcome (missing key, invalid key, lookup error, success) is now
logged with source_ip + reason at a level matched to severity, and
counted via a new AuthMetrics exposed on GET /metrics as
stellargate_auth_attempts_total{outcome,reason}, mirroring the existing
WebhookMetrics pattern.
…arGateLabs#133)

/metrics only exposed webhook delivery and auth outcome counters;
operators had no way to see request throughput/error rates or
settlement latency without parsing logs.

Adds RequestMetrics (counted by matched route template, method, and
status — not raw path, to keep cardinality bounded — plus a latency
histogram) wired as the outermost middleware layer so it captures the
final status including 408s from the timeout layer, and
SettlementMetrics (completed/overpaid/underpaid/expired counters plus
a created-to-settled latency histogram) recorded at the two points a
payment reaches a terminal state: horizon::settle() and
expiry::sweep_once(). Moves the `time` crate from dev- to regular
dependencies to compute settlement latency from stored RFC 3339
timestamps.
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.

No /metrics (Prometheus) endpoint

1 participant