mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-26 10:43:09 +00:00
Handle deleting targets
This commit is contained in:
@@ -28,36 +28,18 @@ export async function addTargets(
|
||||
{ incrementConfigVersion: true, compress: canCompress(version, "newt") }
|
||||
);
|
||||
|
||||
// Create a map for quick lookup
|
||||
const healthCheckMap = new Map<number, TargetHealthCheck>();
|
||||
healthCheckData.forEach((hc) => {
|
||||
if (hc.targetId !== null) {
|
||||
healthCheckMap.set(hc.targetId, hc);
|
||||
}
|
||||
});
|
||||
|
||||
const healthCheckTargets = targets.map((target) => {
|
||||
const hc = healthCheckMap.get(target.targetId);
|
||||
|
||||
// If no health check data found, skip this target
|
||||
if (!hc) {
|
||||
logger.warn(
|
||||
`No health check configuration found for target ${target.targetId}`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
const healthCheckTargets = healthCheckData.map((hc) => {
|
||||
// Ensure all necessary fields are present
|
||||
const isTCP = hc.hcMode?.toLowerCase() === "tcp";
|
||||
if (!hc.hcHostname || !hc.hcPort || !hc.hcInterval) {
|
||||
logger.debug(
|
||||
`Skipping target ${target.targetId} due to missing health check fields`
|
||||
`Skipping hc ${hc.targetHealthCheckId} due to missing health check fields`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
if (!isTCP && (!hc.hcPath || !hc.hcMethod)) {
|
||||
logger.debug(
|
||||
`Skipping target ${target.targetId} due to missing HTTP health check fields`
|
||||
`Skipping hc ${hc.targetHealthCheckId} due to missing HTTP health check fields`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
@@ -105,7 +87,7 @@ export async function addTargets(
|
||||
|
||||
// Filter out any null values from health check targets
|
||||
const validHealthCheckTargets = healthCheckTargets.filter(
|
||||
(target) => target !== null
|
||||
(hc) => hc !== null
|
||||
);
|
||||
|
||||
await sendToClient(
|
||||
@@ -213,6 +195,7 @@ export async function removeStandaloneHealthCheck(
|
||||
export async function removeTargets(
|
||||
newtId: string,
|
||||
targets: Target[],
|
||||
healthCheckData: TargetHealthCheck[],
|
||||
protocol: string,
|
||||
version?: string | null
|
||||
) {
|
||||
@@ -234,8 +217,8 @@ export async function removeTargets(
|
||||
{ incrementConfigVersion: true }
|
||||
);
|
||||
|
||||
const healthCheckTargets = targets.map((target) => {
|
||||
return target.targetId;
|
||||
const healthCheckTargets = healthCheckData.map((hc) => {
|
||||
return hc.targetHealthCheckId;
|
||||
});
|
||||
|
||||
await sendToClient(
|
||||
|
||||
Reference in New Issue
Block a user