@checkstack/incident-backend 1.1.5 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/package.json +16 -16
  3. package/src/router.ts +90 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # @checkstack/incident-backend
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ba07ae2: Quiet down notification spam on flapping systems, auto-open incidents when a check goes critical, and let operators land directly on the broken checks.
8
+
9
+ Notification policy lives **per healthcheck assignment** (one row per `system × configuration`). Different checks on the same system are fully independent — disabling a setting on one check does not affect the others. Defaults preserve existing behaviour for `suppressDeEscalations`; **auto-incident defaults to on** for new and existing assignments.
10
+
11
+ - **`suppressDeEscalations`** (off by default). When on, transitions from a worse state to a better-but-still-failing state (e.g. `unhealthy → degraded`) no longer fire a notification. Escalations and full recoveries to `healthy` are unaffected. Resolved per assignment (the just-ran check is the one driving any aggregate transition).
12
+ - **`autoOpenIncidentOnUnhealthy`** (on by default). Either of two independent triggers can open the auto-incident:
13
+ - **`sustainedUnhealthyTrigger`** (default 30 min) — opens when the check stays continuously unhealthy for the configured duration. Catches real outages.
14
+ - **`flappingTrigger`** (default 3 transitions in 60 min) — opens when the check flips to unhealthy that many times in the window. Catches persistent flapping where each unhealthy phase is too brief for the sustained trigger.
15
+ Each trigger can be individually disabled. One incident per system: triggering checks attach to an existing active auto-incident.
16
+ - **`useNotificationSuppression`** (on by default, only meaningful when auto-open is on). Controls whether the auto-opened incident is created with `suppressNotifications: true` — leaving this off opens the incident but still pings operators on each transition.
17
+ - **`skipDuringMaintenance`** (on by default). No auto-incident is opened while the system has an active maintenance window with suppression. The system is intentionally down and shouldn't trip the on-call.
18
+ - **`autoCloseAfterMinutes`** (default 30). Auto-close cooldown is now per-assignment and snapshotted per-incident at open time — later policy edits don't alter in-flight incidents. Setting `null` ("Never auto-close") leaves the incident for manual resolution.
19
+ - **Require-recovery rule.** After any auto-incident closes (manual or auto), no new auto-incident can open until the check has logged at least one healthy run. Prevents a "operator dismissed but it's still broken" loop.
20
+ - **Auto-close worker** ticks every 60s and resolves auto-opened incidents whose systems have been healthy for their per-row `cooldownMinutes`. Rows with `null` cooldown are skipped entirely. Per-incident: failed close attempts are logged but never abort the sweep.
21
+ - **`incidentResolved` hook subscriber** syncs the auto-incident mapping when an operator manually resolves the incident, so the require-recovery rule sees the close immediately.
22
+ - **Platform-wide defaults.** New admin RPCs `getPlatformNotificationDefaults` / `setPlatformNotificationDefaults` (under the existing `healthcheck.configuration.{read,manage}` access rules) let operators set notification policy once for the whole instance. Per-assignment rows with `notificationPolicy: null` inherit the platform defaults at read time. UI: a "Notification defaults" button in the Assignment IDE opens a modal editor. The per-assignment Notifications panel shows an inheritance banner — "Using platform defaults" (read-only) with an "Override" button, or "Custom override" with a "Use platform defaults" button to revert. The all-or-nothing model keeps the mental model simple: each assignment is either fully inherited or fully overridden.
23
+ - **New service-level RPCs** on the incident plugin (`createAutoIncident`, `resolveAutoIncident`) let other plugins open/close incidents without a user context. Reused by the healthcheck auto-incident flow.
24
+ - **Health-state notification CTA** now deep-links to `?filter=failing` on the system detail page for non-recovery transitions (label changes to "View failing checks"). The system overview gains an `All / Failing / Healthy` segmented filter wired to the same `?filter=…` param.
25
+ - **Notification bell badge** now counts collapse groups instead of raw rows, so the number matches what the user sees in the notifications list. Built on `COUNT(DISTINCT COALESCE(collapse_key, id))` — notifications without a collapse key still each count as one.
26
+ - **`statusFilter` on `getHistory` / `getDetailedHistory`** lets the run-history page and the drawer's Recent Runs panel filter to `All / Healthy / Failing` via shared pills, with the page resetting to the first page on filter change.
27
+ - **Pagination defaults aligned with selector options.** Several pages defaulted to a page size (5 or 20) that wasn't in the dropdown's options (`[10, 25, 50, 100]`), so the page-size `<Select>` rendered empty. The drawer's Recent Runs now defaults to 10; the Run History, History List, and Delivery Logs pages now default to 25.
28
+
29
+ Includes Drizzle migrations adding the `notification_policy` jsonb column to `system_health_checks`, plus two new tables: `health_check_unhealthy_transitions` (for threshold counting) and `health_check_auto_incidents` (for mapping back to incident ids during auto-close).
30
+
31
+ ### Patch Changes
32
+
33
+ - Updated dependencies [ba07ae2]
34
+ - @checkstack/incident-common@1.3.0
35
+ - @checkstack/backend-api@0.17.1
36
+ - @checkstack/cache-api@0.3.5
37
+ - @checkstack/catalog-backend@1.1.6
38
+ - @checkstack/command-backend@0.1.30
39
+ - @checkstack/integration-backend@0.1.30
40
+ - @checkstack/cache-utils@0.2.10
41
+
3
42
  ## 1.1.5
4
43
 
5
44
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/incident-backend",
3
- "version": "1.1.5",
3
+ "version": "1.2.0",
4
4
  "license": "Elastic-2.0",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -14,27 +14,27 @@
