remove extra write on short window
This commit is contained in:
1 parent
187a0fc3d4
commit
4bbfe2e889
1 file changed
+49
-66
@@ -188,79 +188,62 @@ export class StatusService implements IStatusService {
|
|||||||
statusChanged = newStatus === "down";
|
statusChanged = newStatus === "down";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not enough data points yet — record the check and return
|
|
||||||
if (projectedWindow.length < monitor.statusWindowSize) {
|
|
||||||
const updated = await this.monitorsRepository.updateStatusWindowAndChecks(
|
|
||||||
monitor.id,
|
|
||||||
monitor.teamId,
|
|
||||||
check.status,
|
|
||||||
checkSnapshot,
|
|
||||||
monitor.statusWindowSize,
|
|
||||||
MAX_RECENT_CHECKS,
|
|
||||||
patch
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
monitor: updated,
|
|
||||||
statusChanged,
|
|
||||||
prevStatus,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// First evaluate reachability status changes, which apply to all monitor types
|
|
||||||
// and take precedence over hardware breaches.
|
|
||||||
const reachabilityResult = this.computeReachability(newStatus, projectedWindow, monitor.statusWindowThreshold);
|
|
||||||
if (reachabilityResult.transitioned) {
|
|
||||||
newStatus = reachabilityResult.nextStatus;
|
|
||||||
statusChanged = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Evaluate hardware threshold breaches
|
|
||||||
let thresholdBreaches: HardwareBreaches | undefined;
|
let thresholdBreaches: HardwareBreaches | undefined;
|
||||||
if (monitor.type === "hardware") {
|
|
||||||
const hardware = this.computeHardwareStatus({
|
|
||||||
currentStatus: newStatus,
|
|
||||||
reachabilityDown: newStatus === "down",
|
|
||||||
metrics: check,
|
|
||||||
thresholds: {
|
|
||||||
cpu: monitor.cpuAlertThreshold,
|
|
||||||
memory: monitor.memoryAlertThreshold,
|
|
||||||
disk: monitor.diskAlertThreshold,
|
|
||||||
temp: monitor.tempAlertThreshold,
|
|
||||||
},
|
|
||||||
counters: {
|
|
||||||
cpu: monitor.cpuAlertCounter,
|
|
||||||
memory: monitor.memoryAlertCounter,
|
|
||||||
disk: monitor.diskAlertCounter,
|
|
||||||
temp: monitor.tempAlertCounter,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
patch.cpuAlertCounter = hardware.nextCounters.cpu;
|
if (projectedWindow.length >= monitor.statusWindowSize) {
|
||||||
patch.memoryAlertCounter = hardware.nextCounters.memory;
|
// First evaluate reachability status changes, which apply to all monitor types
|
||||||
patch.diskAlertCounter = hardware.nextCounters.disk;
|
// and take precedence over hardware breaches.
|
||||||
patch.tempAlertCounter = hardware.nextCounters.temp;
|
const reachabilityResult = this.computeReachability(newStatus, projectedWindow, monitor.statusWindowThreshold);
|
||||||
thresholdBreaches = hardware.breaches;
|
if (reachabilityResult.transitioned) {
|
||||||
if (hardware.transitioned) {
|
newStatus = reachabilityResult.nextStatus;
|
||||||
newStatus = hardware.nextStatus;
|
|
||||||
statusChanged = true;
|
statusChanged = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (monitor.type === "docker" && check.containers) {
|
// Evaluate hardware threshold breaches
|
||||||
const breaches = findContainerBreaches(monitor, check.containers);
|
if (monitor.type === "hardware") {
|
||||||
const docker = this.computeDockerStatus({
|
const hardware = this.computeHardwareStatus({
|
||||||
currentStatus: newStatus,
|
currentStatus: newStatus,
|
||||||
reachabilityDown: newStatus === "down",
|
reachabilityDown: newStatus === "down",
|
||||||
breaching: breaches.length > 0,
|
metrics: check,
|
||||||
});
|
thresholds: {
|
||||||
if (docker.transitioned) {
|
cpu: monitor.cpuAlertThreshold,
|
||||||
newStatus = docker.nextStatus;
|
memory: monitor.memoryAlertThreshold,
|
||||||
statusChanged = true;
|
disk: monitor.diskAlertThreshold,
|
||||||
|
temp: monitor.tempAlertThreshold,
|
||||||
|
},
|
||||||
|
counters: {
|
||||||
|
cpu: monitor.cpuAlertCounter,
|
||||||
|
memory: monitor.memoryAlertCounter,
|
||||||
|
disk: monitor.diskAlertCounter,
|
||||||
|
temp: monitor.tempAlertCounter,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
patch.cpuAlertCounter = hardware.nextCounters.cpu;
|
||||||
|
patch.memoryAlertCounter = hardware.nextCounters.memory;
|
||||||
|
patch.diskAlertCounter = hardware.nextCounters.disk;
|
||||||
|
patch.tempAlertCounter = hardware.nextCounters.temp;
|
||||||
|
thresholdBreaches = hardware.breaches;
|
||||||
|
if (hardware.transitioned) {
|
||||||
|
newStatus = hardware.nextStatus;
|
||||||
|
statusChanged = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
patch.status = newStatus;
|
if (monitor.type === "docker" && check.containers) {
|
||||||
|
const breaches = findContainerBreaches(monitor, check.containers);
|
||||||
|
const docker = this.computeDockerStatus({
|
||||||
|
currentStatus: newStatus,
|
||||||
|
reachabilityDown: newStatus === "down",
|
||||||
|
breaching: breaches.length > 0,
|
||||||
|
});
|
||||||
|
if (docker.transitioned) {
|
||||||
|
newStatus = docker.nextStatus;
|
||||||
|
statusChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
patch.status = newStatus;
|
||||||
|
}
|
||||||
|
|
||||||
// Single atomic write: push arrays + set status/counters
|
// Single atomic write: push arrays + set status/counters
|
||||||
const updated = await this.monitorsRepository.updateStatusWindowAndChecks(
|
const updated = await this.monitorsRepository.updateStatusWindowAndChecks(
|
||||||
|
|||||||
Reference in new issue
Block a user