Skip to content

Commit 5e4a033

Browse files
committed
[server] ReadinessProbe: add redis as dependency
Tool: gitpod/catfood.gitpod.cloud
1 parent de921c8 commit 5e4a033

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

components/server/src/liveness/readiness-controller.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ import { SpiceDBClientProvider } from "../authorization/spicedb";
1111
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
1212
import { ReadSchemaRequest } from "@authzed/authzed-node/dist/src/v1";
1313
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
14+
import { Redis } from "ioredis";
1415

1516
@injectable()
1617
export class ReadinessController {
1718
@inject(TypeORM) protected readonly typeOrm: TypeORM;
1819
@inject(SpiceDBClientProvider) protected readonly spiceDBClientProvider: SpiceDBClientProvider;
20+
@inject(Redis) protected readonly redis: Redis;
1921

2022
get apiRouter(): express.Router {
2123
const router = express.Router();
@@ -55,7 +57,15 @@ export class ReadinessController {
5557
return;
5658
}
5759

58-
// Both connections are good
60+
// Check Redis connection
61+
const redisConnection = await this.checkRedisConnection();
62+
if (!redisConnection) {
63+
log.warn("Readiness check failed: Redis connection failed");
64+
res.status(503).send("Redis connection failed");
65+
return;
66+
}
67+
68+
// All connections are good
5969
res.status(200).send("Ready");
6070
} catch (error) {
6171
log.error("Readiness check failed", error);
@@ -91,4 +101,16 @@ export class ReadinessController {
91101
return false;
92102
}
93103
}
104+
105+
private async checkRedisConnection(): Promise<boolean> {
106+
try {
107+
// Simple PING command to verify connection is working
108+
const result = await this.redis.ping();
109+
log.debug("Redis connection check successful", { result });
110+
return result === "PONG";
111+
} catch (error) {
112+
log.error("Redis connection check failed", error);
113+
return false;
114+
}
115+
}
94116
}

memory-bank/activeContext.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@ Initial exploration of the Gitpod codebase has revealed:
149149
- Manages complex dependencies between components
150150
- **Server Health Checks**: The Gitpod server uses two distinct health check mechanisms:
151151
- **Liveness Probe**: Checks the event loop lag to determine if the server is functioning properly
152-
- **Readiness Probe**: Checks database and SpiceDB connectivity to ensure the server is ready to handle requests
152+
- **Readiness Probe**: Checks database, SpiceDB, and Redis connectivity to ensure the server is ready to handle requests
153153
- Controlled by a ConfigCat feature flag `server_readiness_probe` (default: true) that can bypass the actual checks
154154
- **Critical Dependencies**: The server has critical external dependencies that must be operational:
155155
- **Database (TypeORM)**: Used for persistent storage
156156
- **SpiceDB**: Used for authorization and permission management
157+
- **Redis**: Used for caching, pub/sub messaging, and distributed locking
157158
- **Server Architecture Patterns**:
158159
- The server uses dependency injection (Inversify) for component management
159160
- Components are registered in `container-module.ts` and injected where needed

memory-bank/progress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,16 @@ No specific blockers or dependencies have been identified yet. This section will
212212
- Created PRD document for the readiness probe implementation
213213
- Updated Kubernetes deployment configuration to add the readiness probe
214214
- Added ConfigCat feature flag `server_readiness_probe` to control readiness checks
215+
- Enhanced server readiness probe with Redis health check:
216+
- Added Redis connectivity check to the ReadinessController
217+
- Updated PRD document to include Redis in the list of checked dependencies
218+
- Ensured the feature flag continues to work with the new Redis check
215219
- Updated memory bank with new learnings:
216220
- Added information about server health checks and critical dependencies
217221
- Documented server architecture patterns and dependency injection
218222
- Added information about Kubernetes deployment configuration
219223
- Documented feature flag implementation for readiness probe
224+
- Added Redis as a critical dependency for the server
220225
- Established standardized development workflows:
221226
- Created `workflows.md` to document standardized development processes
222227
- Documented the Product Requirements Document (PRD) workflow

prd/001-readinessprobe-server.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Overview
44

5-
This document outlines the implementation of a readiness probe for the Gitpod server deployment. The readiness probe will ensure that the server is only considered ready when it has established connections to both the database and SpiceDB authorizer.
5+
This document outlines the implementation of a readiness probe for the Gitpod server deployment. The readiness probe will ensure that the server is only considered ready when it has established connections to the database, SpiceDB authorizer, and Redis.
66

77
## Background
88

@@ -13,6 +13,7 @@ Currently, the server deployment has a liveness probe that checks the event loop
1313
1. Create a readiness endpoint in the server that checks:
1414
- Database connectivity
1515
- SpiceDB authorizer connectivity
16+
- Redis connectivity
1617
2. Configure the Kubernetes deployment to use this endpoint as a readiness probe
1718

1819
## Implementation Details
@@ -22,7 +23,8 @@ Currently, the server deployment has a liveness probe that checks the event loop
2223
We've created a new `ReadinessController` class in `components/server/src/liveness/readiness-controller.ts` that:
2324
- Checks database connectivity by executing a simple query
2425
- Checks SpiceDB connectivity by attempting to get a client
25-
- Returns a 200 status code only if both checks pass, otherwise returns a 503 status code
26+
- Checks Redis connectivity by executing a PING command
27+
- Returns a 200 status code only if all checks pass, otherwise returns a 503 status code
2628

2729
```typescript
2830
// components/server/src/liveness/readiness-controller.ts
@@ -147,8 +149,8 @@ ReadinessProbe: &corev1.Probe{
147149

148150
The readiness probe should be tested to ensure:
149151

150-
1. The server is only considered ready when both database and SpiceDB connections are established
151-
2. The server is not considered ready if either connection fails
152+
1. The server is only considered ready when database, SpiceDB, and Redis connections are established
153+
2. The server is not considered ready if any connection fails
152154
3. The server becomes ready again when connections are re-established
153155

154156
## Deployment Considerations
@@ -161,7 +163,7 @@ The readiness probe should be tested to ensure:
161163

162164
The readiness probe implementation includes a ConfigCat feature flag called `server_readiness_probe` that controls whether the actual connectivity checks are performed:
163165

164-
- When the flag is set to `true` (default): The readiness probe will always return a 200 status code, bypassing the actual database and SpiceDB connectivity checks
166+
- When the flag is set to `true` (default): The readiness probe will always return a 200 status code, bypassing the actual database, SpiceDB, and Redis connectivity checks
165167
- When the flag is set to `false`: The readiness probe will perform the actual checks and return the appropriate status code based on the results
166168

167169
This feature flag provides several benefits:
@@ -173,9 +175,10 @@ This feature flag provides several benefits:
173175
## Future Improvements
174176

175177
- Add more sophisticated checks for SpiceDB connectivity, such as a simple permission check
178+
- Add more sophisticated checks for Redis connectivity, such as a simple key-value operation
176179
- Add metrics for readiness probe failures
177180
- Consider adding more dependencies to the readiness check as needed
178181

179182
## Conclusion
180183

181-
This implementation ensures that the server is only considered ready when it has established connections to both the database and SpiceDB authorizer. This improves the reliability of the deployment by preventing traffic from being sent to instances that are not fully initialized.
184+
This implementation ensures that the server is only considered ready when it has established connections to the database, SpiceDB authorizer, and Redis. This improves the reliability of the deployment by preventing traffic from being sent to instances that are not fully initialized.

0 commit comments

Comments
 (0)