Skip to content

Commit e43a38d

Browse files
committed
[server] Move /ready to /startup, and rename code to StartupController (because it's used by the StartupProbe)
Tool: gitpod/catfood.gitpod.cloud
1 parent fad0801 commit e43a38d

File tree

4 files changed

+15
-55
lines changed

4 files changed

+15
-55
lines changed

components/server/src/container-module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import { WebhookEventGarbageCollector } from "./jobs/webhook-gc";
7171
import { WorkspaceGarbageCollector } from "./jobs/workspace-gc";
7272
import { LinkedInService } from "./linkedin-service";
7373
import { LivenessController } from "./liveness/liveness-controller";
74-
import { ReadinessController } from "./liveness/readiness-controller";
74+
import { StartupController } from "./liveness/startup-controller";
7575
import { RedisSubscriber } from "./messaging/redis-subscriber";
7676
import { MonitoringEndpointsApp } from "./monitoring-endpoints";
7777
import { OAuthController } from "./oauth-server/oauth-controller";
@@ -245,7 +245,7 @@ export const productionContainerModule = new ContainerModule(
245245

246246
bind(ProbesApp).toSelf().inSingletonScope();
247247
bind(LivenessController).toSelf().inSingletonScope();
248-
bind(ReadinessController).toSelf().inSingletonScope();
248+
bind(StartupController).toSelf().inSingletonScope();
249249

250250
bind(OneTimeSecretServer).toSelf().inSingletonScope();
251251

components/server/src/liveness/probes.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as http from "http";
88
import express from "express";
99
import { inject, injectable } from "inversify";
1010
import { LivenessController } from "./liveness-controller";
11-
import { ReadinessController } from "./readiness-controller";
11+
import { StartupController } from "./startup-controller";
1212
import { AddressInfo } from "net";
1313

1414
@injectable()
@@ -18,17 +18,15 @@ export class ProbesApp {
1818

1919
constructor(
2020
@inject(LivenessController) protected readonly livenessController: LivenessController,
21-
@inject(ReadinessController) protected readonly readinessController: ReadinessController,
21+
@inject(StartupController) protected readonly startupController: StartupController,
2222
) {
2323
const probesApp = express();
2424
probesApp.use("/live", this.livenessController.apiRouter);
25-
probesApp.use("/ready", this.readinessController.apiRouter);
25+
probesApp.use("/startup", this.startupController.apiRouter);
2626
this.app = probesApp;
2727
}
2828

2929
public async start(port: number): Promise<number> {
30-
await this.readinessController.start();
31-
3230
return new Promise((resolve, reject) => {
3331
const probeServer = this.app.listen(port, () => {
3432
resolve((<AddressInfo>probeServer.address()).port);
@@ -39,6 +37,5 @@ export class ProbesApp {
3937

4038
public async stop(): Promise<void> {
4139
this.httpServer?.close();
42-
await this.readinessController.stop();
4340
}
4441
}

components/server/src/liveness/readiness-controller.ts renamed to components/server/src/liveness/startup-controller.ts

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,73 +10,53 @@ import { TypeORM } from "@gitpod/gitpod-db/lib";
1010
import { SpiceDBClientProvider } from "../authorization/spicedb";
1111
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
1212
import { v1 } from "@authzed/authzed-node";
13-
import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server";
1413
import { Redis } from "ioredis";
15-
import { repeat } from "@gitpod/gitpod-protocol/lib/util/repeat";
16-
import { Disposable, DisposableCollection } from "@gitpod/gitpod-protocol";
1714

1815
@injectable()
19-
export class ReadinessController {
16+
export class StartupController {
2017
@inject(TypeORM) protected readonly typeOrm: TypeORM;
2118
@inject(SpiceDBClientProvider) protected readonly spiceDBClientProvider: SpiceDBClientProvider;
2219
@inject(Redis) protected readonly redis: Redis;
2320

24-
private readinessProbeEnabled: boolean = true;
25-
private disposables: DisposableCollection = new DisposableCollection();
26-
2721
get apiRouter(): express.Router {
2822
const router = express.Router();
29-
this.addReadinessHandler(router);
23+
this.addStartupHandler(router);
3024
return router;
3125
}
3226

33-
public async start() {
34-
this.disposables.push(this.startPollingFeatureFlag());
35-
}
36-
37-
public async stop() {
38-
this.disposables.dispose();
39-
}
40-
41-
protected addReadinessHandler(router: express.Router) {
27+
protected addStartupHandler(router: express.Router) {
4228
router.get("/", async (_, res) => {
4329
try {
44-
if (!this.readinessProbeEnabled) {
45-
log.debug("Readiness check skipped due to feature flag");
46-
res.status(200);
47-
return;
48-
}
49-
5030
// Check database connection
5131
const dbConnection = await this.checkDatabaseConnection();
5232
if (!dbConnection) {
53-
log.warn("Readiness check failed: Database connection failed");
33+
log.warn("Startup check failed: Database connection failed");
5434
res.status(503).send("Database connection failed");
5535
return;
5636
}
5737

5838
// Check SpiceDB connection
5939
const spiceDBConnection = await this.checkSpiceDBConnection();
6040
if (!spiceDBConnection) {
61-
log.warn("Readiness check failed: SpiceDB connection failed");
41+
log.warn("Startup check failed: SpiceDB connection failed");
6242
res.status(503).send("SpiceDB connection failed");
6343
return;
6444
}
6545

6646
// Check Redis connection
6747
const redisConnection = await this.checkRedisConnection();
6848
if (!redisConnection) {
69-
log.warn("Readiness check failed: Redis connection failed");
49+
log.warn("Startup check failed: Redis connection failed");
7050
res.status(503).send("Redis connection failed");
7151
return;
7252
}
7353

7454
// All connections are good
7555
res.status(200).send("Ready");
76-
log.debug("Readiness check successful");
56+
log.debug("Startup check successful");
7757
} catch (error) {
78-
log.error("Readiness check failed", error);
79-
res.status(503).send("Readiness check failed");
58+
log.error("Startup check failed", error);
59+
res.status(503).send("Startup check failed");
8060
}
8161
});
8262
}
@@ -121,21 +101,4 @@ export class ReadinessController {
121101
return false;
122102
}
123103
}
124-
125-
private startPollingFeatureFlag(): Disposable {
126-
return repeat(async () => {
127-
// Check feature flag first
128-
const readinessProbeEnabled = await getExperimentsClientForBackend().getValueAsync(
129-
"server_readiness_probe",
130-
true, // Default to readiness probe, skip if false
131-
{},
132-
);
133-
134-
log.debug("Feature flag server_readiness_probe updated", {
135-
readinessProbeEnabled,
136-
oldValue: this.readinessProbeEnabled,
137-
});
138-
this.readinessProbeEnabled = readinessProbeEnabled;
139-
}, 10_000);
140-
}
141104
}

install/installer/pkg/components/server/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
376376
StartupProbe: &corev1.Probe{
377377
ProbeHandler: corev1.ProbeHandler{
378378
HTTPGet: &corev1.HTTPGetAction{
379-
Path: "/ready",
379+
Path: "/startup",
380380
Port: intstr.IntOrString{
381381
Type: intstr.Int,
382382
IntVal: ProbesPort,

0 commit comments

Comments
 (0)