remove statusChange from decision, no longer needed

This commit is contained in:
Alex Holliday committed 2026-09-24 12:41:33 -07:00
1 parent 91de9e7fb7
commit 6b75f9bf7c
2 files changed
+13 -37

No files matched your search

-2
View File
@@ -1,7 +1,6 @@
import { HardwareBreaches, Monitor } from "@/domain/monitors/monitor.type.js"; import { HardwareBreaches, Monitor } from "@/domain/monitors/monitor.type.js";
import { Check } from "@/domain/checks/check.type.js"; import { Check } from "@/domain/checks/check.type.js";
import { Job, JobType } from "@/domain/jobs/job.type.js"; import { Job, JobType } from "@/domain/jobs/job.type.js";
import { StatusChangeResult } from "@/types/network.js";
import { QueueWorker } from "@/domain/queue-workers/queue-worker.type.js"; import { QueueWorker } from "@/domain/queue-workers/queue-worker.type.js";
import type { QueueMode } from "@/domain/app-settings/app-settings.type.js"; import type { QueueMode } from "@/domain/app-settings/app-settings.type.js";
@@ -19,7 +18,6 @@ export interface MonitorActionDecision {
export type MonitorEvaluation = { export type MonitorEvaluation = {
monitor: Monitor; monitor: Monitor;
check: Check; check: Check;
statusChange: StatusChangeResult; // from statusService.updateMonitorStatus
decision: MonitorActionDecision; decision: MonitorActionDecision;
}; };
+13 -35
View File
@@ -3,7 +3,6 @@ import { ICheckService } from "@/domain/checks/check.service.js";
import { Check } from "@/domain/checks/check.type.js"; import { Check } from "@/domain/checks/check.type.js";
import { IDockerLogsService } from "@/domain/docker/docker-log.service.js"; import { IDockerLogsService } from "@/domain/docker/docker-log.service.js";
import { IEgressService, isHttpStatusCode } from "@/domain/egress/egress.service.js"; import { IEgressService, isHttpStatusCode } from "@/domain/egress/egress.service.js";
import type { EgressStatus } from "@/domain/egress/egress.type.js";
import { IJobsRepository } from "@/domain/jobs/job.repository.interface.js"; import { IJobsRepository } from "@/domain/jobs/job.repository.interface.js";
import { PendingCheck } from "@/domain/jobs/job.type.js"; import { PendingCheck } from "@/domain/jobs/job.type.js";
import { IMaintenanceWindowsRepository } from "@/domain/maintenance-windows/maintenance-window.repository.interface.js"; import { IMaintenanceWindowsRepository } from "@/domain/maintenance-windows/maintenance-window.repository.interface.js";
@@ -21,7 +20,13 @@ import { IReactorDispatcher } from "@/worker/reactors/reactor.dispatcher.js";
import { JobHandler, MonitorActionDecision, MonitorEvaluation } from "@/worker/worker.interface.js"; import { JobHandler, MonitorActionDecision, MonitorEvaluation } from "@/worker/worker.interface.js";
const SERVICE_NAME = "WorkerPipeline"; const SERVICE_NAME = "WorkerPipeline";
const NO_ACTION: MonitorActionDecision = {
shouldCreateIncident: false,
shouldResolveIncident: false,
shouldSendNotification: false,
incidentReason: null,
notificationReason: null,
};
// The three entry points: the queue calls the two handlers, the buffer calls ingestChecks. // The three entry points: the queue calls the two handlers, the buffer calls ingestChecks.
// produce and evaluateCheck stay public on the class so tests can drive one stage without the queue or the buffer. // produce and evaluateCheck stay public on the class so tests can drive one stage without the queue or the buffer.
export interface IWorkerPipeline { export interface IWorkerPipeline {
@@ -128,7 +133,7 @@ export class WorkerPipeline implements IWorkerPipeline {
// Step 2b: On a transport failure, ask whether the instance itself can reach anything before blaming the // Step 2b: On a transport failure, ask whether the instance itself can reach anything before blaming the
// target. Null means the egress check is disabled (or failed internally) and the check is treated as usual. // target. Null means the egress check is disabled (or failed internally) and the check is treated as usual.
const egressStatus = this.isTransportFailure(monitor, status) ? await this.assessEgress(monitor.id) : null; const egressStatus = this.isTransportFailure(monitor, status) ? await this.deps.egressService.assessAfterFailure() : null;
if (egressStatus !== null) { if (egressStatus !== null) {
check.egressStatus = egressStatus; check.egressStatus = egressStatus;
} }
@@ -171,20 +176,6 @@ export class WorkerPipeline implements IWorkerPipeline {
return status.status === false && isEgressAttributable(monitor) && !this.peerAnswered(status); return status.status === false && isEgressAttributable(monitor) && !this.peerAnswered(status);
} }
// The egress check must never stop a check being recorded, so a rejection is logged and treated as unknown.
private async assessEgress(monitorId: string): Promise<EgressStatus | null> {
try {
return await this.deps.egressService.assessAfterFailure();
} catch (error: unknown) {
this.deps.logger.warn({
message: `Egress assessment failed for monitor ${monitorId}: ${error instanceof Error ? error.message : String(error)}`,
service: SERVICE_NAME,
method: "assessEgress",
});
return null;
}
}
// **************************************************************** // ****************************************************************
// Stage 2: Ingestion // Stage 2: Ingestion
// Called by the buffer, checks are inserted and evaluation jobs created // Called by the buffer, checks are inserted and evaluation jobs created
@@ -252,7 +243,7 @@ export class WorkerPipeline implements IWorkerPipeline {
}); });
return; return;
} }
current = evaluation.statusChange.monitor; // fresh statusWindow/status/counters for the next check current = evaluation.monitor; // fresh statusWindow/status/counters for the next check
} }
// Ids whose check was not returned (deleted by retention cleanup) would otherwise sit on the row forever // Ids whose check was not returned (deleted by retention cleanup) would otherwise sit on the row forever
@@ -277,18 +268,11 @@ export class WorkerPipeline implements IWorkerPipeline {
service: SERVICE_NAME, service: SERVICE_NAME,
method: "evaluateCheck", method: "evaluateCheck",
}); });
const decision: MonitorActionDecision = {
shouldCreateIncident: false,
shouldResolveIncident: false,
shouldSendNotification: false,
incidentReason: null,
notificationReason: null,
};
return { return {
monitor, monitor,
check, check,
statusChange: { monitor, statusChanged: false, prevStatus: monitor.status, code: check.statusCode, timestamp: Date.now() }, decision: { ...NO_ACTION },
decision,
}; };
}; };
@@ -300,18 +284,12 @@ export class WorkerPipeline implements IWorkerPipeline {
const statusChange = await this.deps.statusService.updateMonitorStatus(check, monitor); const statusChange = await this.deps.statusService.updateMonitorStatus(check, monitor);
const decision = this.decide(statusChange); const decision = this.decide(statusChange);
return { monitor: statusChange.monitor, check, statusChange, decision }; return { monitor: statusChange.monitor, check, decision };
}; };
private decide = (statusChange: StatusChangeResult): MonitorActionDecision => { private decide = (statusChange: StatusChangeResult): MonitorActionDecision => {
const { monitor, statusChanged, prevStatus } = statusChange; const { monitor, statusChanged, prevStatus } = statusChange;
const decision: MonitorActionDecision = { const decision: MonitorActionDecision = { ...NO_ACTION };
shouldCreateIncident: false,
shouldResolveIncident: false,
shouldSendNotification: false,
incidentReason: null,
notificationReason: null,
};
if (!statusChanged) return decision; if (!statusChanged) return decision;
if (monitor.status === "down") { if (monitor.status === "down") {