@checkstack/healthcheck-backend 1.2.0 → 1.4.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 (38) hide show
  1. package/CHANGELOG.md +541 -0
  2. package/drizzle/0015_quiet_meggan.sql +12 -0
  3. package/drizzle/0016_complex_maginty.sql +1 -0
  4. package/drizzle/0017_pretty_caretaker.sql +1 -0
  5. package/drizzle/meta/0015_snapshot.json +764 -0
  6. package/drizzle/meta/0016_snapshot.json +644 -0
  7. package/drizzle/meta/0017_snapshot.json +563 -0
  8. package/drizzle/meta/_journal.json +21 -0
  9. package/package.json +24 -21
  10. package/src/automations.test.ts +234 -0
  11. package/src/automations.ts +342 -0
  12. package/src/collector-script-test.test.ts +236 -0
  13. package/src/collector-script-test.ts +221 -0
  14. package/src/health-entity.test.ts +698 -0
  15. package/src/health-entity.ts +369 -0
  16. package/src/health-state.test.ts +115 -0
  17. package/src/health-state.ts +333 -0
  18. package/src/healthcheck-gitops-kinds.test.ts +6 -32
  19. package/src/healthcheck-gitops-kinds.ts +4 -19
  20. package/src/hooks.test.ts +19 -6
  21. package/src/hooks.ts +38 -28
  22. package/src/index.ts +150 -98
  23. package/src/queue-executor.test.ts +137 -0
  24. package/src/queue-executor.ts +282 -380
  25. package/src/retention-job.ts +65 -1
  26. package/src/retention-state-transitions.test.ts +49 -0
  27. package/src/router.test.ts +18 -0
  28. package/src/router.ts +56 -1
  29. package/src/schema.ts +34 -54
  30. package/src/service-assignments.test.ts +184 -0
  31. package/src/service-notification-policy.test.ts +28 -71
  32. package/src/service.ts +154 -0
  33. package/src/state-transitions.test.ts +126 -0
  34. package/src/state-transitions.ts +112 -0
  35. package/tsconfig.json +12 -3
  36. package/src/auto-incident-close-job.ts +0 -164
  37. package/src/auto-incident.test.ts +0 -196
  38. package/src/auto-incident.ts +0 -332
