A degraded episode now reads as a gap in monitoring rather than as downtime
or as a dip in response time. The exclusion is applied once per query, in the
top-level $match, so no pipeline can count a degraded check by omission.
- check.query.ts: EXCLUDE_DEGRADED_EGRESS_MATCH is the only helper;
IS_NOT_DEGRADED_EGRESS_EXPR and the $cond accumulators it fed are gone.
- findUptimeDateRangeChecks: excludes at the match, so the response-time
series, the up/down series and the averages drop degraded checks too.
- findPageSpeedDateRangeChecks: excludes as well; pagespeed is egress
attributable and was previously missed.
- getDailyStatusBuckets: excludes at the match; the group shapes and the
totalChecks > 0 guard revert to their original form.
- check.docker.aggregation.ts, check.hardware.aggregations.ts: reverted.
Neither type is egress attributable, so their checks never carry the flag
and the filters were dead code. A test now pins that decision.
- Tests: the gap behaviour, a window that was entirely degraded, pagespeed,
the team listing and the resolve filter, and an incident that stays open
when egress drops during it.
🔧
185 lines
6.8 KiB
TypeScript
185 lines
6.8 KiB
TypeScript
import { describe, expect, it, beforeEach } from "@jest/globals";
|
|
import { createHeartbeatTestHarness, makeMonitor, type HeartbeatTestHarness } from "../helpers/heartbeatTestHarness.ts";
|
|
import { NETWORK_ERROR } from "../../src/types/network.ts";
|
|
|
|
// Egress is only consulted for transport failures, so these heartbeats fail with the network-error
|
|
// sentinel (timeout / connection refused) rather than an HTTP status code.
|
|
|
|
describe("Heartbeat job: degraded egress", () => {
|
|
let h: HeartbeatTestHarness;
|
|
|
|
beforeEach(() => {
|
|
h = createHeartbeatTestHarness();
|
|
});
|
|
|
|
it("records failing checks as degraded without changing monitor status, opening an incident or notifying", async () => {
|
|
const monitor = makeMonitor();
|
|
h.monitorsRepo.seed(monitor);
|
|
|
|
// Enough failures to cross the 60% threshold if they were counted
|
|
h.setEgressStatus("degraded");
|
|
h.setNextResponse(false, NETWORK_ERROR);
|
|
for (let i = 0; i < 3; i++) {
|
|
await h.heartbeatJob(monitor);
|
|
}
|
|
|
|
// Every check was buffered, flagged, so the repository can exclude it from uptime
|
|
expect(h.egressService.assessAfterFailure).toHaveBeenCalledTimes(3);
|
|
expect(h.bufferStub.addToBuffer).toHaveBeenCalledTimes(3);
|
|
for (const [check] of h.bufferStub.addToBuffer.mock.calls) {
|
|
expect(check).toMatchObject({ status: false, egressStatus: "degraded" });
|
|
}
|
|
|
|
// Nothing downstream moved
|
|
const storedMonitor = await h.monitorsRepo.findById("mon-1", "team-1");
|
|
expect(storedMonitor.status).toBe("up");
|
|
expect(storedMonitor.statusWindow).toEqual([true, true, true, true, true]);
|
|
expect(h.incidentsRepo.getAll()).toHaveLength(0);
|
|
expect(h.notificationsService.handleNotifications).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("does not fire a spurious recovery once egress returns", async () => {
|
|
const monitor = makeMonitor();
|
|
h.monitorsRepo.seed(monitor);
|
|
|
|
h.setEgressStatus("degraded");
|
|
h.setNextResponse(false, NETWORK_ERROR);
|
|
for (let i = 0; i < 3; i++) {
|
|
await h.heartbeatJob(monitor);
|
|
}
|
|
|
|
// Egress is back and the target is fine
|
|
h.setEgressStatus(null);
|
|
h.setNextResponse(true, 200);
|
|
await h.heartbeatJob(monitor);
|
|
|
|
expect((await h.monitorsRepo.findById("mon-1", "team-1")).status).toBe("up");
|
|
expect(h.incidentsRepo.getAll()).toHaveLength(0);
|
|
expect(h.notificationsService.handleNotifications).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("detects down at the normal threshold when the egress check is disabled", async () => {
|
|
const monitor = makeMonitor();
|
|
h.monitorsRepo.seed(monitor);
|
|
|
|
h.setEgressStatus(null);
|
|
h.setNextResponse(false, NETWORK_ERROR);
|
|
for (let i = 0; i < 3; i++) {
|
|
await h.heartbeatJob(monitor);
|
|
}
|
|
|
|
expect(h.egressService.assessAfterFailure).toHaveBeenCalledTimes(3);
|
|
for (const [check] of h.bufferStub.addToBuffer.mock.calls) {
|
|
expect(check).not.toHaveProperty("egressStatus");
|
|
}
|
|
expect((await h.monitorsRepo.findById("mon-1", "team-1")).status).toBe("down");
|
|
expect(h.incidentsRepo.getAll()).toHaveLength(1);
|
|
expect(h.notificationsService.handleNotifications).toHaveBeenCalled();
|
|
});
|
|
|
|
it("detects down at the normal threshold when egress is confirmed ok", async () => {
|
|
const monitor = makeMonitor();
|
|
h.monitorsRepo.seed(monitor);
|
|
|
|
h.setEgressStatus("ok");
|
|
h.setNextResponse(false, NETWORK_ERROR);
|
|
for (let i = 0; i < 3; i++) {
|
|
await h.heartbeatJob(monitor);
|
|
}
|
|
|
|
for (const [check] of h.bufferStub.addToBuffer.mock.calls) {
|
|
expect(check).toMatchObject({ status: false, egressStatus: "ok" });
|
|
}
|
|
expect((await h.monitorsRepo.findById("mon-1", "team-1")).status).toBe("down");
|
|
expect(h.incidentsRepo.getAll()).toHaveLength(1);
|
|
expect(h.notificationsService.handleNotifications).toHaveBeenCalled();
|
|
});
|
|
|
|
it("evaluates HTTP error responses normally while egress is degraded", async () => {
|
|
const monitor = makeMonitor();
|
|
h.monitorsRepo.seed(monitor);
|
|
|
|
// The target answered, so the failure is its own even though the instance is degraded
|
|
h.setEgressStatus("degraded");
|
|
h.setNextResponse(false, 503);
|
|
for (let i = 0; i < 3; i++) {
|
|
await h.heartbeatJob(monitor);
|
|
}
|
|
|
|
expect(h.egressService.assessAfterFailure).not.toHaveBeenCalled();
|
|
for (const [check] of h.bufferStub.addToBuffer.mock.calls) {
|
|
expect(check).not.toHaveProperty("egressStatus");
|
|
}
|
|
expect((await h.monitorsRepo.findById("mon-1", "team-1")).status).toBe("down");
|
|
expect(h.incidentsRepo.getAll()).toHaveLength(1);
|
|
expect(h.incidentsRepo.getAll()[0].statusCode).toBe(503);
|
|
expect(h.notificationsService.handleNotifications).toHaveBeenCalled();
|
|
});
|
|
|
|
it("evaluates a failing docker check normally while egress is degraded", async () => {
|
|
const monitor = makeMonitor({ type: "docker", url: "unix:///var/run/docker.sock" });
|
|
h.monitorsRepo.seed(monitor);
|
|
|
|
h.setEgressStatus("degraded");
|
|
h.setNextResponse(false, NETWORK_ERROR);
|
|
for (let i = 0; i < 3; i++) {
|
|
await h.heartbeatJob(monitor);
|
|
}
|
|
|
|
expect(h.egressService.assessAfterFailure).not.toHaveBeenCalled();
|
|
for (const [check] of h.bufferStub.addToBuffer.mock.calls) {
|
|
expect(check).not.toHaveProperty("egressStatus");
|
|
}
|
|
expect((await h.monitorsRepo.findById("mon-1", "team-1")).status).toBe("down");
|
|
expect(h.incidentsRepo.getAll()).toHaveLength(1);
|
|
});
|
|
|
|
it("leaves an open incident open when egress drops during it", async () => {
|
|
const monitor = makeMonitor();
|
|
h.monitorsRepo.seed(monitor);
|
|
|
|
// The target goes down first and is detected normally
|
|
h.setEgressStatus(null);
|
|
h.setNextResponse(false, NETWORK_ERROR);
|
|
for (let i = 0; i < 3; i++) {
|
|
await h.heartbeatJob(monitor);
|
|
}
|
|
expect((await h.monitorsRepo.findById("mon-1", "team-1")).status).toBe("down");
|
|
expect(h.incidentsRepo.getAll()).toHaveLength(1);
|
|
|
|
// Egress then drops. The monitor must stay down rather than be resolved by the silence.
|
|
h.setEgressStatus("degraded");
|
|
for (let i = 0; i < 3; i++) {
|
|
await h.heartbeatJob(monitor);
|
|
}
|
|
|
|
expect((await h.monitorsRepo.findById("mon-1", "team-1")).status).toBe("down");
|
|
expect(h.incidentsRepo.getAll()).toHaveLength(1);
|
|
expect(h.notificationsService.handleNotifications).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("keeps counting real failures taken either side of a degraded spell", async () => {
|
|
const monitor = makeMonitor();
|
|
h.monitorsRepo.seed(monitor);
|
|
|
|
// 2 real failures: window [t, t, t, f, f] = 40% < 60%
|
|
h.setNextResponse(false, NETWORK_ERROR);
|
|
await h.heartbeatJob(monitor);
|
|
await h.heartbeatJob(monitor);
|
|
|
|
// A degraded spell must not push the window over the threshold
|
|
h.setEgressStatus("degraded");
|
|
await h.heartbeatJob(monitor);
|
|
await h.heartbeatJob(monitor);
|
|
expect((await h.monitorsRepo.findById("mon-1", "team-1")).status).toBe("up");
|
|
expect(h.incidentsRepo.getAll()).toHaveLength(0);
|
|
|
|
// 3rd real failure: window [t, t, f, f, f] = 60% >= 60%
|
|
h.setEgressStatus(null);
|
|
await h.heartbeatJob(monitor);
|
|
|
|
expect((await h.monitorsRepo.findById("mon-1", "team-1")).status).toBe("down");
|
|
expect(h.incidentsRepo.getAll()).toHaveLength(1);
|
|
});
|
|
});
|