Address review of degraded-egress check persistence

CheckProducer consults egress only for a transport failure: the check
failed, no HTTP status came back (isHttpStatusCode from PR 1), and the
monitor type is one whose failure can be a loss of egress
(EgressAttributableTypes; hardware and docker are excluded). A 4xx/5xx
or a content mismatch is evaluated as usual while the instance is
degraded. A rejected assessment is logged and treated as unknown so the
check is still buffered.

EXCLUDE_DEGRADED_EGRESS_MATCH moves out of the model into
check.query.ts, with an expression form for $group accumulators.
Daily status buckets and docker stats buckets exclude degraded checks
from their up/total counts while keeping them in the response-time
average, matching the uptime facet. toEntity maps egressStatus like its
siblings.

Adds heartbeatJobDegradedEgress integration tests, extends the
repository exclusion tests, and makes the harness egress stub settable.

🔧
This commit is contained in:
Craig Lawson committed 2026-09-17 22:06:16 +01:00
1 parent 4f5dba560d
commit 4335e6b7b6
13 files changed
+334 -29

No files matched your search

@@ -78,7 +78,7 @@ describe("MongoChecksRepository degraded-egress exclusion", () => {
// The evaluator runs from this read, so the flag must survive persistence for the short-circuit to fire.
expect(checks.map((check) => check.egressStatus)).toEqual(["degraded", "ok", undefined]);
expect(checks[2]).not.toHaveProperty("egressStatus");
expect(checks[2].egressStatus).toBeUndefined();
});
it("rejects a value outside the EgressStatuses tuple", async () => {
@@ -95,8 +95,9 @@ describe("MongoChecksRepository degraded-egress exclusion", () => {
// 1 up of 2 attributable checks. Counting the degraded pair would give 25%.
expect(result.uptimePercentage).toBe(0.5);
// The graph still shows the degraded checks as failures.
expect(result.groupedChecks[0]).toMatchObject({ totalChecks: 4 });
// The graph still shows the degraded checks as failures, and their response times stay in the averages.
expect(result.avgResponseTime).toBe(200);
expect(result.groupedChecks[0]).toMatchObject({ totalChecks: 4, avgResponseTime: 200 });
expect(result.groupedDownChecks[0]).toMatchObject({ totalChecks: 3 });
expect(result.groupedUpChecks[0]).toMatchObject({ totalChecks: 1 });
});
@@ -120,7 +121,7 @@ describe("MongoChecksRepository degraded-egress exclusion", () => {
expect(summary).toEqual({ totalChecks: 2, downChecks: 1 });
});
it("excludes degraded checks from the daily status buckets and yields no row for a day of only degraded checks", async () => {
it("excludes degraded checks from the daily status bucket counts but keeps them in its response-time average", async () => {
const otherMonitor = new mongoose.Types.ObjectId();
await seedCheck();
await seedCheck({ status: false });
@@ -129,8 +130,10 @@ describe("MongoChecksRepository degraded-egress exclusion", () => {
const buckets = await repo.getDailyStatusBuckets([MONITOR_ID.toString(), otherMonitor.toString()], 7, "UTC");
// (100 + 100 + 300) / 3 = 167: the degraded check's response time counts, its failure does not.
// The other monitor saw only degraded checks that day, so it gets no row rather than a 0/0 bucket.
expect(buckets).toEqual([
{ monitorId: MONITOR_ID.toString(), date: utcDate(BUCKET_TIME), totalChecks: 2, upChecks: 1, downChecks: 1, avgResponseTime: 100 },
{ monitorId: MONITOR_ID.toString(), date: utcDate(BUCKET_TIME), totalChecks: 2, upChecks: 1, downChecks: 1, avgResponseTime: 167 },
]);
});
@@ -154,6 +157,19 @@ describe("MongoChecksRepository degraded-egress exclusion", () => {
expect(docker.upChecks.totalChecks).toBe(1);
});
it("excludes degraded checks from the docker bucket counts but keeps them in its response-time average", async () => {
const dockerMonitor = new mongoose.Types.ObjectId();
const dockerMeta = { monitorId: dockerMonitor, teamId: TEAM_ID, type: "docker" };
await seedCheck({ metadata: dockerMeta });
await seedDegradedFailure({ metadata: dockerMeta });
const docker = (await repo.findByDateRangeAndMonitorId(dockerMonitor.toString(), "day", { type: "docker" })) as DockerChecksResult;
expect(docker.aggregate).toHaveLength(1);
expect(docker.aggregate[0]).toMatchObject({ upCount: 1, totalCount: 1, avgResponseTime: 200 });
});
it("keeps degraded checks in the paginated listing so they can be shown as such", async () => {
await seedCheck({ status: false });
await seedDegradedFailure();