@@ -0,0 +1,644 @@
1
+ {
2
+ "id": "59252e71-9a8e-4a51-a2a5-e3c98e3d9182",
3
+ "prevId": "a5bf5f4f-f128-4c9f-8898-f6f4e6cb8f2a",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "public.health_check_aggregates": {
8
+ "name": "health_check_aggregates",
9
+ "schema": "",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "uuid",
14
+ "primaryKey": true,
15
+ "notNull": true,
16
+ "default": "gen_random_uuid()"
17
+ },
18
+ "configuration_id": {
19
+ "name": "configuration_id",
20
+ "type": "uuid",
21
+ "primaryKey": false,
22
+ "notNull": true
23
+ },
24
+ "system_id": {
25
+ "name": "system_id",
26
+ "type": "text",
27
+ "primaryKey": false,
28
+ "notNull": true
29
+ },
30
+ "bucket_start": {
31
+ "name": "bucket_start",
32
+ "type": "timestamp",
33
+ "primaryKey": false,
34
+ "notNull": true
35
+ },
36
+ "bucket_size": {
37
+ "name": "bucket_size",
38
+ "type": "bucket_size",
39
+ "typeSchema": "public",
40
+ "primaryKey": false,
41
+ "notNull": true
42
+ },
43
+ "run_count": {
44
+ "name": "run_count",
45
+ "type": "integer",
46
+ "primaryKey": false,
47
+ "notNull": true
48
+ },
49
+ "healthy_count": {
50
+ "name": "healthy_count",
51
+ "type": "integer",
52
+ "primaryKey": false,
53
+ "notNull": true
54
+ },
55
+ "degraded_count": {
56
+ "name": "degraded_count",
57
+ "type": "integer",
58
+ "primaryKey": false,
59
+ "notNull": true
60
+ },
61
+ "unhealthy_count": {
62
+ "name": "unhealthy_count",
63
+ "type": "integer",
64
+ "primaryKey": false,
65
+ "notNull": true
66
+ },
67
+ "latency_sum_ms": {
68
+ "name": "latency_sum_ms",
69
+ "type": "integer",
70
+ "primaryKey": false,
71
+ "notNull": false
72
+ },
73
+ "avg_latency_ms": {
74
+ "name": "avg_latency_ms",
75
+ "type": "integer",
76
+ "primaryKey": false,
77
+ "notNull": false
78
+ },
79
+ "min_latency_ms": {
80
+ "name": "min_latency_ms",
81
+ "type": "integer",
82
+ "primaryKey": false,
83
+ "notNull": false
84
+ },
85
+ "max_latency_ms": {
86
+ "name": "max_latency_ms",
87
+ "type": "integer",
88
+ "primaryKey": false,
89
+ "notNull": false
90
+ },
91
+ "p95_latency_ms": {
92
+ "name": "p95_latency_ms",
93
+ "type": "integer",
94
+ "primaryKey": false,
95
+ "notNull": false
96
+ },
97
+ "aggregated_result": {
98
+ "name": "aggregated_result",
99
+ "type": "jsonb",
100
+ "primaryKey": false,
101
+ "notNull": false
102
+ },
103
+ "tdigest_state": {
104
+ "name": "tdigest_state",
105
+ "type": "jsonb",
106
+ "primaryKey": false,
107
+ "notNull": false
108
+ },
109
+ "source_id": {
110
+ "name": "source_id",
111
+ "type": "text",
112
+ "primaryKey": false,
113
+ "notNull": false
114
+ },
115
+ "source_label": {
116
+ "name": "source_label",
117
+ "type": "text",
118
+ "primaryKey": false,
119
+ "notNull": false
120
+ }
121
+ },
122
+ "indexes": {},
123
+ "foreignKeys": {
124
+ "health_check_aggregates_configuration_id_health_check_configurations_id_fk": {
125
+ "name": "health_check_aggregates_configuration_id_health_check_configurations_id_fk",
126
+ "tableFrom": "health_check_aggregates",
127
+ "tableTo": "health_check_configurations",
128
+ "columnsFrom": [
129
+ "configuration_id"
130
+ ],
131
+ "columnsTo": [
132
+ "id"
133
+ ],
134
+ "onDelete": "cascade",
135
+ "onUpdate": "no action"
136
+ }
137
+ },
138
+ "compositePrimaryKeys": {},
139
+ "uniqueConstraints": {
140
+ "health_check_aggregates_bucket_unique": {
141
+ "name": "health_check_aggregates_bucket_unique",
142
+ "nullsNotDistinct": true,
143
+ "columns": [
144
+ "configuration_id",
145
+ "system_id",
146
+ "bucket_start",
147
+ "bucket_size",
148
+ "source_id"
149
+ ]
150
+ }
151
+ },
152
+ "policies": {},
153
+ "checkConstraints": {},
154
+ "isRLSEnabled": false
155
+ },
156
+ "public.health_check_configurations": {
157
+ "name": "health_check_configurations",
158
+ "schema": "",
159
+ "columns": {
160
+ "id": {
161
+ "name": "id",
162
+ "type": "uuid",
163
+ "primaryKey": true,
164
+ "notNull": true,
165
+ "default": "gen_random_uuid()"
166
+ },
167
+ "name": {
168
+ "name": "name",
169
+ "type": "text",
170
+ "primaryKey": false,
171
+ "notNull": true
172
+ },
173
+ "strategy_id": {
174
+ "name": "strategy_id",
175
+ "type": "text",
176
+ "primaryKey": false,
177
+ "notNull": true
178
+ },
179
+ "config": {
180
+ "name": "config",
181
+ "type": "jsonb",
182
+ "primaryKey": false,
183
+ "notNull": true
184
+ },
185
+ "collectors": {
186
+ "name": "collectors",
187
+ "type": "jsonb",
188
+ "primaryKey": false,
189
+ "notNull": false
190
+ },
191
+ "interval_seconds": {
192
+ "name": "interval_seconds",
193
+ "type": "integer",
194
+ "primaryKey": false,
195
+ "notNull": true
196
+ },
197
+ "is_template": {
198
+ "name": "is_template",
199
+ "type": "boolean",
200
+ "primaryKey": false,
201
+ "notNull": false,
202
+ "default": false
203
+ },
204
+ "paused": {
205
+ "name": "paused",
206
+ "type": "boolean",
207
+ "primaryKey": false,
208
+ "notNull": true,
209
+ "default": false
210
+ },
211
+ "created_at": {
212
+ "name": "created_at",
213
+ "type": "timestamp",
214
+ "primaryKey": false,
215
+ "notNull": true,
216
+ "default": "now()"
217
+ },
218
+ "updated_at": {
219
+ "name": "updated_at",
220
+ "type": "timestamp",
221
+ "primaryKey": false,
222
+ "notNull": true,
223
+ "default": "now()"
224
+ }
225
+ },
226
+ "indexes": {},
227
+ "foreignKeys": {},
228
+ "compositePrimaryKeys": {},
229
+ "uniqueConstraints": {},
230
+ "policies": {},
231
+ "checkConstraints": {},
232
+ "isRLSEnabled": false
233
+ },
234
+ "public.health_check_runs": {
235
+ "name": "health_check_runs",
236
+ "schema": "",
237
+ "columns": {
238
+ "id": {
239
+ "name": "id",
240
+ "type": "uuid",
241
+ "primaryKey": true,
242
+ "notNull": true,
243
+ "default": "gen_random_uuid()"
244
+ },
245
+ "configuration_id": {
246
+ "name": "configuration_id",
247
+ "type": "uuid",
248
+ "primaryKey": false,
249
+ "notNull": true
250
+ },
251
+ "system_id": {
252
+ "name": "system_id",
253
+ "type": "text",
254
+ "primaryKey": false,
255
+ "notNull": true
256
+ },
257
+ "status": {
258
+ "name": "status",
259
+ "type": "health_check_status",
260
+ "typeSchema": "public",
261
+ "primaryKey": false,
262
+ "notNull": true
263
+ },
264
+ "latency_ms": {
265
+ "name": "latency_ms",
266
+ "type": "integer",
267
+ "primaryKey": false,
268
+ "notNull": false
269
+ },
270
+ "result": {
271
+ "name": "result",
272
+ "type": "jsonb",
273
+ "primaryKey": false,
274
+ "notNull": false
275
+ },
276
+ "source_id": {
277
+ "name": "source_id",
278
+ "type": "text",
279
+ "primaryKey": false,
280
+ "notNull": false
281
+ },
282
+ "source_label": {
283
+ "name": "source_label",
284
+ "type": "text",
285
+ "primaryKey": false,
286
+ "notNull": false
287
+ },
288
+ "timestamp": {
289
+ "name": "timestamp",
290
+ "type": "timestamp",
291
+ "primaryKey": false,
292
+ "notNull": true,
293
+ "default": "now()"
294
+ }
295
+ },
296
+ "indexes": {},
297
+ "foreignKeys": {
298
+ "health_check_runs_configuration_id_health_check_configurations_id_fk": {
299
+ "name": "health_check_runs_configuration_id_health_check_configurations_id_fk",
300
+ "tableFrom": "health_check_runs",
301
+ "tableTo": "health_check_configurations",
302
+ "columnsFrom": [
303
+ "configuration_id"
304
+ ],
305
+ "columnsTo": [
306
+ "id"
307
+ ],
308
+ "onDelete": "cascade",
309
+ "onUpdate": "no action"
310
+ }
311
+ },
312
+ "compositePrimaryKeys": {},
313
+ "uniqueConstraints": {},
314
+ "policies": {},
315
+ "checkConstraints": {},
316
+ "isRLSEnabled": false
317
+ },
318
+ "public.health_check_state_transitions": {
319
+ "name": "health_check_state_transitions",
320
+ "schema": "",
321
+ "columns": {
322
+ "id": {
323
+ "name": "id",
324
+ "type": "uuid",
325
+ "primaryKey": true,
326
+ "notNull": true,
327
+ "default": "gen_random_uuid()"
328
+ },
329
+ "system_id": {
330
+ "name": "system_id",
331
+ "type": "text",
332
+ "primaryKey": false,
333
+ "notNull": true
334
+ },
335
+ "configuration_id": {
336
+ "name": "configuration_id",
337
+ "type": "uuid",
338
+ "primaryKey": false,
339
+ "notNull": true
340
+ },
341
+ "from_status": {
342
+ "name": "from_status",
343
+ "type": "health_check_status",
344
+ "typeSchema": "public",
345
+ "primaryKey": false,
346
+ "notNull": false
347
+ },
348
+ "to_status": {
349
+ "name": "to_status",
350
+ "type": "health_check_status",
351
+ "typeSchema": "public",
352
+ "primaryKey": false,
353
+ "notNull": true
354
+ },
355
+ "transitioned_at": {
356
+ "name": "transitioned_at",
357
+ "type": "timestamp",
358
+ "primaryKey": false,
359
+ "notNull": true,
360
+ "default": "now()"
361
+ }
362
+ },
363
+ "indexes": {
364
+ "health_check_state_transitions_lookup_idx": {
365
+ "name": "health_check_state_transitions_lookup_idx",
366
+ "columns": [
367
+ {
368
+ "expression": "system_id",
369
+ "isExpression": false,
370
+ "asc": true,
371
+ "nulls": "last"
372
+ },
373
+ {
374
+ "expression": "to_status",
375
+ "isExpression": false,
376
+ "asc": true,
377
+ "nulls": "last"
378
+ },
379
+ {
380
+ "expression": "transitioned_at",
381
+ "isExpression": false,
382
+ "asc": true,
383
+ "nulls": "last"
384
+ }
385
+ ],
386
+ "isUnique": false,
387
+ "concurrently": false,
388
+ "method": "btree",
389
+ "with": {}
390
+ },
391
+ "health_check_state_transitions_system_recent_idx": {
392
+ "name": "health_check_state_transitions_system_recent_idx",
393
+ "columns": [
394
+ {
395
+ "expression": "system_id",
396
+ "isExpression": false,
397
+ "asc": true,
398
+ "nulls": "last"
399
+ },
400
+ {
401
+ "expression": "transitioned_at",
402
+ "isExpression": false,
403
+ "asc": true,
404
+ "nulls": "last"
405
+ }
406
+ ],
407
+ "isUnique": false,
408
+ "concurrently": false,
409
+ "method": "btree",
410
+ "with": {}
411
+ }
412
+ },
413
+ "foreignKeys": {
414
+ "health_check_state_transitions_configuration_id_health_check_configurations_id_fk": {
415
+ "name": "health_check_state_transitions_configuration_id_health_check_configurations_id_fk",
416
+ "tableFrom": "health_check_state_transitions",
417
+ "tableTo": "health_check_configurations",
418
+ "columnsFrom": [
419
+ "configuration_id"
420
+ ],
421
+ "columnsTo": [
422
+ "id"
423
+ ],
424
+ "onDelete": "cascade",
425
+ "onUpdate": "no action"
426
+ }
427
+ },
428
+ "compositePrimaryKeys": {},
429
+ "uniqueConstraints": {},
430
+ "policies": {},
431
+ "checkConstraints": {},
432
+ "isRLSEnabled": false
433
+ },
434
+ "public.health_check_unhealthy_transitions": {
435
+ "name": "health_check_unhealthy_transitions",
436
+ "schema": "",
437
+ "columns": {
438
+ "id": {
439
+ "name": "id",
440
+ "type": "uuid",
441
+ "primaryKey": true,
442
+ "notNull": true,
443
+ "default": "gen_random_uuid()"
444
+ },
445
+ "configuration_id": {
446
+ "name": "configuration_id",
447
+ "type": "uuid",
448
+ "primaryKey": false,
449
+ "notNull": true
450
+ },
451
+ "system_id": {
452
+ "name": "system_id",
453
+ "type": "text",
454
+ "primaryKey": false,
455
+ "notNull": true
456
+ },
457
+ "transitioned_at": {
458
+ "name": "transitioned_at",
459
+ "type": "timestamp",
460
+ "primaryKey": false,
461
+ "notNull": true,
462
+ "default": "now()"
463
+ }
464
+ },
465
+ "indexes": {
466
+ "health_check_unhealthy_transitions_lookup_idx": {
467
+ "name": "health_check_unhealthy_transitions_lookup_idx",
468
+ "columns": [
469
+ {
470
+ "expression": "configuration_id",
471
+ "isExpression": false,
472
+ "asc": true,
473
+ "nulls": "last"
474
+ },
475
+ {
476
+ "expression": "system_id",
477
+ "isExpression": false,
478
+ "asc": true,
479
+ "nulls": "last"
480
+ },
481
+ {
482
+ "expression": "transitioned_at",
483
+ "isExpression": false,
484
+ "asc": true,
485
+ "nulls": "last"
486
+ }
487
+ ],
488
+ "isUnique": false,
489
+ "concurrently": false,
490
+ "method": "btree",
491
+ "with": {}
492
+ }
493
+ },
494
+ "foreignKeys": {
495
+ "health_check_unhealthy_transitions_configuration_id_health_check_configurations_id_fk": {
496
+ "name": "health_check_unhealthy_transitions_configuration_id_health_check_configurations_id_fk",
497
+ "tableFrom": "health_check_unhealthy_transitions",
498
+ "tableTo": "health_check_configurations",
499
+ "columnsFrom": [
500
+ "configuration_id"
501
+ ],
502
+ "columnsTo": [
503
+ "id"
504
+ ],
505
+ "onDelete": "cascade",
506
+ "onUpdate": "no action"
507
+ }
508
+ },
509
+ "compositePrimaryKeys": {},
510
+ "uniqueConstraints": {},
511
+ "policies": {},
512
+ "checkConstraints": {},
513
+ "isRLSEnabled": false
514
+ },
515
+ "public.system_health_checks": {
516
+ "name": "system_health_checks",
517
+ "schema": "",
518
+ "columns": {
519
+ "system_id": {
520
+ "name": "system_id",
521
+ "type": "text",
522
+ "primaryKey": false,
523
+ "notNull": true
524
+ },
525
+ "configuration_id": {
526
+ "name": "configuration_id",
527
+ "type": "uuid",
528
+ "primaryKey": false,
529
+ "notNull": true
530
+ },
531
+ "enabled": {
532
+ "name": "enabled",
533
+ "type": "boolean",
534
+ "primaryKey": false,
535
+ "notNull": true,
536
+ "default": true
537
+ },
538
+ "state_thresholds": {
539
+ "name": "state_thresholds",
540
+ "type": "jsonb",
541
+ "primaryKey": false,
542
+ "notNull": false
543
+ },
544
+ "retention_config": {
545
+ "name": "retention_config",
546
+ "type": "jsonb",
547
+ "primaryKey": false,
548
+ "notNull": false
549
+ },
550
+ "satellite_ids": {
551
+ "name": "satellite_ids",
552
+ "type": "jsonb",
553
+ "primaryKey": false,
554
+ "notNull": false
555
+ },
556
+ "include_local": {
557
+ "name": "include_local",
558
+ "type": "boolean",
559
+ "primaryKey": false,
560
+ "notNull": true,
561
+ "default": true
562
+ },
563
+ "notification_policy": {
564
+ "name": "notification_policy",
565
+ "type": "jsonb",
566
+ "primaryKey": false,
567
+ "notNull": false
568
+ },
569
+ "created_at": {
570
+ "name": "created_at",
571
+ "type": "timestamp",
572
+ "primaryKey": false,
573
+ "notNull": true,
574
+ "default": "now()"
575
+ },
576
+ "updated_at": {
577
+ "name": "updated_at",
578
+ "type": "timestamp",
579
+ "primaryKey": false,
580
+ "notNull": true,
581
+ "default": "now()"
582
+ }
583
+ },
584
+ "indexes": {},
585
+ "foreignKeys": {
586
+ "system_health_checks_configuration_id_health_check_configurations_id_fk": {
587
+ "name": "system_health_checks_configuration_id_health_check_configurations_id_fk",
588
+ "tableFrom": "system_health_checks",
589
+ "tableTo": "health_check_configurations",
590
+ "columnsFrom": [
591
+ "configuration_id"
592
+ ],
593
+ "columnsTo": [
594
+ "id"
595
+ ],
596
+ "onDelete": "cascade",
597
+ "onUpdate": "no action"
598
+ }
599
+ },
600
+ "compositePrimaryKeys": {
601
+ "system_health_checks_system_id_configuration_id_pk": {
602
+ "name": "system_health_checks_system_id_configuration_id_pk",
603
+ "columns": [
604
+ "system_id",
605
+ "configuration_id"
606
+ ]
607
+ }
608
+ },
609
+ "uniqueConstraints": {},
610
+ "policies": {},
611
+ "checkConstraints": {},
612
+ "isRLSEnabled": false
613
+ }
614
+ },
615
+ "enums": {
616
+ "public.bucket_size": {
617
+ "name": "bucket_size",
618
+ "schema": "public",
619
+ "values": [
620
+ "hourly",
621
+ "daily"
622
+ ]
623
+ },
624
+ "public.health_check_status": {
625
+ "name": "health_check_status",
626
+ "schema": "public",
627
+ "values": [
628
+ "healthy",
629
+ "unhealthy",
630
+ "degraded"
631
+ ]
632
+ }
633
+ },
634
+ "schemas": {},
635
+ "sequences": {},
636
+ "roles": {},
637
+ "policies": {},
638
+ "views": {},
639
+ "_meta": {
640
+ "columns": {},
641
+ "schemas": {},
642
+ "tables": {}
643
+ }
644
+ }