-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[server] Introduces ReadinessProbe #20669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0c1af2c
[server] Introduce ReadinessController and probe at /ready
geropl aedcdd7
[server] Move /live and /ready endpoints to a separate express app an…
geropl 5a57076
[memory-bank] task-related learnings
geropl f417382
[server] Introduce `server_readiness_probe` feature flag so we can di…
geropl de921c8
docs: formalize Product Requirements Document workflow
geropl 5e4a033
[server] ReadinessProbe: add redis as dependency
geropl 5819f53
review comments
geropl 6c8b811
[dev] Remove outdated gopls config
geropl 6437e49
[server] Fix import
geropl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| /** | ||
| * Copyright (c) 2025 Gitpod GmbH. All rights reserved. | ||
| * Licensed under the GNU Affero General Public License (AGPL). | ||
| * See License.AGPL.txt in the project root for license information. | ||
| */ | ||
|
|
||
| import express from "express"; | ||
| import { inject, injectable } from "inversify"; | ||
| import { LivenessController } from "./liveness-controller"; | ||
| import { ReadinessController } from "./readiness-controller"; | ||
|
|
||
| @injectable() | ||
| export class ProbesApp { | ||
| constructor( | ||
| @inject(LivenessController) protected readonly livenessController: LivenessController, | ||
| @inject(ReadinessController) protected readonly readinessController: ReadinessController, | ||
| ) {} | ||
|
|
||
| public create(): express.Application { | ||
| const probesApp = express(); | ||
| probesApp.use("/live", this.livenessController.apiRouter); | ||
| probesApp.use("/ready", this.readinessController.apiRouter); | ||
| return probesApp; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /** | ||
| * Copyright (c) 2025 Gitpod GmbH. All rights reserved. | ||
| * Licensed under the GNU Affero General Public License (AGPL). | ||
| * See License.AGPL.txt in the project root for license information. | ||
| */ | ||
|
|
||
| import { injectable, inject } from "inversify"; | ||
| import express from "express"; | ||
| import { TypeORM } from "@gitpod/gitpod-db/lib"; | ||
| import { SpiceDBClientProvider } from "../authorization/spicedb"; | ||
| import { log } from "@gitpod/gitpod-protocol/lib/util/logging"; | ||
| import { ReadSchemaRequest } from "@authzed/authzed-node/dist/src/v1"; | ||
| import { getExperimentsClientForBackend } from "@gitpod/gitpod-protocol/lib/experiments/configcat-server"; | ||
| import { Redis } from "ioredis"; | ||
|
|
||
| @injectable() | ||
| export class ReadinessController { | ||
| @inject(TypeORM) protected readonly typeOrm: TypeORM; | ||
| @inject(SpiceDBClientProvider) protected readonly spiceDBClientProvider: SpiceDBClientProvider; | ||
| @inject(Redis) protected readonly redis: Redis; | ||
|
|
||
| get apiRouter(): express.Router { | ||
| const router = express.Router(); | ||
| this.addReadinessHandler(router); | ||
| return router; | ||
| } | ||
|
|
||
| protected addReadinessHandler(router: express.Router) { | ||
| router.get("/", async (_, res) => { | ||
| try { | ||
| // Check feature flag first | ||
| const readinessProbeEnabled = await getExperimentsClientForBackend().getValueAsync( | ||
| "server_readiness_probe", | ||
| true, // Default to readiness probe, skip if false | ||
| {}, | ||
| ); | ||
|
|
||
| if (!readinessProbeEnabled) { | ||
| log.debug("Readiness check skipped due to feature flag"); | ||
| res.status(200); | ||
| return; | ||
| } | ||
|
|
||
| // Check database connection | ||
| const dbConnection = await this.checkDatabaseConnection(); | ||
| if (!dbConnection) { | ||
| log.warn("Readiness check failed: Database connection failed"); | ||
| res.status(503).send("Database connection failed"); | ||
| return; | ||
| } | ||
|
|
||
| // Check SpiceDB connection | ||
| const spiceDBConnection = await this.checkSpiceDBConnection(); | ||
| if (!spiceDBConnection) { | ||
| log.warn("Readiness check failed: SpiceDB connection failed"); | ||
| res.status(503).send("SpiceDB connection failed"); | ||
| return; | ||
| } | ||
|
|
||
| // Check Redis connection | ||
| const redisConnection = await this.checkRedisConnection(); | ||
| if (!redisConnection) { | ||
| log.warn("Readiness check failed: Redis connection failed"); | ||
| res.status(503).send("Redis connection failed"); | ||
| return; | ||
| } | ||
|
|
||
| // All connections are good | ||
| res.status(200).send("Ready"); | ||
| } catch (error) { | ||
| log.error("Readiness check failed", error); | ||
| res.status(503).send("Readiness check failed"); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| private async checkDatabaseConnection(): Promise<boolean> { | ||
| try { | ||
| const connection = await this.typeOrm.getConnection(); | ||
| // Simple query to verify connection is working | ||
| await connection.query("SELECT 1"); | ||
| return true; | ||
| } catch (error) { | ||
| log.error("Database connection check failed", error); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| private async checkSpiceDBConnection(): Promise<boolean> { | ||
| try { | ||
| const client = this.spiceDBClientProvider.getClient(); | ||
|
|
||
| // Send a request, to verify that the connection works | ||
| const req = ReadSchemaRequest.create({}); | ||
| const response = await client.readSchema(req); | ||
| log.debug("SpiceDB connection check successful", { schemaLength: response.schemaText.length }); | ||
|
|
||
| return true; | ||
| } catch (error) { | ||
| log.error("SpiceDB connection check failed", error); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| private async checkRedisConnection(): Promise<boolean> { | ||
| try { | ||
| // Simple PING command to verify connection is working | ||
| const result = await this.redis.ping(); | ||
| log.debug("Redis connection check successful", { result }); | ||
| return result === "PONG"; | ||
| } catch (error) { | ||
| log.error("Redis connection check failed", error); | ||
| return false; | ||
| } | ||
| } | ||
| } |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.