Dependency check - #92
Merged
Merged
Conversation
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.
Here's a full summary of the changes I made:
Summary of Changes
1. Backend/src/routes/health.routes.ts — Separated liveness and readiness endpoints
I rewrote the health routes to implement two distinct endpoints:
GET /health— A lightweight liveness probe that returns only success, message, uptime, and timestamp. It no longer performs any dependency checks, making it fast and suitable for load balancers and container orchestrators.GET /health/ready— A readiness endpoint that checks Prisma ($queryRawUnsafe('SELECT 1')) and Redis (redis.status === 'ready') connectivity in parallel. It returns 200 with status: 'ok' when all dependencies are healthy, and 503 with status: 'degraded' when any critical dependency is unavailable. Error details are passed throughredactError()to avoid leaking connection strings or secrets.I also removed the
checkWorkersfunction and the workers check from the readiness probe, since workers are a background concern and not a critical dependency for API readiness. TheHealthChecktype andHealthStatustype were kept. ThegetBootstrappedWorkersimport was removed since it's no longer needed.2. Backend/src/middleware/requestId.ts — New request ID middleware (bonus)
I created a new middleware that generates a unique UUID for every incoming request via
crypto.randomUUID(), attaches it toreq.requestIdfor downstream use, and sets the X-Request-Id response header so clients can trace requests. This complements the health check work by making it easy to trace requests through logs when debugging dependency issues reported by the readiness endpoint.3. Backend/src/middleware/index.ts — Added requestId export
I added the requestId export to the middleware barrel file so it's available for import from app.ts.
4. Backend/src/app.ts — Registered requestId middleware
I imported requestId from the middleware module and registered it early in the middleware chain (before rate limiting and routes) so every request gets an ID from the start.
5. Backend/tests/unit/health.test.ts — Rewrote unit tests
I rewrote the unit tests with jest.mock for
../../src/databaseand../../src/config/redisto control Prisma and Redis states. The tests now cover:6. Backend/tests/integration/health.integration.test.ts — Rewrote integration tests
I rewrote the integration tests with the same mocking approach, covering the same healthy and simulated-unavailable-dependency scenarios, plus the existing 404 test.
All 12 health tests pass (6 unit + 6 integration). No changes were needed to Backend/src/config/index.ts or Backend/src/database/index.ts — the existing
redactErrorutility andPrisma/Redisexports already supported the implementation.RELATED ISSUE
CLOSES #81 ✔️