feat(metrics): validate query params, paginate stats breakdown, extract cursor helper - #409
Closed
thlpkee20-wq wants to merge 4 commits into
Closed
feat(metrics): validate query params, paginate stats breakdown, extract cursor helper#409thlpkee20-wq wants to merge 4 commits into
thlpkee20-wq wants to merge 4 commits into
Conversation
The pr-404 merge left literal <<<<<<</=======/>>>>>>> markers in devDependencies, producing invalid JSON and breaking npm install for every contributor. Resolves to typescript@^6.0.3 with typescript-eslint@^8.65.0: the currently published typescript-eslint (8.65.0) only supports typescript <6.1.0, so pairing it with the typescript@^7.0.2 side of the conflict leaves the dependency tree unresolvable.
- Reject unknown query parameters on /health, /api/v1/health/ready, and /api/v1/health/deep with a structured 400 invalid_request. - Add a checks array to /api/v1/health/deep exposing per-subsystem status (event log, usage/services/webhook/API-key stores, memory), with opaque-cursor pagination (limit default 10, max 50) matching the existing events-log cursor contract. - Add docs/health.md covering all three routes, the new pagination contract, and error codes. - Add src/health-deep.test.ts covering success, pagination, malformed cursor, and unknown-query-param rejection.
- Extract the since/type/limit/cursor parsing preamble in GET /api/v1/events into parseEventsListQuery(), a single entry point for the bounded query contract. - Reject unknown query parameters on both /api/v1/events and /api/v1/events/summary with a structured 400 invalid_request, instead of silently ignoring typos. - Expand docs/events.md into a full API contract doc: both routes, request/response examples, and an error-codes table. - Add src/events-query-validation.test.ts covering the new rejection behavior and confirming documented parameters still work. Cursor pagination on the events listing (GrantFox Agentpay-Org#392) was already implemented prior to this change; this PR hardens and documents it rather than re-adding it.
…ct cursor helper - Extract the opaque-cursor pagination logic (previously duplicated inline in the health-checks handler) into a generic, reusable paginateByCursor() in src/cursorPagination.ts, and refactor the health route to use it. - Reject unknown query parameters on /api/v1/metrics and /api/v1/stats with a structured 400 invalid_request. - Add a cursor-paginated servicesBreakdown (per-service price and outstanding requests) to GET /api/v1/stats, using the same shared pagination helper (limit default 50, max 500). - Document both routes in docs/metrics.md, including the new stats contract, an example response, and an error-codes table. - Add src/stats-breakdown.test.ts covering pagination, malformed cursor, unknown-query-param rejection, and idempotent repeat requests.
Contributor
Author
|
Closing to re-split into one PR per issue instead of one PR per group. Follow-up PRs each closing a single issue are incoming. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #391
Closes #390
Closes #389
Closes #388
Closes #387
inline in the health-checks handler from Add cursor pagination to the health listing endpoint #397) into a generic,
reusable
paginateByCursor()insrc/cursorPagination.ts, andrefactored the health route to use it instead of its own
encode/decode pair.
/api/v1/metricsand/api/v1/statsnow reject any queryparameter outside their documented allow-list with a structured
400 invalid_request.servicesBreakdown(per-serviceprice and outstanding request count) to
GET /api/v1/stats, using thesame shared pagination helper (
limitdefault 50 / max 500, stablenextServicesBreakdownCursor)./api/v1/metricsitself staysunpaginated Prometheus exposition text, since paginating a scrape
target would break standard Prometheus clients.
docs/metrics.md: the new statscontract with an example response, and an error-codes table.
src/stats-breakdown.test.tscovering pagination(first/second page, total, stable cursor), malformed cursor,
unknown-query-param rejection on both routes, and an idempotent-repeat
check.
Test plan
npm run buildnpm run lintnpm test— targeted run ofstats-breakdown.test.js,lifetime-metrics.test.js,metrics.test.js,settlement-metrics.test.js,etag-events-stats.test.js,routes/operational.test.js,health-deep.test.js,openapi-routes.test.js: 30/30 passing.Note
Stacked on #406/#407/#408 for the reasons noted there; the metrics-group
change is
src/routes/meta.ts(cursor-helper refactor only),src/routes/metrics.ts,src/cursorPagination.ts,docs/metrics.md,and the new test file.