14
14
  "lint:code": "eslint . --max-warnings 0"
15
15
  },
16
16
  "dependencies": {
17
- "@checkstack/backend-api": "0.16.0",
18
- "@checkstack/cache-api": "0.3.3",
19
- "@checkstack/cache-utils": "0.2.8",
20
- "@checkstack/incident-common": "1.2.1",
21
- "@checkstack/catalog-common": "2.2.1",
22
- "@checkstack/catalog-backend": "1.1.4",
23
- "@checkstack/notification-common": "1.1.1",
24
- "@checkstack/auth-common": "0.7.0",
25
- "@checkstack/command-backend": "0.1.28",
26
- "@checkstack/signal-common": "0.2.3",
27
- "@checkstack/integration-backend": "0.1.28",
28
- "@checkstack/integration-common": "0.4.0",
29
- "@checkstack/common": "0.10.0",
17
+ "@checkstack/backend-api": "0.17.0",
18
+ "@checkstack/cache-api": "0.3.4",
19
+ "@checkstack/cache-utils": "0.2.9",
20
+ "@checkstack/incident-common": "1.2.2",
21
+ "@checkstack/catalog-common": "2.2.2",
22
+ "@checkstack/catalog-backend": "1.1.5",
23
+ "@checkstack/notification-common": "1.2.0",
24
+ "@checkstack/auth-common": "0.7.1",
25
+ "@checkstack/command-backend": "0.1.29",
26
+ "@checkstack/signal-common": "0.2.4",
27
+ "@checkstack/integration-backend": "0.1.29",
28
+ "@checkstack/integration-common": "0.5.0",
29
+ "@checkstack/common": "0.11.0",
30
30
  "drizzle-orm": "^0.45.0",
31
31
  "zod": "^4.2.1",
32
32
  "@orpc/server": "^1.13.2"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@checkstack/drizzle-helper": "0.0.5",
36
- "@checkstack/scripts": "0.3.2",
37
- "@checkstack/test-utils-backend": "0.1.28",
36
+ "@checkstack/scripts": "0.3.3",
37
+ "@checkstack/test-utils-backend": "0.1.29",
38
38
  "@checkstack/tsconfig": "0.0.7",
39
39
  "@types/bun": "^1.0.0",
40
40
  "drizzle-kit": "^0.31.10",
package/src/router.ts CHANGED
@@ -395,6 +395,96 @@ export function createRouter(
395
395
  return { suppressed };
396
396
  }),
397
397
 
398
+ createAutoIncident: os.createAutoIncident.handler(
399
+ async ({ input, context }) => {
400
+ // No user context for service-initiated incidents; createdBy
401
+ // stays null and the timeline shows the originating plugin via
402
+ // the hook payload.
403
+ const result = await service.createIncident(input);
404
+
405
+ await cache.invalidateForMutation({
406
+ incidentId: result.id,
407
+ systemIds: result.systemIds,
408
+ });
409
+
410
+ await signalService.broadcast(INCIDENT_UPDATED, {
411
+ incidentId: result.id,
412
+ systemIds: result.systemIds,
413
+ action: "created",
414
+ });
415
+
416
+ await context.emitHook(incidentHooks.incidentCreated, {
417
+ incidentId: result.id,
418
+ systemIds: result.systemIds,
419
+ title: result.title,
420
+ description: result.description,
421
+ severity: result.severity,
422
+ status: result.status,
423
+ createdAt: result.createdAt.toISOString(),
424
+ });
425
+
426
+ const systemNames = await resolveSystemNames(result.systemIds);
427
+ await notifyAffectedSystems({
428
+ catalogClient,
429
+ notificationClient,
430
+ logger,
431
+ incidentId: result.id,
432
+ incidentTitle: result.title,
433
+ systemIds: result.systemIds,
434
+ systemNames,
435
+ action: "created",
436
+ severity: result.severity,
437
+ });
438
+
439
+ return { id: result.id };
440
+ },
441
+ ),
442
+
443
+ resolveAutoIncident: os.resolveAutoIncident.handler(
444
+ async ({ input, context }) => {
445
+ const result = await service.resolveIncident(input.id, input.message);
446
+ // Idempotent: a missing or already-resolved incident is treated
447
+ // as success so the auto-close worker can be re-run safely.
448
+ if (!result) {
449
+ return { success: true };
450
+ }
451
+
452
+ await cache.invalidateForMutation({
453
+ incidentId: result.id,
454
+ systemIds: result.systemIds,
455
+ });
456
+
457
+ await signalService.broadcast(INCIDENT_UPDATED, {
458
+ incidentId: result.id,
459
+ systemIds: result.systemIds,
460
+ action: "resolved",
461
+ });
462
+
463
+ await context.emitHook(incidentHooks.incidentResolved, {
464
+ incidentId: result.id,
465
+ systemIds: result.systemIds,
466
+ title: result.title,
467
+ severity: result.severity,
468
+ resolvedAt: new Date().toISOString(),
469
+ });
470
+
471
+ const systemNames = await resolveSystemNames(result.systemIds);
472
+ await notifyAffectedSystems({
473
+ catalogClient,
474
+ notificationClient,
475
+ logger,
476
+ incidentId: result.id,
477
+ incidentTitle: result.title,
478
+ systemIds: result.systemIds,
479
+ systemNames,
480
+ action: "resolved",
481
+ severity: result.severity,
482
+ });
483
+
484
+ return { success: true };
485
+ },
486
+ ),
487
+
398
488
  addLink: os.addLink.handler(async ({ input }) => {
399
489
  // Verify incident exists so the FK violation surfaces as NOT_FOUND.
400
490
  const incident = await service.getIncident(input.incidentId);