-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): add /healthz endpoint (#13834)
* feat(backend): add /healthz endpoint * feat(backend): also check meilisearch status if available * style: header * chore: no-store * chore: healthcheck.sh * style: format
- Loading branch information
1 parent
aafa669
commit 611e303
Showing
6 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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,6 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
export const readyRef = { value: false }; |
This file contains 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,54 @@ | ||
/* | ||
* SPDX-FileCopyrightText: syuilo and misskey-project | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
import { Inject, Injectable } from '@nestjs/common'; | ||
import * as Redis from 'ioredis'; | ||
import { DataSource } from 'typeorm'; | ||
import { bindThis } from '@/decorators.js'; | ||
import { DI } from '@/di-symbols.js'; | ||
import { readyRef } from '@/boot/ready.js'; | ||
import type { FastifyInstance, FastifyPluginOptions } from 'fastify'; | ||
import type { MeiliSearch } from 'meilisearch'; | ||
|
||
@Injectable() | ||
export class HealthServerService { | ||
constructor( | ||
@Inject(DI.redis) | ||
private redis: Redis.Redis, | ||
|
||
@Inject(DI.redisForPub) | ||
private redisForPub: Redis.Redis, | ||
|
||
@Inject(DI.redisForSub) | ||
private redisForSub: Redis.Redis, | ||
|
||
@Inject(DI.redisForTimelines) | ||
private redisForTimelines: Redis.Redis, | ||
|
||
@Inject(DI.db) | ||
private db: DataSource, | ||
|
||
@Inject(DI.meilisearch) | ||
private meilisearch: MeiliSearch | null, | ||
) {} | ||
|
||
@bindThis | ||
public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) { | ||
fastify.get('/', async (request, reply) => { | ||
reply.code(await Promise.all([ | ||
new Promise<void>((resolve, reject) => readyRef.value ? resolve() : reject()), | ||
this.redis.ping(), | ||
this.redisForPub.ping(), | ||
this.redisForSub.ping(), | ||
this.redisForTimelines.ping(), | ||
this.db.query('SELECT 1'), | ||
...(this.meilisearch ? [this.meilisearch.health()] : []), | ||
]).then(() => 200, () => 503)); | ||
reply.header('Cache-Control', 'no-store'); | ||
}); | ||
|
||
done(); | ||
} | ||
} |
This file contains 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 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