fix: healthz readiness should only fail if redis fails
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
import { isShuttingDown } from '@/utils/graceful-shutdown';
|
|
||||||
import { chQuery, db } from '@openpanel/db';
|
import { chQuery, db } from '@openpanel/db';
|
||||||
import { getRedisCache } from '@openpanel/redis';
|
import { getRedisCache } from '@openpanel/redis';
|
||||||
import type { FastifyReply, FastifyRequest } from 'fastify';
|
import type { FastifyReply, FastifyRequest } from 'fastify';
|
||||||
|
import { isShuttingDown } from '@/utils/graceful-shutdown';
|
||||||
|
|
||||||
// For docker compose healthcheck
|
// For docker compose healthcheck
|
||||||
export async function healthcheck(
|
export async function healthcheck(
|
||||||
request: FastifyRequest,
|
request: FastifyRequest,
|
||||||
reply: FastifyReply,
|
reply: FastifyReply
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
const redisRes = await getRedisCache().ping();
|
const redisRes = await getRedisCache().ping();
|
||||||
@@ -21,6 +21,7 @@ export async function healthcheck(
|
|||||||
ch: chRes && chRes.length > 0,
|
ch: chRes && chRes.length > 0,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
request.log.warn('healthcheck failed', { error });
|
||||||
return reply.status(503).send({
|
return reply.status(503).send({
|
||||||
ready: false,
|
ready: false,
|
||||||
reason: 'dependencies not ready',
|
reason: 'dependencies not ready',
|
||||||
@@ -41,18 +42,22 @@ export async function readiness(request: FastifyRequest, reply: FastifyReply) {
|
|||||||
|
|
||||||
// Perform lightweight dependency checks for readiness
|
// Perform lightweight dependency checks for readiness
|
||||||
const redisRes = await getRedisCache().ping();
|
const redisRes = await getRedisCache().ping();
|
||||||
const dbRes = await db.project.findFirst();
|
const dbRes = await db.$executeRaw`SELECT 1`;
|
||||||
const chRes = await chQuery('SELECT 1');
|
const chRes = await chQuery('SELECT 1');
|
||||||
|
|
||||||
const isReady = redisRes && dbRes && chRes;
|
const isReady = redisRes;
|
||||||
|
|
||||||
if (!isReady) {
|
if (!isReady) {
|
||||||
return reply.status(503).send({
|
const res = {
|
||||||
ready: false,
|
|
||||||
reason: 'dependencies not ready',
|
|
||||||
redis: redisRes === 'PONG',
|
redis: redisRes === 'PONG',
|
||||||
db: !!dbRes,
|
db: !!dbRes,
|
||||||
ch: chRes && chRes.length > 0,
|
ch: chRes && chRes.length > 0,
|
||||||
|
};
|
||||||
|
request.log.warn('dependencies not ready', res);
|
||||||
|
return reply.status(503).send({
|
||||||
|
ready: false,
|
||||||
|
reason: 'dependencies not ready',
|
||||||
|
...res,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user