mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-03 22:35:59 +00:00
Handeling the different health status
This commit is contained in:
@@ -173,15 +173,25 @@ async function handleResource(orgId: string, healthCheckTargetId?: number | null
|
||||
const otherTargets = await trx
|
||||
.select({ hcHealth: targetHealthCheck.hcHealth })
|
||||
.from(targets)
|
||||
.innerJoin(targetHealthCheck, eq(targetHealthCheck.targetId, targets.targetId))
|
||||
.where(eq(targets.resourceId, resource.resourceId));
|
||||
|
||||
let health = "healthy";
|
||||
const allHealthy = otherTargets.every((t) => t.hcHealth === "healthy");
|
||||
if (!allHealthy) {
|
||||
const allUnhealthy = otherTargets.every((t) => t.hcHealth === "unhealthy");
|
||||
|
||||
if (allHealthy) {
|
||||
health = "healthy";
|
||||
} else if (allUnhealthy) {
|
||||
logger.debug(
|
||||
`Not marking resource ${resource.resourceId} as healthy because not all targets are healthy`
|
||||
`Marking resource ${resource.resourceId} as unhealthy because all targets are unhealthy`
|
||||
);
|
||||
health = "unhealthy";
|
||||
} else {
|
||||
logger.debug(
|
||||
`Marking resource ${resource.resourceId} as degraded because some targets are unhealthy`
|
||||
);
|
||||
health = "degraded";
|
||||
}
|
||||
|
||||
if (health != resource.health) {
|
||||
|
||||
@@ -141,7 +141,8 @@ export async function createHealthCheck(
|
||||
hcStatus: hcStatus ?? null,
|
||||
hcTlsServerName: hcTlsServerName ?? null,
|
||||
hcHealthyThreshold,
|
||||
hcUnhealthyThreshold
|
||||
hcUnhealthyThreshold,
|
||||
hcHealth: "unhealthy"
|
||||
})
|
||||
.returning();
|
||||
|
||||
|
||||
@@ -166,6 +166,17 @@ export async function updateHealthCheck(
|
||||
|
||||
const updateData: Record<string, unknown> = {};
|
||||
|
||||
const [existingHealthCheck] = await db
|
||||
.select()
|
||||
.from(targetHealthCheck)
|
||||
.where(
|
||||
and(
|
||||
eq(targetHealthCheck.targetHealthCheckId, healthCheckId),
|
||||
eq(targetHealthCheck.orgId, orgId)
|
||||
)
|
||||
)
|
||||
.limit(1);
|
||||
|
||||
if (name !== undefined) updateData.name = name;
|
||||
if (siteId !== undefined) updateData.siteId = siteId;
|
||||
if (hcEnabled !== undefined) updateData.hcEnabled = hcEnabled;
|
||||
@@ -190,6 +201,26 @@ export async function updateHealthCheck(
|
||||
if (hcUnhealthyThreshold !== undefined)
|
||||
updateData.hcUnhealthyThreshold = hcUnhealthyThreshold;
|
||||
|
||||
const hcEnabledTurnedOn =
|
||||
parsedBody.data.hcEnabled === true &&
|
||||
existingHealthCheck.hcEnabled === false;
|
||||
|
||||
let hcHealthValue: "unknown" | "healthy" | "unhealthy" | undefined;
|
||||
if (
|
||||
parsedBody.data.hcEnabled === false ||
|
||||
parsedBody.data.hcEnabled === null
|
||||
) {
|
||||
hcHealthValue = "unknown";
|
||||
} else if (hcEnabledTurnedOn) {
|
||||
hcHealthValue = "unhealthy";
|
||||
} else {
|
||||
hcHealthValue = undefined;
|
||||
}
|
||||
|
||||
if (hcHealthValue) {
|
||||
updateData.hcHealth = hcHealthValue;
|
||||
}
|
||||
|
||||
const [updated] = await db
|
||||
.update(targetHealthCheck)
|
||||
.set(updateData)
|
||||
|
||||
Reference in New Issue
Block a user