Skip to content

Swagger docs (timeout, pagination) + oracle key validation + pool exhaustion monitoring - #481

Merged
nonsobethel0-dev merged 4 commits into
Parashield-Protocol:mainfrom
oss-dw:enhancement/docs-validation-467-471-472-473
Aug 28, 2026
Merged

Swagger docs (timeout, pagination) + oracle key validation + pool exhaustion monitoring#481
nonsobethel0-dev merged 4 commits into
Parashield-Protocol:mainfrom
oss-dw:enhancement/docs-validation-467-471-472-473

Conversation

@bbjiggy

@bbjiggy bbjiggy commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #467, Closes #471, Closes #472, Closes #473

Also includes one prerequisite commit fixing pre-existing build-breaking bugs found while working on these (missing import, an invalid object key, wrong relative import paths in the webhooks module, and an out-of-sync package-lock.json) — the project did not compile on main before this.

Test plan

  • npx tsc --noEmit — no new errors introduced (remaining errors are pre-existing and unrelated: auth.guards.spec.ts, claims.worker.ts/policy.controller.ts's paginated-products typing, rate-limit-headers.ts, policy.service.spec.ts)
  • npx jest src/health src/oracle src/claims — all tests in files touched by this PR pass; new tests added for pool exhaustion, oracle key format validation, and the new query-param validation
  • Verified against a stashed baseline of main that no previously-passing suite regressed

Found while working on other issues in this repo — the project did not
compile on main:

- policy.service.ts referenced StatusEventsService without importing it
- error-response.dto.ts used an invalid object key (400_bad, a numeric
  literal immediately followed by an identifier is not valid JS/TS)
- webhooks.service.ts / webhooks.controller.ts / webhooks.module.ts
  imported PrismaService/PrismaModule via a relative path one directory
  too shallow (../prisma/... instead of ../../prisma/...)
- package-lock.json was out of sync with package.json (missing
  OpenTelemetry and compression entries), so npm ci failed outright
…ashield-Protocol#471)

The health check already reported pool active/idle/waiting counts (Parashield-Protocol#444)
but never flagged exhaustion — operators had to interpret raw numbers
themselves and the health endpoint stayed "ok" even as the pool filled up.

- Compare active connections against the configured pool size
  (DATABASE_CONNECTION_LIMIT, default 10 — same default PrismaService
  applies) and compute a utilization percentage
- Mark the database check degraded once utilization meets or exceeds
  DB_POOL_EXHAUSTION_WARN_PERCENT (default 90%), consistent with how
  keeper balance and replication lag thresholds already work
- Extend DatabasePoolDto with max/utilizationPercent/exhausted

Also fixes health.controller.spec.ts's mock HealthController construction,
which was missing the required REDIS_CLIENT argument and the
checkRpcConnectivity() method on the Stellar mock (both added in earlier
commits after this spec was written), so every test in the file was
failing before any of my changes.
…-Protocol#473)

Oracle keys were never validated before use:

- GET /oracle/reading?key= and GET /oracle/latest/:key accepted any
  string, letting a malformed key fall through to a DB lookup that just
  resolves as a generic 404 instead of a clear "this was never a valid
  oracle key" 400
- POST /oracle/rainfall and GET /oracle/flight take lat/lng/year/month
  and flight/date as raw, unvalidated query params (unlike the DTO-backed
  POST /oracle/fetch/* endpoints) — an unparsable value silently became
  NaN and built a garbage oracle key/upstream request instead of failing
  loudly

Adds:
- oracle-key-format.ts: shared isValidOracleKeyFormat(), recognizing the
  three formats OracleService ever writes (rainfall/temperature with
  lat/lng bounds, flight)
- OracleKeyValidationMiddleware, registered on GET /oracle/reading and
  GET /oracle/latest/:key, rejecting a malformed key with 400 before it
  reaches the controller
- Bounds/format checks in getRainfall and getFlight, mirroring the
  validation OracleFeedRequestDto already applies to the POST endpoints
…arashield-Protocol#467, Parashield-Protocol#472)

Request timeout behavior (Parashield-Protocol#467) and pagination parameters (Parashield-Protocol#472) were
both applied consistently across the API but never written down anywhere
a caller could find them:

- New "Request Timeouts" section in the Swagger description: the 30s
  application-level + socket-level timeout, the 408 response, and that
  it deliberately does NOT use the standard error envelope (it's written
  directly by request-timeout middleware before the request reaches
  route handling, unlike every other documented error response)
- New "Pagination" section: page/limit defaults and clamping, the
  { success, data, total, page, limit } envelope, and which endpoints
  use it vs. the ?stream=true NDJSON alternative

Also brings claims.controller.ts's page/limit @apiquery descriptions
(GET /claims, GET /claims/history/:wallet) up to the same level of
detail policy.controller.ts's already had (default values, the 100 max,
examples) instead of the bare "Page number" / "Items per page" they had.
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@bbjiggy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@nonsobethel0-dev
nonsobethel0-dev merged commit 0af88dd into Parashield-Protocol:main Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants