Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
external status: fix incident comparaison (#2251)
Thibault Le Ouay8bcf63128b4f
diff --git a/apps/workflows/src/cron/external-status.ts b/apps/workflows/src/cron/external-status.tsindex a39e4e04e..14006706a 100644--- a/apps/workflows/src/cron/external-status.ts+++ b/apps/workflows/src/cron/external-status.ts@@ -314,7 +314,10 @@ function summarizeStatus(outcomes: StatusPhaseOutcome[]): {failureCount++;logger.warn("external-status status: fetch failed for slug={slug}: {reason}",- { slug: o.slug, reason: o.reason },+ {+ slug: o.slug,+ reason: o.reason,+ },);}}@@ -342,7 +345,10 @@ function summarizeIncidents(outcomes: IncidentPhaseOutcome[]): PhaseCounts {failureCount++;logger.warn("external-status incidents: failed for slug={slug}: {reason}",- { slug: o.slug, reason: o.reason },+ {+ slug: o.slug,+ reason: o.reason,+ },);}}@@ -372,7 +378,10 @@ function summarizeComponents(outcomes: ComponentPhaseOutcome[]): {failureCount++;logger.warn("external-status components: failed for slug={slug}: {reason}",- { slug: o.slug, reason: o.reason },+ {+ slug: o.slug,+ reason: o.reason,+ },);}}@@ -417,7 +426,7 @@ export async function runExternalStatusTick(): Promise<{runIncidentPhase(triplets, tickStartedAt),runComponentPhase(triplets, tickStartedAt, tickStartedAt.getTime()),],- { concurrency: "unbounded" },+ { concurrency: "50" },),);diff --git a/packages/services/src/external-service-incident/__tests__/external-service-incident.test.ts b/packages/services/src/external-service-incident/__tests__/external-service-incident.test.tsindex 5b22341c4..a74921b9c 100644--- a/packages/services/src/external-service-incident/__tests__/external-service-incident.test.ts+++ b/packages/services/src/external-service-incident/__tests__/external-service-incident.test.ts@@ -189,6 +189,62 @@ describe("upsertExternalIncidentsForService", () => {);});+ test("idle re-upsert ignores sub-second precision lost on storage round-trip", async () => {+ const serviceId = await seedService({ slug: `${TEST_PREFIX}-subsec` });+ const baseDate = new Date("2024-06-01T12:00:00.000Z");+ const incident: UpsertExternalIncidentInput = {+ providerIncidentId: "subsec-1",+ name: "Sub-second outage",+ status: "resolved",+ impact: "critical",+ shortlink: "https://stspg.io/subsec",+ startedAt: new Date("2024-06-01T11:55:00.569Z"),+ createdAt: new Date("2024-06-01T11:56:00.123Z"),+ resolvedAt: new Date("2024-06-01T12:30:00.611Z"),+ affectedComponentIds: ["cmp-a"],+ raw: { id: "subsec-1" },+ };++ await upsertExternalIncidentsForService({+ externalServiceId: serviceId,+ now: baseDate,+ incidents: [incident],+ });++ const before = await db+ .select()+ .from(externalServiceIncident)+ .where(+ and(+ eq(externalServiceIncident.externalServiceId, serviceId),+ eq(externalServiceIncident.providerIncidentId, "subsec-1"),+ ),+ )+ .all();++ const laterDate = new Date("2024-06-01T13:00:00.000Z");+ const result = await upsertExternalIncidentsForService({+ externalServiceId: serviceId,+ now: laterDate,+ incidents: [incident],+ });+ expect(result.upserted).toBe(0);++ const after = await db+ .select()+ .from(externalServiceIncident)+ .where(+ and(+ eq(externalServiceIncident.externalServiceId, serviceId),+ eq(externalServiceIncident.providerIncidentId, "subsec-1"),+ ),+ )+ .all();+ expect(after[0]?.updatedAt.getTime()).toBe(+ before[0]?.updatedAt.getTime() ?? -1,+ );+ });+test("rawPayload co-rewrites when a scalar field changes", async () => {const serviceId = await seedService({ slug: `${TEST_PREFIX}-corew` });const baseDate = new Date("2024-06-01T12:00:00.000Z");diff --git a/packages/services/src/external-service-incident/upsert.ts b/packages/services/src/external-service-incident/upsert.tsindex 19d72caa4..e722eb22f 100644--- a/packages/services/src/external-service-incident/upsert.ts+++ b/packages/services/src/external-service-incident/upsert.ts@@ -64,10 +64,14 @@ function affectedIdsEqual(a: string[], b: string[]): boolean {return true;}+// Storage is `integer({ mode: 'timestamp' })` — seconds. Incoming dates parsed+// from upstream ISO strings carry sub-second precision that is lost on write,+// so a strict ms compare flags every row as changed on the next tick. Compare+// at the storage resolution instead.function datesEqual(a: Date | null, b: Date | null): boolean {if (a === b) return true;if (a === null || b === null) return false;- return a.getTime() === b.getTime();+ return Math.floor(a.getTime() / 1000) === Math.floor(b.getTime() / 1000);}function incidentsEqual(existing: ExistingRow, desired: DesiredRow): boolean {