Skip to content

feat(metrics): add cursor-paginated services breakdown to /api/v1/stats - #417

Merged
mikewheeleer merged 3 commits into
Agentpay-Org:mainfrom
thlpkee20-wq:feature/metrics-01-pagination
Jul 28, 2026
Merged

feat(metrics): add cursor-paginated services breakdown to /api/v1/stats#417
mikewheeleer merged 3 commits into
Agentpay-Org:mainfrom
thlpkee20-wq:feature/metrics-01-pagination

Conversation

@thlpkee20-wq

Copy link
Copy Markdown
Contributor

Closes #387

Adds servicesBreakdown (per-service tenantId/serviceId/
priceStroops/requestsOutstanding) to GET /api/v1/stats,
cursor-paginated via the shared paginateByCursor() helper (limit
default 50 / max 500, stable nextServicesBreakdownCursor). A malformed
or expired cursor returns 400 invalid_request.

/api/v1/metrics itself stays unpaginated Prometheus exposition text —
paginating a scrape target would break standard Prometheus clients, so
the listing/pagination work lands on /api/v1/stats instead.

Test plan

  • npm run build
  • npm run lint
  • npm test — targeted run of metrics.test.js,
    lifetime-metrics.test.js, settlement-metrics.test.js,
    etag-events-stats.test.js, routes/operational.test.js: 20/20
    passing.

Note

Stacked on #415 and #416 (same fork-only caveat noted on other PRs in
this series). The pagination-specific change is the servicesBreakdown
addition in src/routes/metrics.ts.

The health/deep checks handler inlined its own base64url cursor
encode/decode and page-slicing logic. Extracted it into a generic
paginateByCursor() in src/cursorPagination.ts (mirroring the offset
pagination helper already shared between the api-keys and webhooks list
endpoints) and refactored the health handler to use it. No behavior
change; this is the shared entry point subsequent metrics pagination
work will build on.
/api/v1/metrics and /api/v1/stats now reject any query parameter with a
structured 400 invalid_request; neither route accepts parameters today.
Adds servicesBreakdown (per-service tenantId/serviceId/priceStroops/
requestsOutstanding) to GET /api/v1/stats, cursor-paginated via the
shared paginateByCursor() helper (limit default 50, max 500, stable
nextServicesBreakdownCursor). /api/v1/metrics itself stays unpaginated
Prometheus exposition text, since paginating a scrape target would
break standard Prometheus clients.
@mikewheeleer

Copy link
Copy Markdown
Contributor

good stuff @thlpkee20-wq — clear and focused. merging 👏

@mikewheeleer
mikewheeleer merged commit 8217cfd into Agentpay-Org:main Jul 28, 2026
1 check failed
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 cursor pagination to the metrics listing endpoint

2 participants