mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-30 04:32:53 +00:00
Just use the targetHealthCheckId as the id
This commit is contained in:
@@ -21,7 +21,6 @@ import {
|
||||
generateSubnetProxyTargetV2,
|
||||
SubnetProxyTargetV2
|
||||
} from "@server/lib/ip";
|
||||
import { supportsTargetHealthChecksV2 } from "./targets";
|
||||
|
||||
export async function buildClientConfigurationForNewtClient(
|
||||
site: Site,
|
||||
@@ -232,12 +231,7 @@ export async function buildTargetConfigurationForNewtClient(
|
||||
hcUnhealthyThreshold: targetHealthCheck.hcUnhealthyThreshold
|
||||
})
|
||||
.from(targetHealthCheck)
|
||||
.where(
|
||||
and(
|
||||
eq(targetHealthCheck.siteId, siteId),
|
||||
eq(targetHealthCheck.hcEnabled, true)
|
||||
)
|
||||
);
|
||||
.where(eq(targetHealthCheck.siteId, siteId));
|
||||
|
||||
const { tcpTargets, udpTargets } = allTargets.reduce(
|
||||
(acc, target) => {
|
||||
@@ -285,9 +279,7 @@ export async function buildTargetConfigurationForNewtClient(
|
||||
}
|
||||
|
||||
return {
|
||||
id: supportsTargetHealthChecksV2(version)
|
||||
? target.targetId
|
||||
: target.targetHealthCheckId,
|
||||
id: target.targetHealthCheckId,
|
||||
hcEnabled: target.hcEnabled,
|
||||
hcPath: target.hcPath,
|
||||
hcScheme: target.hcScheme,
|
||||
|
||||
@@ -2,15 +2,6 @@ import { Target, TargetHealthCheck } from "@server/db";
|
||||
import { sendToClient } from "#dynamic/routers/ws";
|
||||
import logger from "@server/logger";
|
||||
import { canCompress } from "@server/lib/clientVersionChecks";
|
||||
import semver from "semver";
|
||||
|
||||
const NEWT_V2_TARGET_HEALTH_CHECK_VERSION = ">=1.12.0";
|
||||
|
||||
export function supportsTargetHealthChecksV2(version?: string | null) {
|
||||
return version
|
||||
? semver.satisfies(version, NEWT_V2_TARGET_HEALTH_CHECK_VERSION)
|
||||
: false;
|
||||
}
|
||||
|
||||
export async function addTargets(
|
||||
newtId: string,
|
||||
@@ -92,9 +83,7 @@ export async function addTargets(
|
||||
}
|
||||
|
||||
return {
|
||||
id: supportsTargetHealthChecksV2(version)
|
||||
? target.targetId
|
||||
: hc.targetHealthCheckId,
|
||||
id: hc.targetHealthCheckId,
|
||||
hcEnabled: hc.hcEnabled,
|
||||
hcPath: hc.hcPath,
|
||||
hcScheme: hc.hcScheme,
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
fireHealthCheckHealthyAlert,
|
||||
fireHealthCheckNotHealthyAlert
|
||||
} from "#dynamic/lib/alerts";
|
||||
import { supportsTargetHealthChecksV2 } from "@server/routers/newt/targets";
|
||||
|
||||
interface TargetHealthStatus {
|
||||
status: string;
|
||||
@@ -74,8 +73,6 @@ export const handleHealthcheckStatusMessage: MessageHandler = async (
|
||||
let successCount = 0;
|
||||
let errorCount = 0;
|
||||
|
||||
const isV2 = supportsTargetHealthChecksV2(newt.version);
|
||||
|
||||
// Process each target status update
|
||||
for (const [targetId, healthStatus] of Object.entries(data.targets)) {
|
||||
logger.debug(
|
||||
@@ -91,78 +88,34 @@ export const handleHealthcheckStatusMessage: MessageHandler = async (
|
||||
continue;
|
||||
}
|
||||
|
||||
let targetCheck: {
|
||||
targetId: number;
|
||||
siteId: number | null;
|
||||
orgId: string | null;
|
||||
targetHealthCheckId: number;
|
||||
resourceOrgId: string | null;
|
||||
resourceId: number | null;
|
||||
name: string | null;
|
||||
hcStatus: string | null;
|
||||
} | undefined;
|
||||
|
||||
if (isV2) {
|
||||
// New newt (>= 1.12.0): the key is the targetId
|
||||
[targetCheck] = await db
|
||||
.select({
|
||||
targetId: targets.targetId,
|
||||
siteId: targets.siteId,
|
||||
orgId: targetHealthCheck.orgId,
|
||||
targetHealthCheckId: targetHealthCheck.targetHealthCheckId,
|
||||
resourceOrgId: resources.orgId,
|
||||
resourceId: resources.resourceId,
|
||||
name: targetHealthCheck.name,
|
||||
hcStatus: targetHealthCheck.hcHealth
|
||||
})
|
||||
.from(targets)
|
||||
.innerJoin(
|
||||
resources,
|
||||
eq(targets.resourceId, resources.resourceId)
|
||||
const [targetCheck] = await db
|
||||
.select({
|
||||
targetId: targets.targetId,
|
||||
siteId: targets.siteId,
|
||||
orgId: targetHealthCheck.orgId,
|
||||
targetHealthCheckId: targetHealthCheck.targetHealthCheckId,
|
||||
resourceOrgId: resources.orgId,
|
||||
resourceId: resources.resourceId,
|
||||
name: targetHealthCheck.name,
|
||||
hcStatus: targetHealthCheck.hcHealth
|
||||
})
|
||||
.from(targetHealthCheck)
|
||||
.innerJoin(
|
||||
targets,
|
||||
eq(targetHealthCheck.targetId, targets.targetId)
|
||||
)
|
||||
.innerJoin(
|
||||
resources,
|
||||
eq(targets.resourceId, resources.resourceId)
|
||||
)
|
||||
.innerJoin(sites, eq(targets.siteId, sites.siteId))
|
||||
.where(
|
||||
and(
|
||||
eq(targetHealthCheck.targetHealthCheckId, targetIdNum),
|
||||
eq(sites.siteId, newt.siteId)
|
||||
)
|
||||
.innerJoin(sites, eq(targets.siteId, sites.siteId))
|
||||
.innerJoin(
|
||||
targetHealthCheck,
|
||||
eq(targets.targetId, targetHealthCheck.targetId)
|
||||
)
|
||||
.where(
|
||||
and(
|
||||
eq(targets.targetId, targetIdNum),
|
||||
eq(sites.siteId, newt.siteId)
|
||||
)
|
||||
)
|
||||
.limit(1);
|
||||
} else {
|
||||
// Old newt (< 1.12.0): the key is the targetHealthCheckId
|
||||
[targetCheck] = await db
|
||||
.select({
|
||||
targetId: targets.targetId,
|
||||
siteId: targets.siteId,
|
||||
orgId: targetHealthCheck.orgId,
|
||||
targetHealthCheckId: targetHealthCheck.targetHealthCheckId,
|
||||
resourceOrgId: resources.orgId,
|
||||
resourceId: resources.resourceId,
|
||||
name: targetHealthCheck.name,
|
||||
hcStatus: targetHealthCheck.hcHealth
|
||||
})
|
||||
.from(targetHealthCheck)
|
||||
.innerJoin(
|
||||
targets,
|
||||
eq(targetHealthCheck.targetId, targets.targetId)
|
||||
)
|
||||
.innerJoin(
|
||||
resources,
|
||||
eq(targets.resourceId, resources.resourceId)
|
||||
)
|
||||
.innerJoin(sites, eq(targets.siteId, sites.siteId))
|
||||
.where(
|
||||
and(
|
||||
eq(targetHealthCheck.targetHealthCheckId, targetIdNum),
|
||||
eq(sites.siteId, newt.siteId)
|
||||
)
|
||||
)
|
||||
.limit(1);
|
||||
}
|
||||
)
|
||||
.limit(1);
|
||||
|
||||
if (!targetCheck) {
|
||||
logger.warn(
|
||||
|
||||
Reference in New Issue
Block a user