feat: add /api/quotas/health dependency probe - #1060
Merged
greatest0fallt1me merged 1 commit intoJul 29, 2026
Conversation
Adds a health probe for the /api/quotas route group, reporting the status
of its external dependencies (currently the shared PostgreSQL database,
which backs quota-request persistence and usage aggregation).
- src/routes/quotas/health.ts: GET / handler reusing the existing
checkDatabase/sanitizeCheck infrastructure from
src/services/healthCheck.ts and src/routes/health/dependencies.ts, so
the response shape ({ status, timestamp, dependencies }) and error
sanitization rules match the app's other dependency probes. Applies the
same correlationMiddleware and quotasDrainTracker used by
src/routes/quotas/counts.ts for structured logging and graceful
shutdown.
- src/routes/quotas.ts: mount the new router at /api/quotas/health,
after the shared per-user token-bucket rate limiter (same protection
as every other /api/quotas route).
- docs/quotas-health-probe.md + README.md: document the endpoint,
response shape, status codes, and correlation ID behavior.
- src/routes/quotas/health.test.ts: 8 tests covering healthy/down
database status, error sanitization, dependency key set, correlation
ID echo/generation, default pool wiring, and drain-tracker
compatibility (93% line coverage on the new route file).
Closes CalloraOrg#773
|
@emteebug12-jpg 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! 🚀 |
Contributor
|
Solid — merged 🎉 |
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
Adds
GET /api/quotas/health, a health probe reporting the status of the external dependencies the/api/quotasroute group relies on.Today that's the shared PostgreSQL database, which backs quota-request persistence and the usage aggregation
/api/quotas/countsdepends on. The response shape ({ status, timestamp, dependencies }) and error-sanitization rules intentionally mirror the existingGET /api/health/dependenciesprobe, reusing itscheckDatabase()/sanitizeCheck()helpers rather than duplicating that logic, so ops tooling can treat every dependency probe in the app the same way.src/routes/quotas/health.ts(new): the probe router. Applies the samecorrelationMiddlewareandquotasDrainTrackeralready used bysrc/routes/quotas/counts.ts, so it getsX-Correlation-Idpropagation and graceful-shutdown draining consistent with the rest of/api/quotas. Accepts an injectablepoolfor tests; defaults to the shared app pool otherwise. No auth required — same as the global dependencies probe, since it exposes no tenant data.src/routes/quotas.ts: mounts the new router at/api/quotas/health, after the shared per-user token-bucket rate limiter — the probe is protected by the same rate limit as every other/api/quotasendpoint, it isn't a bypass.docs/quotas-health-probe.md(new) +README.md: document the endpoint, response shape, HTTP status codes, and correlation-ID behavior, and cross-link it alongside the existing health-probe docs.src/routes/quotas/health.test.ts(new): 8 focused tests.Closes #773
Test plan
npx jest src/routes/quotas/health.test.ts— 8/8 passing:okwhen the DB check succeeds; 503/downwhen it failsdependenciesonly ever containsdatabase(no other dependency exists today)x-correlation-id, or generated and returned in both the body andX-Correlation-Idheader when absentnpx jest --coverage --collectCoverageFrom='src/routes/quotas/health.ts' src/routes/quotas/health.test.ts— 93.33% line coverage (only the outer catch-all error branch, whichcheckDatabase()'s own try/catch makes practically unreachable, is uncovered — same acknowledged limitation as the existingsrc/routes/health/dependencies.test.tssuite).npx jest src/routes/quotas— no new failures. One pre-existing failure inquotas.ratelimit.test.ts(injects retryAfterMs into the error envelope) reproduces identically onmainwithout this branch's changes — unrelated to this PR.npx tsc --noEmit— no new type errors (2 pre-existing syntax errors onmain, insrc/controllers/authController.tsandsrc/routes/forecast.test.ts, reproduce identically without this branch).npx eslint src/routes/quotas.ts src/routes/quotas/health.ts src/routes/quotas/health.test.ts— clean.