1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
//! shared counters + prometheus text formatting
//!
//! observability from day one (docs/lessons-from-zlay.md #8, #11): the
//! build_info canary proves which binary runs, and verification counters
//! prove verification is actually verifying — a check that silently passes
//! everything is indistinguishable from a working one without them.
//!
//! all counters are atomics: single-writer ingest thread, read by whichever
//! server thread serves /metrics.
const std = @import("std");
const build_options = @import("build_options");
const convert = @import("../ingest/convert.zig");
const process_metrics = @import("process_metrics.zig");
const timestamp_parse = @import("../timestamp/parse.zig");
const Io = std.Io;
pub const Counter = std.atomic.Value(u64);
pub const Compression = enum { none, deflate, zstd };
pub const OptionsErrorReason = enum { oversize, bad_envelope_json, bad_payload_json, invalid_options };
pub const CursorMode = enum { live, seq, time_us, clamped, disabled, unavailable, too_old, resolve_failed };
pub const HttpHandler = enum {
root,
status,
subscribe,
subscribe_v2,
xrpc,
};
pub const HttpMethod = enum { get, head, post, put, patch, delete, options, connect, trace, other };
pub const HttpCode = enum { c200, c201, c206, c304, c400, c401, c404, c405, c409, c412, c416, c500, c501, c503, other };
pub const GetBlockResult = enum { ok, not_found, bad_request, error_result };
/// why a subscriber's delivery worker ended. Found 2026-08-13: connections
/// were dying during compaction passes with no log line and no counter —
/// every worker exit must name itself so the next incident self-identifies.
pub const SubscriberExit = enum {
/// tail shut down (process stopping) — benign
tail_closed,
/// the connection's own read side closed it (client hangup discovered
/// by the server reader, or a proxy dropping the middle) — the reason
/// the 2026-08-13 eval drops were invisible inside tail_closed
client_closed,
/// hot-tail readBatch returned an error (allocation or internal)
read_batch_error,
/// socket write failed while the connection was still considered live
write_error,
/// write found the connection already closed (handler/ping tore it down)
write_closed,
/// the keepalive ping could not be written — dead socket found idle
ping_write_error,
/// slow-consumer policy disconnected the subscriber (also counted in
/// subscribe_adversarial_drops_total)
too_slow,
/// cold replay failed (archive read error)
cold_failed,
/// rotation-seam invariant violated (also subscribe_cold_stalls_total)
cold_stall,
};
pub const StoreOp = enum { get, set, delete, batch_commit };
pub const StoreStatus = enum { ok, notfound, error_result };
pub const OrchestratorPhase = enum { bootstrap, merging, steady_state };
pub const OrchestratorState = enum {
drain_bootstrap,
seal_bootstrap,
close_backfill,
write_phase_merging,
merge,
write_phase_steady,
};
pub const CompactionPassResult = enum { ok, error_result };
pub const CompactionReason = enum { record, sync, account };
pub const PipelineFailureStage = enum { scheduler, emit, repair, cursor };
const http_series_count = @typeInfo(HttpHandler).@"enum".field_names.len *
@typeInfo(HttpMethod).@"enum".field_names.len * @typeInfo(HttpCode).@"enum".field_names.len;
const store_series_count = @typeInfo(StoreOp).@"enum".field_names.len *
@typeInfo(StoreStatus).@"enum".field_names.len;
const orchestrator_phase_count = @typeInfo(OrchestratorPhase).@"enum".field_names.len;
pub const Stats = struct {
start_time_s: i64 = 0,
events_total: Counter = .init(0),
frames_total: Counter = .init(0),
ingest_events_appended_total: Counter = .init(0),
ingest_blocks_flushed_total: Counter = .init(0),
ingest_segments_rotated_total: Counter = .init(0),
ingest_append_errors_total: Counter = .init(0),
ingest_active_segment_bytes: std.atomic.Value(usize) = .init(0),
segment_seal_duration_count: Counter = .init(0),
segment_seal_duration_sum_us: Counter = .init(0),
segment_seal_duration_buckets: [15]Counter = @splat(.init(0)),
http_request_duration_count: [http_series_count]Counter = @splat(.init(0)),
http_request_duration_sum_us: [http_series_count]Counter = @splat(.init(0)),
http_request_duration_buckets: [http_series_count][11]Counter = @splat(@splat(.init(0))),
getblock_requests: std.enums.EnumArray(GetBlockResult, Counter) = .initFill(.init(0)),
subscribe_worker_exits: std.enums.EnumArray(SubscriberExit, Counter) = .initFill(.init(0)),
getblock_served_bytes_total: Counter = .init(0),
getblock_duration_count: Counter = .init(0),
getblock_duration_sum_us: Counter = .init(0),
getblock_duration_buckets: [12]Counter = @splat(.init(0)),
manifest_segments_loaded: std.atomic.Value(usize) = .init(0),
manifest_resident_bytes: std.atomic.Value(usize) = .init(0),
manifest_block_index_cache_hits_total: Counter = .init(0),
manifest_block_index_cache_misses_total: Counter = .init(0),
manifest_block_index_load_count: Counter = .init(0),
manifest_block_index_load_sum_us: Counter = .init(0),
manifest_block_index_load_buckets: [8]Counter = @splat(.init(0)),
store_op_duration_count: [store_series_count]Counter = @splat(.init(0)),
store_op_duration_sum_us: [store_series_count]Counter = @splat(.init(0)),
store_op_duration_buckets: [store_series_count][15]Counter = @splat(@splat(.init(0))),
orchestrator_phase: std.atomic.Value(usize) = .init(0),
orchestrator_phase_transitions: [orchestrator_phase_count * orchestrator_phase_count]Counter = @splat(.init(0)),
orchestrator_state_duration_count: [@typeInfo(OrchestratorState).@"enum".field_names.len]Counter = @splat(.init(0)),
orchestrator_state_duration_sum_us: [@typeInfo(OrchestratorState).@"enum".field_names.len]Counter = @splat(.init(0)),
orchestrator_state_duration_buckets: [@typeInfo(OrchestratorState).@"enum".field_names.len][14]Counter = @splat(@splat(.init(0))),
orchestrator_merge_events_kept_total: Counter = .init(0),
orchestrator_merge_events_dropped_total: Counter = .init(0),
orchestrator_merge_segments_consumed_total: Counter = .init(0),
orchestrator_merge_did_lookups_total: Counter = .init(0),
orchestrator_merge_repo_revs_updated_total: Counter = .init(0),
orchestrator_merge_dids_discovered_post_bootstrap_total: Counter = .init(0),
upstream_seq: std.atomic.Value(i64) = .init(0),
drops: std.enums.EnumArray(convert.DropReason, Counter) = .initFill(.init(0)),
backfill_drops: std.enums.EnumArray(convert.DropReason, Counter) = .initFill(.init(0)),
verify_valid: Counter = .init(0),
verify_invalid: Counter = .init(0),
verify_unverified: Counter = .init(0),
verify_cache_hits: Counter = .init(0),
verify_cache_misses: Counter = .init(0),
resync_completed_total: Counter = .init(0),
resync_failed_total: Counter = .init(0),
resync_pending_dropped_total: Counter = .init(0),
resync_rate_limited_total: Counter = .init(0),
resync_stale_total: Counter = .init(0),
resync_active: Counter = .init(0),
resync_queue_depth: std.atomic.Value(usize) = .init(0),
resync_pending: std.atomic.Value(usize) = .init(0),
livestream_decode_errors_total: Counter = .init(0),
verify_queue_dropped_total: Counter = .init(0),
replayed_account_events_dropped_total: Counter = .init(0),
replayed_identity_events_dropped_total: Counter = .init(0),
livestream_reconnects_total: Counter = .init(0),
upstream_slow_reconnects_total: Counter = .init(0),
livestream_sequence_gaps_total: Counter = .init(0),
livestream_sequence_gap_missed_seqs_total: Counter = .init(0),
livestream_unknown_events_total: Counter = .init(0),
livestream_stream_error_future_cursor_total: Counter = .init(0),
livestream_stream_error_consumer_too_slow_total: Counter = .init(0),
livestream_stream_error_other_total: Counter = .init(0),
livestream_stream_error_missing_total: Counter = .init(0),
livestream_last_seen_upstream_event_timestamp_seconds: std.atomic.Value(i64) = .init(0),
pipeline_submitted: Counter = .init(0),
pipeline_claimed: Counter = .init(0),
/// Tickets settled by drop-oldest before a verifier worker claimed them.
pipeline_unclaimed_dropped: Counter = .init(0),
/// Historical `emitted` name: every settled ticket, including drops and
/// verifier rejections. This is the scheduler's durable drain boundary.
pipeline_emitted: Counter = .init(0),
pipeline_fatal: Counter = .init(0),
pipeline_failures: std.enums.EnumArray(PipelineFailureStage, Counter) = .initFill(.init(0)),
compaction_watermark: Counter = .init(0),
compaction_watermark_lag_us: Counter = .init(0),
compaction_passes: std.enums.EnumArray(CompactionPassResult, Counter) = .initFill(.init(0)),
compaction_pass_duration_count: Counter = .init(0),
compaction_pass_duration_sum_us: Counter = .init(0),
compaction_pass_duration_buckets: [16]Counter = @splat(.init(0)),
compaction_passes_early_total: Counter = .init(0),
compaction_tombstones_collected: std.enums.EnumArray(CompactionReason, Counter) = .initFill(.init(0)),
compaction_tombstone_set_entries: std.atomic.Value(usize) = .init(0),
compaction_tombstone_set_bytes: std.atomic.Value(usize) = .init(0),
compaction_segments_examined_total: Counter = .init(0),
compaction_segments_rewritten_total: Counter = .init(0),
compaction_segments_skipped_clean_total: Counter = .init(0),
compaction_manifest_reconciled_total: Counter = .init(0),
compaction_rows_dropped: std.enums.EnumArray(CompactionReason, Counter) = .initFill(.init(0)),
compaction_bytes_rewritten_total: Counter = .init(0),
/// Unix seconds when the last compaction pass finished (ok or error); set
/// to boot time at startup so "never ran since boot" reads as growing
/// age, not as a healthy zero. Alert when age exceeds 2x the interval.
compaction_last_pass_unix_s: std.atomic.Value(i64) = .init(0),
/// Segments folded (tombstone-collected) by the running pass, live.
/// The fold phase of a backlog pass reads the whole archive and
/// previously reported nothing until chunk commit.
compaction_fold_segments_total: Counter = .init(0),
compaction_rewritten_age_count: Counter = .init(0),
compaction_rewritten_age_sum_s: Counter = .init(0),
compaction_rewritten_age_buckets: [8]Counter = @splat(.init(0)),
rebloom_segments_total: Counter = .init(0),
rebloom_bytes_reclaimed_total: Counter = .init(0),
retry_resynced_total: Counter = .init(0),
retry_failed_total: Counter = .init(0),
backfill_discovered_total: Counter = .init(0),
backfill_completed_total: Counter = .init(0),
backfill_failed_total: Counter = .init(0),
backfill_active_flips_total: Counter = .init(0),
backfill_on_fail_store_errors_total: Counter = .init(0),
backfill_handle_repo_duration_count: Counter = .init(0),
backfill_handle_repo_duration_sum_us: Counter = .init(0),
backfill_handle_repo_duration_buckets: [15]Counter = @splat(.init(0)),
backfill_progress_completed: std.atomic.Value(usize) = .init(0),
backfill_completion_queued_total: Counter = .init(0),
backfill_completion_queue_depth: std.atomic.Value(usize) = .init(0),
backfill_completion_durable_batches_total: Counter = .init(0),
backfill_completion_durable_repos_total: Counter = .init(0),
backfill_completion_stage_errors_total: Counter = .init(0),
backfill_completion_queue_wait_count: Counter = .init(0),
backfill_completion_queue_wait_sum_us: Counter = .init(0),
backfill_completion_queue_wait_buckets: [15]Counter = @splat(.init(0)),
backfill_forced_checkpoint_flushes_total: Counter = .init(0),
retry_passes_total: Counter = .init(0),
retry_terminal_failures_total: Counter = .init(0),
retry_candidates_total: Counter = .init(0),
retry_attempts_total: Counter = .init(0),
retry_skipped_host_parked_total: Counter = .init(0),
retry_pds_direct_total: Counter = .init(0),
retry_relay_fallback_total: Counter = .init(0),
backfill_workers_active: std.atomic.Value(usize) = .init(0),
backfill_queue_depth: std.atomic.Value(usize) = .init(0),
import_jobs_ok_total: Counter = .init(0),
import_jobs_error_total: Counter = .init(0),
import_job_duration_count: Counter = .init(0),
import_job_duration_sum_us: Counter = .init(0),
import_job_duration_buckets: [16]Counter = @splat(.init(0)),
import_phase: Counter = .init(0),
import_rows_parsed_total: Counter = .init(0),
import_rows_rejected: std.enums.EnumArray(timestamp_parse.RejectReason, Counter) = .initFill(.init(0)),
import_rows_mutated_total: Counter = .init(0),
import_rows_matched_all_total: Counter = .init(0),
import_rows_matched_specific_total: Counter = .init(0),
import_rows_corrupt_offset_total: Counter = .init(0),
import_dids_matched_total: Counter = .init(0),
import_segments_examined_total: Counter = .init(0),
import_segments_patched_total: Counter = .init(0),
import_bytes_rewritten_total: Counter = .init(0),
subscribe_active: std.enums.EnumArray(Compression, Counter) = .initFill(.init(0)),
subscribe_events_sent: std.enums.EnumArray(Compression, Counter) = .initFill(.init(0)),
subscribe_bytes_sent: std.enums.EnumArray(Compression, Counter) = .initFill(.init(0)),
subscribe_bytes_encoded: std.enums.EnumArray(Compression, Counter) = .initFill(.init(0)),
subscribe_events_filtered_total: Counter = .init(0),
subscribe_events_oversize_total: Counter = .init(0),
subscribe_events_skipped_sync_total: Counter = .init(0),
subscribe_events_skipped_resync_total: Counter = .init(0),
subscribe_encode_errors_total: Counter = .init(0),
subscribe_options_update_errors: std.enums.EnumArray(OptionsErrorReason, Counter) = .initFill(.init(0)),
subscribe_cursor_requests: std.enums.EnumArray(CursorMode, Counter) = .initFill(.init(0)),
subscribe_cursor_resolve_count: Counter = .init(0),
subscribe_cursor_resolve_sum_us: Counter = .init(0),
subscribe_cursor_resolve_buckets: [8]Counter = @splat(.init(0)),
subscribe_hot_reads_total: Counter = .init(0),
subscribe_cold_reads_total: Counter = .init(0),
subscribe_cold_stalls_total: Counter = .init(0),
subscribe_cold_contended_total: Counter = .init(0),
subscribe_capacity_rejects_total: Counter = .init(0),
subscribe_adversarial_drops_total: Counter = .init(0),
subscribe_clean_disconnects_total: Counter = .init(0),
subscribe_options_updates_total: Counter = .init(0),
pub fn addDrops(self: *Stats, before: *const convert.Drops, after: *const convert.Drops) void {
inline for (comptime std.enums.values(convert.DropReason)) |reason| {
const delta = after.get(reason) - before.get(reason);
if (delta > 0) _ = self.drops.getPtr(reason).fetchAdd(delta, .monotonic);
}
}
pub fn observeCursorResolve(self: *Stats, duration_us: u64) void {
_ = self.subscribe_cursor_resolve_count.fetchAdd(1, .monotonic);
_ = self.subscribe_cursor_resolve_sum_us.fetchAdd(duration_us, .monotonic);
const bounds = [_]u64{ 100, 400, 1_600, 6_400, 25_600, 102_400, 409_600, 1_638_400 };
inline for (bounds, 0..) |upper, i| {
if (duration_us <= upper) _ = self.subscribe_cursor_resolve_buckets[i].fetchAdd(1, .monotonic);
}
}
pub fn observeSegmentSeal(self: *Stats, duration_us: u64) void {
_ = self.segment_seal_duration_count.fetchAdd(1, .monotonic);
_ = self.segment_seal_duration_sum_us.fetchAdd(duration_us, .monotonic);
inline for (0..15) |i| {
const upper_us = @as(u64, 10_000) << @intCast(i);
if (duration_us <= upper_us)
_ = self.segment_seal_duration_buckets[i].fetchAdd(1, .monotonic);
}
}
pub fn observeHttp(self: *Stats, handler: HttpHandler, method: HttpMethod, code: u16, duration_us: u64) void {
const index = httpIndex(handler, method, httpCode(code));
_ = self.http_request_duration_count[index].fetchAdd(1, .monotonic);
_ = self.http_request_duration_sum_us[index].fetchAdd(duration_us, .monotonic);
const bounds_us = [_]u64{ 5_000, 10_000, 25_000, 50_000, 100_000, 250_000, 500_000, 1_000_000, 2_500_000, 5_000_000, 10_000_000 };
inline for (bounds_us, 0..) |upper, i| {
if (duration_us <= upper)
_ = self.http_request_duration_buckets[index][i].fetchAdd(1, .monotonic);
}
}
pub fn observeGetBlock(self: *Stats, code: u16, served_bytes: u64, duration_us: u64) void {
const result: GetBlockResult = switch (code) {
200, 206, 304 => .ok,
400 => .bad_request,
404 => .not_found,
else => .error_result,
};
_ = self.getblock_requests.getPtr(result).fetchAdd(1, .monotonic);
if (code == 200 and served_bytes > 0)
_ = self.getblock_served_bytes_total.fetchAdd(served_bytes, .monotonic);
_ = self.getblock_duration_count.fetchAdd(1, .monotonic);
_ = self.getblock_duration_sum_us.fetchAdd(duration_us, .monotonic);
inline for (0..12) |i| {
const upper_us = @as(u64, 100) << @intCast(i);
if (duration_us <= upper_us)
_ = self.getblock_duration_buckets[i].fetchAdd(1, .monotonic);
}
}
pub fn observeManifestLoad(self: *Stats, duration_us: u64) void {
_ = self.manifest_block_index_load_count.fetchAdd(1, .monotonic);
_ = self.manifest_block_index_load_sum_us.fetchAdd(duration_us, .monotonic);
inline for (0..8) |index| {
const upper_us = @as(u64, 100) << @intCast(index * 2);
if (duration_us <= upper_us)
_ = self.manifest_block_index_load_buckets[index].fetchAdd(1, .monotonic);
}
}
/// Bucket bounds in seconds: 1h, 6h, 1d, 3d, 7d, 30d, 90d, 365d. The
/// distribution answers whether steady-state rewrites cluster in recent
/// segments or scatter across deep history (storage-tiering go/no-go).
pub const rewritten_age_bounds_s = [8]u64{ 3600, 21600, 86400, 259200, 604800, 2592000, 7776000, 31536000 };
pub fn observeCompactionRewriteAge(self: *Stats, age_s: u64) void {
_ = self.compaction_rewritten_age_count.fetchAdd(1, .monotonic);
_ = self.compaction_rewritten_age_sum_s.fetchAdd(age_s, .monotonic);
inline for (rewritten_age_bounds_s, 0..) |upper_s, index| {
if (age_s <= upper_s)
_ = self.compaction_rewritten_age_buckets[index].fetchAdd(1, .monotonic);
}
}
pub fn observeStore(self: *Stats, op: StoreOp, status: StoreStatus, duration_us: u64) void {
const index = storeIndex(op, status);
_ = self.store_op_duration_count[index].fetchAdd(1, .monotonic);
_ = self.store_op_duration_sum_us[index].fetchAdd(duration_us, .monotonic);
inline for (0..15) |bucket_index| {
const upper_us = @as(u64, 100) << @intCast(bucket_index);
if (duration_us <= upper_us)
_ = self.store_op_duration_buckets[index][bucket_index].fetchAdd(1, .monotonic);
}
}
pub fn setOrchestratorPhase(self: *Stats, phase: OrchestratorPhase) void {
self.orchestrator_phase.store(@backingInt(phase) + 1, .monotonic);
}
pub fn observeOrchestratorTransition(self: *Stats, from: OrchestratorPhase, to: OrchestratorPhase) void {
_ = self.orchestrator_phase_transitions[orchestratorTransitionIndex(from, to)].fetchAdd(1, .monotonic);
}
pub fn observeOrchestratorState(self: *Stats, state: OrchestratorState, duration_us: u64) void {
const index = @backingInt(state);
_ = self.orchestrator_state_duration_count[index].fetchAdd(1, .monotonic);
_ = self.orchestrator_state_duration_sum_us[index].fetchAdd(duration_us, .monotonic);
inline for (0..14) |bucket_index| {
const upper_us = @as(u64, 10_000) << @intCast(bucket_index);
if (duration_us <= upper_us)
_ = self.orchestrator_state_duration_buckets[index][bucket_index].fetchAdd(1, .monotonic);
}
}
pub fn observeBackfillHandleRepo(self: *Stats, duration_us: u64) void {
observeSlowHistogram(
&self.backfill_handle_repo_duration_count,
&self.backfill_handle_repo_duration_sum_us,
&self.backfill_handle_repo_duration_buckets,
duration_us,
);
}
pub fn observeBackfillCompletionWait(self: *Stats, duration_us: u64) void {
observeSlowHistogram(
&self.backfill_completion_queue_wait_count,
&self.backfill_completion_queue_wait_sum_us,
&self.backfill_completion_queue_wait_buckets,
duration_us,
);
}
pub fn observeCompactionPass(self: *Stats, result: CompactionPassResult, duration_us: u64) void {
_ = self.compaction_passes.getPtr(result).fetchAdd(1, .monotonic);
_ = self.compaction_pass_duration_count.fetchAdd(1, .monotonic);
_ = self.compaction_pass_duration_sum_us.fetchAdd(duration_us, .monotonic);
inline for (0..16) |index| {
const upper_us = @as(u64, 100_000) << @intCast(index);
if (duration_us <= upper_us) _ = self.compaction_pass_duration_buckets[index].fetchAdd(1, .monotonic);
}
}
};
fn observeSlowHistogram(count: *Counter, sum_us: *Counter, buckets: *[15]Counter, duration_us: u64) void {
_ = count.fetchAdd(1, .monotonic);
_ = sum_us.fetchAdd(duration_us, .monotonic);
inline for (0..15) |index| {
const upper_us = @as(u64, 10_000) << @intCast(index);
if (duration_us <= upper_us) _ = buckets[index].fetchAdd(1, .monotonic);
}
}
fn storeIndex(op: StoreOp, status: StoreStatus) usize {
return @backingInt(op) * @typeInfo(StoreStatus).@"enum".field_names.len + @backingInt(status);
}
fn orchestratorTransitionIndex(from: OrchestratorPhase, to: OrchestratorPhase) usize {
return @backingInt(from) * orchestrator_phase_count + @backingInt(to);
}
fn httpIndex(handler: HttpHandler, method: HttpMethod, code: HttpCode) usize {
const method_count = @typeInfo(HttpMethod).@"enum".field_names.len;
const code_count = @typeInfo(HttpCode).@"enum".field_names.len;
return (@backingInt(handler) * method_count + @backingInt(method)) * code_count + @backingInt(code);
}
fn httpCode(code: u16) HttpCode {
return switch (code) {
200 => .c200,
201 => .c201,
206 => .c206,
304 => .c304,
400 => .c400,
401 => .c401,
404 => .c404,
405 => .c405,
409 => .c409,
412 => .c412,
416 => .c416,
500 => .c500,
501 => .c501,
503 => .c503,
else => .other,
};
}
/// Mirror upstream's public mux, including its middleware boundaries. The
/// debug /metrics and /healthz routes and unmatched public requests are not
/// wrapped. All XRPC methods share the stable `xrpc/` handler label because
/// upstream registers one `/xrpc/` subtree handler.
pub fn httpHandler(path: []const u8, method: []const u8) ?HttpHandler {
// the v2 subscription lives on an /xrpc/ path but keeps its own handler
// label (continuity with the /subscribe-v2 era dashboards)
if (std.mem.eql(u8, path, "/xrpc/network.bsky.jetstream.subscribeEvents")) return .subscribe_v2;
if (std.mem.startsWith(u8, path, "/xrpc/")) return .xrpc;
if (std.mem.eql(u8, method, "GET")) {
if (std.mem.eql(u8, path, "/")) return .root;
if (std.mem.eql(u8, path, "/status")) return .status;
if (std.mem.eql(u8, path, "/subscribe")) return .subscribe;
}
if (std.mem.eql(u8, method, "HEAD") and std.mem.eql(u8, path, "/status")) return .status;
return null;
}
pub fn httpMethod(method: []const u8) HttpMethod {
if (std.mem.eql(u8, method, "GET")) return .get;
if (std.mem.eql(u8, method, "HEAD")) return .head;
if (std.mem.eql(u8, method, "POST")) return .post;
if (std.mem.eql(u8, method, "PUT")) return .put;
if (std.mem.eql(u8, method, "PATCH")) return .patch;
if (std.mem.eql(u8, method, "DELETE")) return .delete;
if (std.mem.eql(u8, method, "OPTIONS")) return .options;
if (std.mem.eql(u8, method, "CONNECT")) return .connect;
if (std.mem.eql(u8, method, "TRACE")) return .trace;
return .other;
}
pub const TailGauges = struct {
entries: usize,
bytes: usize,
pinned_bytes: usize,
pinned_overrun_bytes: usize,
base: u64,
tip: u64,
};
/// Durable repository counts, read from the metadata store at scrape time.
/// These are the only backfill progress figures that survive a restart: the
/// process-local counters reset to zero and climb again, which is what made a
/// restart look like progress on the July dashboard. Null when no repository
/// state exists, which must not render as zero.
pub const DurableRepos = struct {
complete: u64 = 0,
pending: u64 = 0,
failed: u64 = 0,
unavailable: u64 = 0,
not_started: u64 = 0,
pub fn total(self: DurableRepos) u64 {
return self.complete + self.pending + self.failed + self.unavailable + self.not_started;
}
};
pub fn format(
buf: []u8,
stats: *const Stats,
subscribers_active: u32,
tail: TailGauges,
now_s: i64,
process: process_metrics.Snapshot,
data_dir_free_bytes: ?u64,
durable_repos: ?DurableRepos,
) []const u8 {
@setEvalBranchQuota(2_000);
var w: Io.Writer = .fixed(buf);
// canary: proves what binary is running (lessons #8)
w.print(
\\# TYPE stream_build_info gauge
\\stream_build_info{{git_sha="{s}",optimize="{s}"}} 1
\\# TYPE stream_uptime_seconds gauge
\\stream_uptime_seconds {d}
\\# TYPE stream_events_total counter
\\stream_events_total {d}
\\# TYPE stream_frames_total counter
\\stream_frames_total {d}
\\# TYPE stream_upstream_seq gauge
\\stream_upstream_seq {d}
\\# TYPE stream_subscribers_active gauge
\\stream_subscribers_active {d}
\\# TYPE stream_tail_entries gauge
\\stream_tail_entries {d}
\\# TYPE stream_tail_bytes gauge
\\stream_tail_bytes {d}
\\# TYPE jetstream_ingest_readable_log_bytes gauge
\\jetstream_ingest_readable_log_bytes {d}
\\# TYPE jetstream_ingest_readable_log_pinned_bytes gauge
\\jetstream_ingest_readable_log_pinned_bytes {d}
\\# TYPE jetstream_ingest_readable_log_pinned_overrun_bytes gauge
\\jetstream_ingest_readable_log_pinned_overrun_bytes {d}
\\# TYPE stream_tail_base gauge
\\stream_tail_base {d}
\\# TYPE stream_tail_tip gauge
\\stream_tail_tip {d}
\\
, .{
build_options.git_sha,
build_options.optimize,
now_s - stats.start_time_s,
stats.events_total.load(.monotonic),
stats.frames_total.load(.monotonic),
stats.upstream_seq.load(.monotonic),
subscribers_active,
tail.entries,
tail.bytes,
tail.bytes,
tail.pinned_bytes,
tail.pinned_overrun_bytes,
tail.base,
tail.tip,
}) catch {};
const pipeline_submitted = stats.pipeline_submitted.load(.monotonic);
const pipeline_claimed = stats.pipeline_claimed.load(.monotonic);
const pipeline_unclaimed_dropped = stats.pipeline_unclaimed_dropped.load(.monotonic);
const pipeline_emitted = stats.pipeline_emitted.load(.monotonic);
const pipeline_claimed_settled = pipeline_emitted -| pipeline_unclaimed_dropped;
w.print(
\\# TYPE stream_pipeline_ticket gauge
\\stream_pipeline_ticket{{stage="submitted"}} {d}
\\stream_pipeline_ticket{{stage="claimed"}} {d}
\\stream_pipeline_ticket{{stage="emitted"}} {d}
\\# TYPE stream_pipeline_stage_gap gauge
\\stream_pipeline_stage_gap{{boundary="submitted_to_claimed"}} {d}
\\stream_pipeline_stage_gap{{boundary="claimed_to_emitted"}} {d}
\\stream_pipeline_stage_gap{{boundary="submitted_to_emitted"}} {d}
\\# TYPE stream_pipeline_fatal gauge
\\stream_pipeline_fatal {d}
\\# TYPE stream_pipeline_failures_total counter
\\
, .{
pipeline_submitted,
pipeline_claimed,
pipeline_emitted,
pipeline_submitted -| pipeline_claimed -| pipeline_unclaimed_dropped,
pipeline_claimed -| pipeline_claimed_settled,
pipeline_submitted -| pipeline_emitted,
stats.pipeline_fatal.load(.monotonic),
}) catch {};
inline for (comptime std.enums.values(PipelineFailureStage)) |stage| {
w.print("stream_pipeline_failures_total{{stage=\"{s}\"}} {d}\n", .{
@tagName(stage), stats.pipeline_failures.getPtrConst(stage).load(.monotonic),
}) catch {};
}
w.print(
\\# TYPE process_start_time_seconds gauge
\\process_start_time_seconds {d}
\\
, .{stats.start_time_s}) catch {};
if (process.cpu_us) |value| w.print(
\\# TYPE process_cpu_seconds_total counter
\\process_cpu_seconds_total {d}.{d:0>6}
\\
, .{ value / std.time.us_per_s, value % std.time.us_per_s }) catch {};
if (process.resident_memory_bytes) |value| w.print(
\\# TYPE process_resident_memory_bytes gauge
\\process_resident_memory_bytes {d}
\\
, .{value}) catch {};
if (process.virtual_memory_bytes) |value| w.print(
\\# TYPE process_virtual_memory_bytes gauge
\\process_virtual_memory_bytes {d}
\\
, .{value}) catch {};
// all-arena glibc heap picture (zlay lesson 8: balanced allocs + growing
// RSS = arena fragmentation; free_total is the recoverable-in-principle
// slice, arena_heaps the chained 64 MiB units that pin it)
if (process.malloc_system_bytes) |value| w.print(
\\# TYPE stream_malloc_system_bytes gauge
\\stream_malloc_system_bytes {d}
\\
, .{value}) catch {};
if (process.malloc_free_total_bytes) |value| w.print(
\\# TYPE stream_malloc_free_total_bytes gauge
\\stream_malloc_free_total_bytes {d}
\\
, .{value}) catch {};
if (process.malloc_arena_heaps) |value| w.print(
\\# TYPE stream_malloc_arena_heaps gauge
\\stream_malloc_arena_heaps {d}
\\
, .{value}) catch {};
if (process.threads) |value| w.print(
\\# TYPE stream_process_threads gauge
\\stream_process_threads {d}
\\
, .{value}) catch {};
if (process.open_fds) |value| w.print(
\\# TYPE process_open_fds gauge
\\process_open_fds {d}
\\
, .{value}) catch {};
if (process.max_fds) |value| w.print(
\\# TYPE process_max_fds gauge
\\process_max_fds {d}
\\
, .{value}) catch {};
if (process.minor_page_faults) |value| w.print(
\\# TYPE process_minor_page_faults_total counter
\\process_minor_page_faults_total {d}
\\
, .{value}) catch {};
if (process.major_page_faults) |value| w.print(
\\# TYPE process_major_page_faults_total counter
\\process_major_page_faults_total {d}
\\
, .{value}) catch {};
if (process.voluntary_context_switches) |value| w.print(
\\# TYPE process_voluntary_context_switches_total counter
\\process_voluntary_context_switches_total {d}
\\
, .{value}) catch {};
if (process.involuntary_context_switches) |value| w.print(
\\# TYPE process_involuntary_context_switches_total counter
\\process_involuntary_context_switches_total {d}
\\
, .{value}) catch {};
if (data_dir_free_bytes) |value| w.print(
\\# TYPE jetstream_data_dir_free_bytes gauge
\\jetstream_data_dir_free_bytes {d}
\\
, .{value}) catch {};
w.print(
\\# TYPE stream_resync_total counter
\\stream_resync_total{{result="completed"}} {d}
\\stream_resync_total{{result="failed"}} {d}
\\stream_resync_total{{result="rate_limited"}} {d}
\\# TYPE stream_resync_pending_dropped_total counter
\\stream_resync_pending_dropped_total {d}
\\# TYPE stream_resync_workers_active gauge
\\stream_resync_workers_active {d}
\\# TYPE stream_resync_queue_depth gauge
\\stream_resync_queue_depth {d}
\\# TYPE stream_resync_pending gauge
\\stream_resync_pending {d}
\\# TYPE jetstream_livestream_stale_resyncs_dropped_total counter
\\jetstream_livestream_stale_resyncs_dropped_total {d}
\\# TYPE jetstream_livestream_verify_queue_dropped_events_total counter
\\jetstream_livestream_verify_queue_dropped_events_total {d}
\\
, .{
stats.resync_completed_total.load(.monotonic),
stats.resync_failed_total.load(.monotonic),
stats.resync_rate_limited_total.load(.monotonic),
stats.resync_pending_dropped_total.load(.monotonic),
stats.resync_active.load(.monotonic),
stats.resync_queue_depth.load(.monotonic),
stats.resync_pending.load(.monotonic),
stats.resync_stale_total.load(.monotonic),
stats.verify_queue_dropped_total.load(.monotonic),
}) catch {};
const seal_sum_us = stats.segment_seal_duration_sum_us.load(.monotonic);
const seal_count = stats.segment_seal_duration_count.load(.monotonic);
w.print(
\\# TYPE jetstream_segment_seal_duration_seconds histogram
\\jetstream_segment_seal_duration_seconds_sum {d}.{d:0>6}
\\jetstream_segment_seal_duration_seconds_count {d}
\\
, .{ seal_sum_us / std.time.us_per_s, seal_sum_us % std.time.us_per_s, seal_count }) catch {};
const seal_bounds = [_][]const u8{
"0.01", "0.02", "0.04", "0.08", "0.16", "0.32", "0.64", "1.28",
"2.56", "5.12", "10.24", "20.48", "40.96", "81.92", "163.84",
};
inline for (seal_bounds, 0..) |upper, i| {
w.print("jetstream_segment_seal_duration_seconds_bucket{{le=\"{s}\"}} {d}\n", .{
upper,
stats.segment_seal_duration_buckets[i].load(.monotonic),
}) catch {};
}
w.print("jetstream_segment_seal_duration_seconds_bucket{{le=\"+Inf\"}} {d}\n", .{seal_count}) catch {};
w.print("# TYPE jetstream_http_request_duration_seconds histogram\n", .{}) catch {};
for (comptime std.enums.values(HttpHandler)) |handler| {
for (comptime std.enums.values(HttpMethod)) |method| {
for (comptime std.enums.values(HttpCode)) |code| {
const index = httpIndex(handler, method, code);
const count = stats.http_request_duration_count[index].load(.monotonic);
if (count != 0) {
const labels = .{ httpHandlerLabel(handler), httpMethodLabel(method), httpCodeLabel(code) };
const sum_us = stats.http_request_duration_sum_us[index].load(.monotonic);
w.print("jetstream_http_request_duration_seconds_sum{{handler=\"{s}\",method=\"{s}\",code=\"{s}\"}} {d}.{d:0>6}\n", .{
labels[0], labels[1], labels[2], sum_us / std.time.us_per_s, sum_us % std.time.us_per_s,
}) catch {};
w.print("jetstream_http_request_duration_seconds_count{{handler=\"{s}\",method=\"{s}\",code=\"{s}\"}} {d}\n", .{
labels[0], labels[1], labels[2], count,
}) catch {};
const bounds = [_][]const u8{ "0.005", "0.01", "0.025", "0.05", "0.1", "0.25", "0.5", "1", "2.5", "5", "10" };
for (bounds, 0..) |upper, i| w.print("jetstream_http_request_duration_seconds_bucket{{handler=\"{s}\",method=\"{s}\",code=\"{s}\",le=\"{s}\"}} {d}\n", .{
labels[0], labels[1], labels[2], upper, stats.http_request_duration_buckets[index][i].load(.monotonic),
}) catch {};
w.print("jetstream_http_request_duration_seconds_bucket{{handler=\"{s}\",method=\"{s}\",code=\"{s}\",le=\"+Inf\"}} {d}\n", .{
labels[0], labels[1], labels[2], count,
}) catch {};
}
}
}
}
w.print("# TYPE jetstream_getblock_requests_total counter\n", .{}) catch {};
inline for (comptime std.enums.values(GetBlockResult)) |result| {
const count = stats.getblock_requests.getPtrConst(result).load(.monotonic);
if (count != 0) w.print(
"jetstream_getblock_requests_total{{result=\"{s}\"}} {d}\n",
.{ getBlockResultLabel(result), count },
) catch {};
}
// Always emit every reason, zeros included: this family exists to make
// subscriber deaths legible, and an absent series reads as "not scraped"
// rather than "never happened".
w.print("# TYPE stream_subscribe_worker_exits_total counter\n", .{}) catch {};
inline for (comptime std.enums.values(SubscriberExit)) |reason| {
w.print(
"stream_subscribe_worker_exits_total{{reason=\"{s}\"}} {d}\n",
.{ @tagName(reason), stats.subscribe_worker_exits.getPtrConst(reason).load(.monotonic) },
) catch {};
}
w.print(
\\# TYPE jetstream_getblock_served_bytes_total counter
\\jetstream_getblock_served_bytes_total {d}
\\# TYPE jetstream_getblock_duration_seconds histogram
\\jetstream_getblock_duration_seconds_sum {d}.{d:0>6}
\\jetstream_getblock_duration_seconds_count {d}
\\
, .{
stats.getblock_served_bytes_total.load(.monotonic),
stats.getblock_duration_sum_us.load(.monotonic) / std.time.us_per_s,
stats.getblock_duration_sum_us.load(.monotonic) % std.time.us_per_s,
stats.getblock_duration_count.load(.monotonic),
}) catch {};
const getblock_bounds = [_][]const u8{ "0.0001", "0.0002", "0.0004", "0.0008", "0.0016", "0.0032", "0.0064", "0.0128", "0.0256", "0.0512", "0.1024", "0.2048" };
inline for (getblock_bounds, 0..) |upper, i| w.print(
"jetstream_getblock_duration_seconds_bucket{{le=\"{s}\"}} {d}\n",
.{ upper, stats.getblock_duration_buckets[i].load(.monotonic) },
) catch {};
w.print("jetstream_getblock_duration_seconds_bucket{{le=\"+Inf\"}} {d}\n", .{
stats.getblock_duration_count.load(.monotonic),
}) catch {};
const manifest_load_sum_us = stats.manifest_block_index_load_sum_us.load(.monotonic);
const manifest_load_count = stats.manifest_block_index_load_count.load(.monotonic);
w.print(
\\# TYPE jetstream_manifest_segments_loaded gauge
\\jetstream_manifest_segments_loaded {d}
\\# TYPE stream_manifest_resident_bytes gauge
\\stream_manifest_resident_bytes {d}
\\# TYPE jetstream_manifest_block_index_cache_hits_total counter
\\jetstream_manifest_block_index_cache_hits_total {d}
\\# TYPE jetstream_manifest_block_index_cache_misses_total counter
\\jetstream_manifest_block_index_cache_misses_total {d}
\\# TYPE jetstream_manifest_block_index_load_seconds histogram
\\jetstream_manifest_block_index_load_seconds_sum {d}.{d:0>6}
\\jetstream_manifest_block_index_load_seconds_count {d}
\\
, .{
stats.manifest_segments_loaded.load(.monotonic),
stats.manifest_resident_bytes.load(.monotonic),
stats.manifest_block_index_cache_hits_total.load(.monotonic),
stats.manifest_block_index_cache_misses_total.load(.monotonic),
manifest_load_sum_us / std.time.us_per_s,
manifest_load_sum_us % std.time.us_per_s,
manifest_load_count,
}) catch {};
const manifest_load_bounds = [_][]const u8{ "0.0001", "0.0004", "0.0016", "0.0064", "0.0256", "0.1024", "0.4096", "1.6384" };
inline for (manifest_load_bounds, 0..) |upper, index| w.print(
"jetstream_manifest_block_index_load_seconds_bucket{{le=\"{s}\"}} {d}\n",
.{ upper, stats.manifest_block_index_load_buckets[index].load(.monotonic) },
) catch {};
w.print("jetstream_manifest_block_index_load_seconds_bucket{{le=\"+Inf\"}} {d}\n", .{manifest_load_count}) catch {};
w.print("# TYPE jetstream_store_op_duration_seconds histogram\n", .{}) catch {};
const store_bounds = [_][]const u8{
"0.0001", "0.0002", "0.0004", "0.0008", "0.0016",
"0.0032", "0.0064", "0.0128", "0.0256", "0.0512",
"0.1024", "0.2048", "0.4096", "0.8192", "1.6384",
};
inline for (comptime std.enums.values(StoreOp)) |op| {
inline for (comptime std.enums.values(StoreStatus)) |status| {
if (op != .get and status == .notfound) continue;
const index = storeIndex(op, status);
const count = stats.store_op_duration_count[index].load(.monotonic);
const sum_us = stats.store_op_duration_sum_us[index].load(.monotonic);
inline for (store_bounds, 0..) |upper, bucket_index| w.print(
"jetstream_store_op_duration_seconds_bucket{{op=\"{s}\",status=\"{s}\",le=\"{s}\"}} {d}\n",
.{ storeOpLabel(op), storeStatusLabel(status), upper, stats.store_op_duration_buckets[index][bucket_index].load(.monotonic) },
) catch {};
w.print(
"jetstream_store_op_duration_seconds_bucket{{op=\"{s}\",status=\"{s}\",le=\"+Inf\"}} {d}\n",
.{ storeOpLabel(op), storeStatusLabel(status), count },
) catch {};
w.print(
"jetstream_store_op_duration_seconds_sum{{op=\"{s}\",status=\"{s}\"}} {d}.{d:0>6}\n",
.{ storeOpLabel(op), storeStatusLabel(status), sum_us / std.time.us_per_s, sum_us % std.time.us_per_s },
) catch {};
w.print(
"jetstream_store_op_duration_seconds_count{{op=\"{s}\",status=\"{s}\"}} {d}\n",
.{ storeOpLabel(op), storeStatusLabel(status), count },
) catch {};
}
}
w.print(
\\# TYPE jetstream_orchestrator_phase gauge
\\jetstream_orchestrator_phase {d}
\\# TYPE jetstream_orchestrator_phase_transitions_total counter
\\
, .{stats.orchestrator_phase.load(.monotonic)}) catch {};
inline for (comptime std.enums.values(OrchestratorPhase)) |from| {
inline for (comptime std.enums.values(OrchestratorPhase)) |to| {
const count = stats.orchestrator_phase_transitions[orchestratorTransitionIndex(from, to)].load(.monotonic);
if (count != 0) w.print(
"jetstream_orchestrator_phase_transitions_total{{from=\"{s}\",to=\"{s}\"}} {d}\n",
.{ @tagName(from), @tagName(to), count },
) catch {};
}
}
w.print("# TYPE jetstream_orchestrator_state_duration_seconds histogram\n", .{}) catch {};
const orchestrator_state_bounds = [_][]const u8{
"0.01", "0.02", "0.04", "0.08", "0.16", "0.32", "0.64",
"1.28", "2.56", "5.12", "10.24", "20.48", "40.96", "81.92",
};
inline for (comptime std.enums.values(OrchestratorState)) |state| {
const index = @backingInt(state);
const count = stats.orchestrator_state_duration_count[index].load(.monotonic);
if (count != 0) {
const sum_us = stats.orchestrator_state_duration_sum_us[index].load(.monotonic);
inline for (orchestrator_state_bounds, 0..) |upper, bucket_index| w.print(
"jetstream_orchestrator_state_duration_seconds_bucket{{state=\"{s}\",le=\"{s}\"}} {d}\n",
.{ @tagName(state), upper, stats.orchestrator_state_duration_buckets[index][bucket_index].load(.monotonic) },
) catch {};
w.print(
"jetstream_orchestrator_state_duration_seconds_bucket{{state=\"{s}\",le=\"+Inf\"}} {d}\n",
.{ @tagName(state), count },
) catch {};
w.print(
"jetstream_orchestrator_state_duration_seconds_sum{{state=\"{s}\"}} {d}.{d:0>6}\n",
.{ @tagName(state), sum_us / std.time.us_per_s, sum_us % std.time.us_per_s },
) catch {};
w.print(
"jetstream_orchestrator_state_duration_seconds_count{{state=\"{s}\"}} {d}\n",
.{ @tagName(state), count },
) catch {};
}
}
w.print(
\\# TYPE jetstream_orchestrator_merge_events_kept_total counter
\\jetstream_orchestrator_merge_events_kept_total {d}
\\# TYPE jetstream_orchestrator_merge_events_dropped_total counter
\\jetstream_orchestrator_merge_events_dropped_total {d}
\\# TYPE jetstream_orchestrator_merge_segments_consumed_total counter
\\jetstream_orchestrator_merge_segments_consumed_total {d}
\\# TYPE jetstream_orchestrator_merge_did_lookups_total counter
\\jetstream_orchestrator_merge_did_lookups_total {d}
\\# TYPE jetstream_orchestrator_merge_repo_revs_updated_total counter
\\jetstream_orchestrator_merge_repo_revs_updated_total {d}
\\# TYPE jetstream_orchestrator_merge_dids_discovered_post_bootstrap_total counter
\\jetstream_orchestrator_merge_dids_discovered_post_bootstrap_total {d}
\\
, .{
stats.orchestrator_merge_events_kept_total.load(.monotonic),
stats.orchestrator_merge_events_dropped_total.load(.monotonic),
stats.orchestrator_merge_segments_consumed_total.load(.monotonic),
stats.orchestrator_merge_did_lookups_total.load(.monotonic),
stats.orchestrator_merge_repo_revs_updated_total.load(.monotonic),
stats.orchestrator_merge_dids_discovered_post_bootstrap_total.load(.monotonic),
}) catch {};
// Canonical upstream names. These are aliases only where Stream owns the
// same lifecycle boundary; absent families stay absent so the dashboard
// contract cannot be satisfied by placeholder zeroes.
w.print(
\\# TYPE jetstream_build_info gauge
\\jetstream_build_info{{version="{s}",optimize="{s}"}} 1
\\# TYPE jetstream_livestream_events_received_total counter
\\jetstream_livestream_events_received_total {d}
\\# TYPE jetstream_livestream_decode_errors_total counter
\\jetstream_livestream_decode_errors_total {d}
\\# TYPE jetstream_livestream_reconnects_total counter
\\jetstream_livestream_reconnects_total {d}
\\# TYPE jetstream_livestream_sequence_gaps_total counter
\\jetstream_livestream_sequence_gaps_total {d}
\\# TYPE jetstream_livestream_sequence_gap_missed_seqs_total counter
\\jetstream_livestream_sequence_gap_missed_seqs_total {d}
\\# TYPE jetstream_livestream_unknown_events_total counter
\\jetstream_livestream_unknown_events_total {d}
\\# TYPE jetstream_livestream_stream_error_frames_total counter
\\jetstream_livestream_stream_error_frames_total{{code="FutureCursor"}} {d}
\\jetstream_livestream_stream_error_frames_total{{code="ConsumerTooSlow"}} {d}
\\jetstream_livestream_stream_error_frames_total{{code="other"}} {d}
\\jetstream_livestream_stream_error_frames_total{{code="missing"}} {d}
\\# TYPE jetstream_livestream_last_seen_upstream_event_timestamp_seconds gauge
\\jetstream_livestream_last_seen_upstream_event_timestamp_seconds {d}
\\# TYPE jetstream_livestream_replayed_account_events_dropped_total counter
\\jetstream_livestream_replayed_account_events_dropped_total {d}
\\# TYPE jetstream_livestream_replayed_identity_events_dropped_total counter
\\jetstream_livestream_replayed_identity_events_dropped_total {d}
\\# TYPE jetstream_ingest_events_appended_total counter
\\jetstream_ingest_events_appended_total {d}
\\# TYPE jetstream_ingest_blocks_flushed_total counter
\\jetstream_ingest_blocks_flushed_total {d}
\\# TYPE jetstream_ingest_segments_rotated_total counter
\\jetstream_ingest_segments_rotated_total {d}
\\# TYPE jetstream_ingest_append_errors_total counter
\\jetstream_ingest_append_errors_total {d}
\\# TYPE jetstream_ingest_active_segment_bytes gauge
\\jetstream_ingest_active_segment_bytes {d}
\\
, .{
build_options.git_sha,
build_options.optimize,
stats.events_total.load(.monotonic),
stats.livestream_decode_errors_total.load(.monotonic),
stats.livestream_reconnects_total.load(.monotonic),
stats.livestream_sequence_gaps_total.load(.monotonic),
stats.livestream_sequence_gap_missed_seqs_total.load(.monotonic),
stats.livestream_unknown_events_total.load(.monotonic),
stats.livestream_stream_error_future_cursor_total.load(.monotonic),
stats.livestream_stream_error_consumer_too_slow_total.load(.monotonic),
stats.livestream_stream_error_other_total.load(.monotonic),
stats.livestream_stream_error_missing_total.load(.monotonic),
stats.livestream_last_seen_upstream_event_timestamp_seconds.load(.monotonic),
stats.replayed_account_events_dropped_total.load(.monotonic),
stats.replayed_identity_events_dropped_total.load(.monotonic),
stats.ingest_events_appended_total.load(.monotonic),
stats.ingest_blocks_flushed_total.load(.monotonic),
stats.ingest_segments_rotated_total.load(.monotonic),
stats.ingest_append_errors_total.load(.monotonic),
stats.ingest_active_segment_bytes.load(.monotonic),
}) catch {};
w.print("# TYPE jetstream_subscribe_subscribers gauge\n", .{}) catch {};
w.print("# TYPE jetstream_subscribe_events_sent_total counter\n", .{}) catch {};
w.print("# TYPE jetstream_subscribe_bytes_sent_total counter\n", .{}) catch {};
w.print("# TYPE jetstream_subscribe_bytes_encoded_total counter\n", .{}) catch {};
inline for (comptime std.enums.values(Compression)) |scheme| {
w.print("jetstream_subscribe_subscribers{{compression=\"{s}\"}} {d}\n", .{
@tagName(scheme), stats.subscribe_active.getPtrConst(scheme).load(.monotonic),
}) catch {};
w.print("jetstream_subscribe_events_sent_total{{compression=\"{s}\"}} {d}\n", .{
@tagName(scheme), stats.subscribe_events_sent.getPtrConst(scheme).load(.monotonic),
}) catch {};
w.print("jetstream_subscribe_bytes_sent_total{{compression=\"{s}\"}} {d}\n", .{
@tagName(scheme), stats.subscribe_bytes_sent.getPtrConst(scheme).load(.monotonic),
}) catch {};
w.print("jetstream_subscribe_bytes_encoded_total{{compression=\"{s}\"}} {d}\n", .{
@tagName(scheme), stats.subscribe_bytes_encoded.getPtrConst(scheme).load(.monotonic),
}) catch {};
}
w.print(
\\# TYPE jetstream_subscribe_events_filtered_total counter
\\jetstream_subscribe_events_filtered_total {d}
\\# TYPE jetstream_subscribe_events_oversize_total counter
\\jetstream_subscribe_events_oversize_total {d}
\\
, .{
stats.subscribe_events_filtered_total.load(.monotonic),
stats.subscribe_events_oversize_total.load(.monotonic),
}) catch {};
w.print(
\\# TYPE jetstream_subscribe_events_skipped_total counter
\\jetstream_subscribe_events_skipped_total{{reason="sync"}} {d}
\\jetstream_subscribe_events_skipped_total{{reason="resync_replacement"}} {d}
\\# TYPE jetstream_subscribe_encode_errors_total counter
\\jetstream_subscribe_encode_errors_total {d}
\\# TYPE jetstream_subscribe_hot_reads_total counter
\\jetstream_subscribe_hot_reads_total {d}
\\# TYPE jetstream_subscribe_cold_reads_total counter
\\jetstream_subscribe_cold_reads_total {d}
\\# TYPE stream_subscribe_cold_stalls_total counter
\\stream_subscribe_cold_stalls_total {d}
\\# TYPE stream_subscribe_cold_contended_total counter
\\stream_subscribe_cold_contended_total {d}
\\# TYPE stream_subscribe_capacity_rejects_total counter
\\stream_subscribe_capacity_rejects_total {d}
\\# TYPE jetstream_subscribe_adversarial_drops_total counter
\\jetstream_subscribe_adversarial_drops_total {d}
\\# TYPE jetstream_subscribe_clean_disconnects_total counter
\\jetstream_subscribe_clean_disconnects_total {d}
\\# TYPE jetstream_subscribe_options_updates_total counter
\\jetstream_subscribe_options_updates_total {d}
\\
, .{
stats.subscribe_events_skipped_sync_total.load(.monotonic),
stats.subscribe_events_skipped_resync_total.load(.monotonic),
stats.subscribe_encode_errors_total.load(.monotonic),
stats.subscribe_hot_reads_total.load(.monotonic),
stats.subscribe_cold_reads_total.load(.monotonic),
stats.subscribe_cold_stalls_total.load(.monotonic),
stats.subscribe_cold_contended_total.load(.monotonic),
stats.subscribe_capacity_rejects_total.load(.monotonic),
stats.subscribe_adversarial_drops_total.load(.monotonic),
stats.subscribe_clean_disconnects_total.load(.monotonic),
stats.subscribe_options_updates_total.load(.monotonic),
}) catch {};
w.print(
\\# TYPE stream_upstream_slow_reconnects_total counter
\\stream_upstream_slow_reconnects_total {d}
\\
, .{stats.upstream_slow_reconnects_total.load(.monotonic)}) catch {};
w.print("# TYPE jetstream_subscribe_options_update_errors_total counter\n", .{}) catch {};
inline for (comptime std.enums.values(OptionsErrorReason)) |reason| {
w.print("jetstream_subscribe_options_update_errors_total{{reason=\"{s}\"}} {d}\n", .{
@tagName(reason), stats.subscribe_options_update_errors.getPtrConst(reason).load(.monotonic),
}) catch {};
}
w.print("# TYPE jetstream_subscribe_cursor_requests_total counter\n", .{}) catch {};
inline for (comptime std.enums.values(CursorMode)) |mode| {
w.print("jetstream_subscribe_cursor_requests_total{{mode=\"{s}\"}} {d}\n", .{
@tagName(mode), stats.subscribe_cursor_requests.getPtrConst(mode).load(.monotonic),
}) catch {};
}
const cursor_sum_us = stats.subscribe_cursor_resolve_sum_us.load(.monotonic);
w.print(
\\# TYPE jetstream_subscribe_cursor_resolve_seconds histogram
\\jetstream_subscribe_cursor_resolve_seconds_sum {d}.{d:0>6}
\\jetstream_subscribe_cursor_resolve_seconds_count {d}
\\
, .{
cursor_sum_us / std.time.us_per_s,
cursor_sum_us % std.time.us_per_s,
stats.subscribe_cursor_resolve_count.load(.monotonic),
}) catch {};
const cursor_bucket_us = [_]u64{ 100, 400, 1_600, 6_400, 25_600, 102_400, 409_600, 1_638_400 };
inline for (cursor_bucket_us, 0..) |upper_us, i| {
w.print("jetstream_subscribe_cursor_resolve_seconds_bucket{{le=\"{d}.{d:0>6}\"}} {d}\n", .{
upper_us / std.time.us_per_s,
upper_us % std.time.us_per_s,
stats.subscribe_cursor_resolve_buckets[i].load(.monotonic),
}) catch {};
}
w.print("jetstream_subscribe_cursor_resolve_seconds_bucket{{le=\"+Inf\"}} {d}\n", .{
stats.subscribe_cursor_resolve_count.load(.monotonic),
}) catch {};
w.print(
\\# TYPE stream_verify_total counter
\\stream_verify_total{{result="valid"}} {d}
\\stream_verify_total{{result="invalid"}} {d}
\\stream_verify_total{{result="unverified"}} {d}
\\# TYPE stream_verify_key_cache_total counter
\\stream_verify_key_cache_total{{result="hit"}} {d}
\\stream_verify_key_cache_total{{result="miss"}} {d}
\\
, .{
stats.verify_valid.load(.monotonic),
stats.verify_invalid.load(.monotonic),
stats.verify_unverified.load(.monotonic),
stats.verify_cache_hits.load(.monotonic),
stats.verify_cache_misses.load(.monotonic),
}) catch {};
w.print(
\\# TYPE stream_compaction_watermark_seq gauge
\\stream_compaction_watermark_seq {d}
\\# TYPE jetstream_compaction_watermark_seq gauge
\\jetstream_compaction_watermark_seq {d}
\\# TYPE jetstream_compaction_watermark_lag_seconds gauge
\\jetstream_compaction_watermark_lag_seconds {d}.{d:0>6}
\\# TYPE jetstream_compaction_passes_total counter
\\jetstream_compaction_passes_total{{result="ok"}} {d}
\\jetstream_compaction_passes_total{{result="error"}} {d}
\\# TYPE jetstream_compaction_passes_early_total counter
\\jetstream_compaction_passes_early_total {d}
\\# TYPE jetstream_compaction_tombstone_set_entries gauge
\\jetstream_compaction_tombstone_set_entries {d}
\\# TYPE jetstream_compaction_tombstone_set_bytes gauge
\\jetstream_compaction_tombstone_set_bytes {d}
\\# TYPE jetstream_compaction_segments_examined_total counter
\\jetstream_compaction_segments_examined_total {d}
\\# TYPE jetstream_compaction_segments_rewritten_total counter
\\jetstream_compaction_segments_rewritten_total {d}
\\# TYPE jetstream_compaction_segments_skipped_clean_total counter
\\jetstream_compaction_segments_skipped_clean_total {d}
\\# TYPE jetstream_compaction_manifest_reconciled_total counter
\\jetstream_compaction_manifest_reconciled_total {d}
\\# TYPE jetstream_compaction_bytes_rewritten_total counter
\\jetstream_compaction_bytes_rewritten_total {d}
\\# TYPE stream_rebloom_segments_total counter
\\stream_rebloom_segments_total {d}
\\# TYPE stream_rebloom_bytes_reclaimed_total counter
\\stream_rebloom_bytes_reclaimed_total {d}
\\
, .{
stats.compaction_watermark.load(.monotonic),
stats.compaction_watermark.load(.monotonic),
stats.compaction_watermark_lag_us.load(.monotonic) / std.time.us_per_s,
stats.compaction_watermark_lag_us.load(.monotonic) % std.time.us_per_s,
stats.compaction_passes.getPtrConst(.ok).load(.monotonic),
stats.compaction_passes.getPtrConst(.error_result).load(.monotonic),
stats.compaction_passes_early_total.load(.monotonic),
stats.compaction_tombstone_set_entries.load(.monotonic),
stats.compaction_tombstone_set_bytes.load(.monotonic),
stats.compaction_segments_examined_total.load(.monotonic),
stats.compaction_segments_rewritten_total.load(.monotonic),
stats.compaction_segments_skipped_clean_total.load(.monotonic),
stats.compaction_manifest_reconciled_total.load(.monotonic),
stats.compaction_bytes_rewritten_total.load(.monotonic),
stats.rebloom_segments_total.load(.monotonic),
stats.rebloom_bytes_reclaimed_total.load(.monotonic),
}) catch {};
w.print(
\\# HELP stream_compaction_last_pass_timestamp_seconds Unix time of the last completed compaction pass; boot time until one completes. Alert when now minus this exceeds 2x the compaction interval.
\\# TYPE stream_compaction_last_pass_timestamp_seconds gauge
\\stream_compaction_last_pass_timestamp_seconds {d}
\\# TYPE stream_compaction_fold_segments_total counter
\\stream_compaction_fold_segments_total {d}
\\
, .{
stats.compaction_last_pass_unix_s.load(.monotonic),
stats.compaction_fold_segments_total.load(.monotonic),
}) catch {};
w.print(
\\# TYPE stream_compaction_rewritten_age_seconds histogram
\\stream_compaction_rewritten_age_seconds_sum {d}
\\stream_compaction_rewritten_age_seconds_count {d}
\\
, .{
stats.compaction_rewritten_age_sum_s.load(.monotonic),
stats.compaction_rewritten_age_count.load(.monotonic),
}) catch {};
inline for (Stats.rewritten_age_bounds_s, 0..) |upper_s, i| w.print(
"stream_compaction_rewritten_age_seconds_bucket{{le=\"{d}\"}} {d}\n",
.{ upper_s, stats.compaction_rewritten_age_buckets[i].load(.monotonic) },
) catch {};
w.print("stream_compaction_rewritten_age_seconds_bucket{{le=\"+Inf\"}} {d}\n", .{
stats.compaction_rewritten_age_count.load(.monotonic),
}) catch {};
w.print(
\\# TYPE stream_retry_repos_total counter
\\stream_retry_repos_total{{result="resynced"}} {d}
\\stream_retry_repos_total{{result="failed"}} {d}
\\# TYPE jetstream_backfill_discovered_total counter
\\jetstream_backfill_discovered_total {d}
\\# TYPE jetstream_backfill_completed_total counter
\\jetstream_backfill_completed_total {d}
\\# TYPE jetstream_backfill_failed_total counter
\\jetstream_backfill_failed_total {d}
\\# TYPE jetstream_backfill_active_flips_total counter
\\jetstream_backfill_active_flips_total {d}
\\# TYPE jetstream_backfill_on_fail_store_errors_total counter
\\jetstream_backfill_on_fail_store_errors_total {d}
\\# TYPE jetstream_backfill_progress_completed gauge
\\jetstream_backfill_progress_completed {d}
\\# TYPE jetstream_backfill_completion_queued_total counter
\\jetstream_backfill_completion_queued_total {d}
\\# TYPE jetstream_backfill_completion_queue_depth gauge
\\jetstream_backfill_completion_queue_depth {d}
\\# TYPE jetstream_backfill_completion_durable_batches_total counter
\\jetstream_backfill_completion_durable_batches_total {d}
\\# TYPE jetstream_backfill_completion_durable_repos_total counter
\\jetstream_backfill_completion_durable_repos_total {d}
\\# TYPE jetstream_backfill_completion_stage_errors_total counter
\\jetstream_backfill_completion_stage_errors_total {d}
\\# TYPE jetstream_backfill_forced_checkpoint_flushes_total counter
\\jetstream_backfill_forced_checkpoint_flushes_total {d}
\\# TYPE jetstream_backfill_failed_repo_retry_passes_total counter
\\jetstream_backfill_failed_repo_retry_passes_total {d}
\\# TYPE stream_backfill_failed_repo_retry_terminal_failures_total counter
\\stream_backfill_failed_repo_retry_terminal_failures_total {d}
\\# TYPE jetstream_backfill_failed_repo_retry_candidates_total counter
\\jetstream_backfill_failed_repo_retry_candidates_total {d}
\\# TYPE jetstream_backfill_failed_repo_retry_attempts_total counter
\\jetstream_backfill_failed_repo_retry_attempts_total {d}
\\# TYPE jetstream_backfill_failed_repo_retry_succeeded_total counter
\\jetstream_backfill_failed_repo_retry_succeeded_total {d}
\\# TYPE jetstream_backfill_failed_repo_retry_failed_total counter
\\jetstream_backfill_failed_repo_retry_failed_total {d}
\\# TYPE jetstream_backfill_failed_repo_retry_skipped_host_parked_total counter
\\jetstream_backfill_failed_repo_retry_skipped_host_parked_total {d}
\\# TYPE stream_backfill_failed_repo_retry_pds_direct_total counter
\\stream_backfill_failed_repo_retry_pds_direct_total {d}
\\# TYPE stream_backfill_failed_repo_retry_relay_fallback_total counter
\\stream_backfill_failed_repo_retry_relay_fallback_total {d}
\\# TYPE stream_backfill_repos_total counter
\\stream_backfill_repos_total{{result="complete"}} {d}
\\stream_backfill_repos_total{{result="failed"}} {d}
\\# TYPE stream_backfill_workers_active gauge
\\stream_backfill_workers_active {d}
\\# TYPE stream_backfill_queue_depth gauge
\\stream_backfill_queue_depth {d}
\\
, .{
stats.retry_resynced_total.load(.monotonic),
stats.retry_failed_total.load(.monotonic),
stats.backfill_discovered_total.load(.monotonic),
stats.backfill_completed_total.load(.monotonic),
stats.backfill_failed_total.load(.monotonic),
stats.backfill_active_flips_total.load(.monotonic),
stats.backfill_on_fail_store_errors_total.load(.monotonic),
stats.backfill_progress_completed.load(.monotonic),
stats.backfill_completion_queued_total.load(.monotonic),
stats.backfill_completion_queue_depth.load(.monotonic),
stats.backfill_completion_durable_batches_total.load(.monotonic),
stats.backfill_completion_durable_repos_total.load(.monotonic),
stats.backfill_completion_stage_errors_total.load(.monotonic),
stats.backfill_forced_checkpoint_flushes_total.load(.monotonic),
stats.retry_passes_total.load(.monotonic),
stats.retry_terminal_failures_total.load(.monotonic),
stats.retry_candidates_total.load(.monotonic),
stats.retry_attempts_total.load(.monotonic),
stats.retry_resynced_total.load(.monotonic),
stats.retry_failed_total.load(.monotonic),
stats.retry_skipped_host_parked_total.load(.monotonic),
stats.retry_pds_direct_total.load(.monotonic),
stats.retry_relay_fallback_total.load(.monotonic),
stats.backfill_completed_total.load(.monotonic),
stats.backfill_failed_total.load(.monotonic),
stats.backfill_workers_active.load(.monotonic),
stats.backfill_queue_depth.load(.monotonic),
}) catch {};
w.print("# TYPE jetstream_compaction_tombstones_collected_total counter\n", .{}) catch {};
w.print("# TYPE jetstream_compaction_rows_dropped_total counter\n", .{}) catch {};
inline for (comptime std.enums.values(CompactionReason)) |reason| {
w.print("jetstream_compaction_tombstones_collected_total{{kind=\"{s}\"}} {d}\n", .{
@tagName(reason), stats.compaction_tombstones_collected.getPtrConst(reason).load(.monotonic),
}) catch {};
w.print("jetstream_compaction_rows_dropped_total{{reason=\"{s}\"}} {d}\n", .{
@tagName(reason), stats.compaction_rows_dropped.getPtrConst(reason).load(.monotonic),
}) catch {};
}
const compaction_count = stats.compaction_pass_duration_count.load(.monotonic);
const compaction_sum_us = stats.compaction_pass_duration_sum_us.load(.monotonic);
w.print("# TYPE jetstream_compaction_pass_duration_seconds histogram\n", .{}) catch {};
inline for (0..16) |index| {
const upper_us = @as(u64, 100_000) << @intCast(index);
w.print("jetstream_compaction_pass_duration_seconds_bucket{{le=\"{d}.{d:0>6}\"}} {d}\n", .{
upper_us / std.time.us_per_s, upper_us % std.time.us_per_s,
stats.compaction_pass_duration_buckets[index].load(.monotonic),
}) catch {};
}
w.print(
\\jetstream_compaction_pass_duration_seconds_bucket{{le="+Inf"}} {d}
\\jetstream_compaction_pass_duration_seconds_sum {d}.{d:0>6}
\\jetstream_compaction_pass_duration_seconds_count {d}
\\
, .{ compaction_count, compaction_sum_us / std.time.us_per_s, compaction_sum_us % std.time.us_per_s, compaction_count }) catch {};
const backfill_slow_bounds = [_][]const u8{
"0.01", "0.02", "0.04", "0.08", "0.16", "0.32", "0.64", "1.28",
"2.56", "5.12", "10.24", "20.48", "40.96", "81.92", "163.84",
};
const handle_count = stats.backfill_handle_repo_duration_count.load(.monotonic);
const handle_sum_us = stats.backfill_handle_repo_duration_sum_us.load(.monotonic);
w.print(
"# TYPE jetstream_backfill_handle_repo_duration_seconds histogram\n",
.{},
) catch {};
inline for (backfill_slow_bounds, 0..) |upper, index| w.print(
"jetstream_backfill_handle_repo_duration_seconds_bucket{{le=\"{s}\"}} {d}\n",
.{ upper, stats.backfill_handle_repo_duration_buckets[index].load(.monotonic) },
) catch {};
w.print(
\\jetstream_backfill_handle_repo_duration_seconds_bucket{{le="+Inf"}} {d}
\\jetstream_backfill_handle_repo_duration_seconds_sum {d}.{d:0>6}
\\jetstream_backfill_handle_repo_duration_seconds_count {d}
\\
, .{ handle_count, handle_sum_us / std.time.us_per_s, handle_sum_us % std.time.us_per_s, handle_count }) catch {};
const completion_wait_count = stats.backfill_completion_queue_wait_count.load(.monotonic);
const completion_wait_sum_us = stats.backfill_completion_queue_wait_sum_us.load(.monotonic);
w.print(
"# TYPE jetstream_backfill_completion_queue_wait_seconds histogram\n",
.{},
) catch {};
inline for (backfill_slow_bounds, 0..) |upper, index| w.print(
"jetstream_backfill_completion_queue_wait_seconds_bucket{{le=\"{s}\"}} {d}\n",
.{ upper, stats.backfill_completion_queue_wait_buckets[index].load(.monotonic) },
) catch {};
w.print(
\\jetstream_backfill_completion_queue_wait_seconds_bucket{{le="+Inf"}} {d}
\\jetstream_backfill_completion_queue_wait_seconds_sum {d}.{d:0>6}
\\jetstream_backfill_completion_queue_wait_seconds_count {d}
\\
, .{ completion_wait_count, completion_wait_sum_us / std.time.us_per_s, completion_wait_sum_us % std.time.us_per_s, completion_wait_count }) catch {};
w.print("# TYPE stream_dropped_events_total counter\n", .{}) catch {};
w.print("# TYPE jetstream_ingest_dropped_events_total counter\n", .{}) catch {};
inline for (comptime std.enums.values(convert.DropReason)) |reason| {
w.print("stream_dropped_events_total{{reason=\"{s}\"}} {d}\n", .{
@tagName(reason),
stats.drops.getPtrConst(reason).load(.monotonic),
}) catch {};
w.print("jetstream_ingest_dropped_events_total{{source=\"live\",reason=\"{s}\"}} {d}\n", .{
@tagName(reason),
stats.drops.getPtrConst(reason).load(.monotonic),
}) catch {};
w.print("jetstream_ingest_dropped_events_total{{source=\"backfill\",reason=\"{s}\"}} {d}\n", .{
@tagName(reason),
stats.backfill_drops.getPtrConst(reason).load(.monotonic),
}) catch {};
}
w.print(
\\# TYPE jetstream_verifier_failures_total counter
\\jetstream_verifier_failures_total{{kind="invalid"}} {d}
\\jetstream_verifier_failures_total{{kind="unverified"}} {d}
\\
, .{
stats.verify_invalid.load(.monotonic),
stats.verify_unverified.load(.monotonic),
}) catch {};
w.print(
\\# TYPE jetstream_import_jobs_total counter
\\jetstream_import_jobs_total{{result="ok"}} {d}
\\jetstream_import_jobs_total{{result="error"}} {d}
\\# TYPE jetstream_import_phase gauge
\\jetstream_import_phase {d}
\\# TYPE jetstream_import_rows_parsed_total counter
\\jetstream_import_rows_parsed_total {d}
\\# TYPE jetstream_import_rows_mutated_total counter
\\jetstream_import_rows_mutated_total {d}
\\# TYPE jetstream_import_rows_matched_total counter
\\jetstream_import_rows_matched_total{{scope="all_versions"}} {d}
\\jetstream_import_rows_matched_total{{scope="specific"}} {d}
\\# TYPE jetstream_import_rows_corrupt_offset_total counter
\\jetstream_import_rows_corrupt_offset_total {d}
\\# TYPE jetstream_import_dids_matched_total counter
\\jetstream_import_dids_matched_total {d}
\\# TYPE jetstream_import_segments_examined_total counter
\\jetstream_import_segments_examined_total {d}
\\# TYPE jetstream_import_segments_patched_total counter
\\jetstream_import_segments_patched_total {d}
\\# TYPE jetstream_import_bytes_rewritten_total counter
\\jetstream_import_bytes_rewritten_total {d}
\\# TYPE jetstream_import_job_duration_seconds histogram
\\jetstream_import_job_duration_seconds_sum {d}.{d:0>6}
\\jetstream_import_job_duration_seconds_count {d}
\\
, .{
stats.import_jobs_ok_total.load(.monotonic),
stats.import_jobs_error_total.load(.monotonic),
stats.import_phase.load(.monotonic),
stats.import_rows_parsed_total.load(.monotonic),
stats.import_rows_mutated_total.load(.monotonic),
stats.import_rows_matched_all_total.load(.monotonic),
stats.import_rows_matched_specific_total.load(.monotonic),
stats.import_rows_corrupt_offset_total.load(.monotonic),
stats.import_dids_matched_total.load(.monotonic),
stats.import_segments_examined_total.load(.monotonic),
stats.import_segments_patched_total.load(.monotonic),
stats.import_bytes_rewritten_total.load(.monotonic),
stats.import_job_duration_sum_us.load(.monotonic) / std.time.us_per_s,
stats.import_job_duration_sum_us.load(.monotonic) % std.time.us_per_s,
stats.import_job_duration_count.load(.monotonic),
}) catch {};
w.print("# TYPE jetstream_import_rows_rejected_total counter\n", .{}) catch {};
inline for (comptime std.enums.values(timestamp_parse.RejectReason)) |reason| {
w.print("jetstream_import_rows_rejected_total{{reason=\"{s}\"}} {d}\n", .{
@tagName(reason),
stats.import_rows_rejected.getPtrConst(reason).load(.monotonic),
}) catch {};
}
inline for (0..16) |bucket_index| {
const upper = @as(u64, 1) << @intCast(bucket_index);
w.print("jetstream_import_job_duration_seconds_bucket{{le=\"{d}\"}} {d}\n", .{
upper,
stats.import_job_duration_buckets[bucket_index].load(.monotonic),
}) catch {};
}
w.print("jetstream_import_job_duration_seconds_bucket{{le=\"+Inf\"}} {d}\n", .{
stats.import_job_duration_count.load(.monotonic),
}) catch {};
// Durable repository progress. Sourced from the metadata store rather than
// from process-local counters, so a restart continues the curve instead of
// restarting it. Emitted only when repository state exists: absent is not
// zero, and a progress panel reading zero-of-zero is worse than a gap.
if (durable_repos) |repos| {
w.print(
\\# TYPE stream_backfill_repos_durable gauge
\\stream_backfill_repos_durable{{status="complete"}} {d}
\\stream_backfill_repos_durable{{status="pending"}} {d}
\\stream_backfill_repos_durable{{status="failed"}} {d}
\\stream_backfill_repos_durable{{status="unavailable"}} {d}
\\stream_backfill_repos_durable{{status="not_started"}} {d}
\\# TYPE stream_backfill_repos_durable_total gauge
\\stream_backfill_repos_durable_total {d}
\\
, .{
repos.complete,
repos.pending,
repos.failed,
repos.unavailable,
repos.not_started,
repos.total(),
}) catch {};
}
return w.buffered();
}
fn httpHandlerLabel(value: HttpHandler) []const u8 {
return switch (value) {
.root => "root",
.status => "status",
.subscribe => "subscribe",
.subscribe_v2 => "subscribe-v2",
.xrpc => "xrpc/",
};
}
fn httpMethodLabel(value: HttpMethod) []const u8 {
return switch (value) {
.get => "GET",
.head => "HEAD",
.post => "POST",
.put => "PUT",
.patch => "PATCH",
.delete => "DELETE",
.options => "OPTIONS",
.connect => "CONNECT",
.trace => "TRACE",
.other => "OTHER",
};
}
fn httpCodeLabel(value: HttpCode) []const u8 {
return switch (value) {
.c200 => "200",
.c201 => "201",
.c206 => "206",
.c304 => "304",
.c400 => "400",
.c401 => "401",
.c404 => "404",
.c405 => "405",
.c409 => "409",
.c412 => "412",
.c416 => "416",
.c500 => "500",
.c501 => "501",
.c503 => "503",
.other => "other",
};
}
fn getBlockResultLabel(value: GetBlockResult) []const u8 {
return switch (value) {
.ok => "ok",
.not_found => "not_found",
.bad_request => "bad_request",
.error_result => "error",
};
}
fn storeOpLabel(value: StoreOp) []const u8 {
return switch (value) {
.get => "get",
.set => "set",
.delete => "delete",
.batch_commit => "batch_commit",
};
}
fn storeStatusLabel(value: StoreStatus) []const u8 {
return switch (value) {
.ok => "ok",
.notfound => "notfound",
.error_result => "error",
};
}
// === tests ===
test "http handler labels match upstream public middleware boundaries" {
try std.testing.expectEqual(HttpHandler.root, httpHandler("/", "GET").?);
try std.testing.expectEqual(HttpHandler.status, httpHandler("/status", "GET").?);
try std.testing.expectEqual(HttpHandler.status, httpHandler("/status", "HEAD").?);
try std.testing.expectEqual(HttpHandler.subscribe, httpHandler("/subscribe", "GET").?);
try std.testing.expectEqual(HttpHandler.subscribe_v2, httpHandler("/xrpc/network.bsky.jetstream.subscribeEvents", "GET").?);
try std.testing.expectEqual(HttpHandler.xrpc, httpHandler("/xrpc/network.bsky.jetstream.getBlock", "GET").?);
try std.testing.expectEqual(HttpHandler.xrpc, httpHandler("/xrpc/not-implemented", "POST").?);
try std.testing.expectEqual(null, httpHandler("/metrics", "GET"));
try std.testing.expectEqual(null, httpHandler("/healthz", "GET"));
try std.testing.expectEqual(null, httpHandler("/", "POST"));
try std.testing.expectEqual(null, httpHandler("/not-found", "GET"));
}
test "getBlock metrics preserve upstream result and served-byte semantics" {
var stats: Stats = .{};
stats.observeGetBlock(200, 100, 99);
stats.observeGetBlock(206, 50, 100);
stats.observeGetBlock(304, 0, 101);
stats.observeGetBlock(400, 0, 102);
stats.observeGetBlock(404, 0, 103);
stats.observeGetBlock(412, 0, 104);
stats.observeGetBlock(416, 0, 105);
try std.testing.expectEqual(3, stats.getblock_requests.getPtrConst(.ok).load(.monotonic));
try std.testing.expectEqual(1, stats.getblock_requests.getPtrConst(.bad_request).load(.monotonic));
try std.testing.expectEqual(1, stats.getblock_requests.getPtrConst(.not_found).load(.monotonic));
try std.testing.expectEqual(2, stats.getblock_requests.getPtrConst(.error_result).load(.monotonic));
try std.testing.expectEqual(100, stats.getblock_served_bytes_total.load(.monotonic));
try std.testing.expectEqual(7, stats.getblock_duration_count.load(.monotonic));
}
// Every worker-exit reason renders, zeros included: this family exists so a
// subscriber death during an incident names itself; an absent series must
// mean "not scraped", never "never happened". (2026-08-13: eval connections
// died during compaction passes with no log and no counter.)
test "subscriber worker exits render every reason, zeros included" {
var stats: Stats = .{};
_ = stats.subscribe_worker_exits.getPtr(.write_error).fetchAdd(2, .monotonic);
var buf: [64 * 1024]u8 = undefined;
const out = format(&buf, &stats, 0, .{
.entries = 0,
.bytes = 0,
.pinned_bytes = 0,
.pinned_overrun_bytes = 0,
.base = 0,
.tip = 0,
}, 0, .{
.cpu_us = 0,
.resident_memory_bytes = 0,
.virtual_memory_bytes = 0,
.threads = 0,
.open_fds = 0,
.max_fds = 0,
.minor_page_faults = 0,
.major_page_faults = 0,
.voluntary_context_switches = 0,
.involuntary_context_switches = 0,
}, null, null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_subscribe_worker_exits_total{reason=\"write_error\"} 2") != null);
inline for (comptime std.enums.values(SubscriberExit)) |reason| {
var line_buf: [128]u8 = undefined;
const line = try std.fmt.bufPrint(&line_buf, "stream_subscribe_worker_exits_total{{reason=\"{s}\"}}", .{@tagName(reason)});
try std.testing.expect(std.mem.indexOf(u8, out, line) != null);
}
}
test "format renders counters" {
var stats: Stats = .{};
_ = stats.events_total.fetchAdd(7, .monotonic);
_ = stats.verify_valid.fetchAdd(3, .monotonic);
_ = stats.drops.getPtr(.invalid_rev).fetchAdd(1, .monotonic);
_ = stats.backfill_drops.getPtr(.invalid_rkey).fetchAdd(2, .monotonic);
_ = stats.backfill_completed_total.fetchAdd(11, .monotonic);
_ = stats.ingest_blocks_flushed_total.fetchAdd(6, .monotonic);
_ = stats.ingest_segments_rotated_total.fetchAdd(7, .monotonic);
_ = stats.ingest_append_errors_total.fetchAdd(8, .monotonic);
stats.ingest_active_segment_bytes.store(9000, .monotonic);
_ = stats.livestream_decode_errors_total.fetchAdd(2, .monotonic);
_ = stats.livestream_reconnects_total.fetchAdd(3, .monotonic);
_ = stats.livestream_sequence_gaps_total.fetchAdd(4, .monotonic);
_ = stats.livestream_sequence_gap_missed_seqs_total.fetchAdd(5, .monotonic);
_ = stats.livestream_unknown_events_total.fetchAdd(6, .monotonic);
_ = stats.livestream_stream_error_future_cursor_total.fetchAdd(7, .monotonic);
stats.livestream_last_seen_upstream_event_timestamp_seconds.store(1234, .monotonic);
_ = stats.verify_queue_dropped_total.fetchAdd(9, .monotonic);
_ = stats.replayed_account_events_dropped_total.fetchAdd(3, .monotonic);
_ = stats.replayed_identity_events_dropped_total.fetchAdd(4, .monotonic);
_ = stats.retry_attempts_total.fetchAdd(5, .monotonic);
_ = stats.backfill_discovered_total.fetchAdd(2, .monotonic);
_ = stats.backfill_active_flips_total.fetchAdd(3, .monotonic);
_ = stats.backfill_on_fail_store_errors_total.fetchAdd(4, .monotonic);
stats.observeBackfillHandleRepo(20_000);
stats.backfill_progress_completed.store(11, .monotonic);
_ = stats.backfill_completion_queued_total.fetchAdd(12, .monotonic);
stats.backfill_completion_queue_depth.store(1, .monotonic);
_ = stats.backfill_completion_durable_batches_total.fetchAdd(6, .monotonic);
_ = stats.backfill_completion_durable_repos_total.fetchAdd(11, .monotonic);
_ = stats.backfill_completion_stage_errors_total.fetchAdd(1, .monotonic);
stats.observeBackfillCompletionWait(40_000);
_ = stats.backfill_forced_checkpoint_flushes_total.fetchAdd(7, .monotonic);
_ = stats.retry_passes_total.fetchAdd(8, .monotonic);
_ = stats.retry_candidates_total.fetchAdd(9, .monotonic);
_ = stats.retry_skipped_host_parked_total.fetchAdd(10, .monotonic);
_ = stats.retry_pds_direct_total.fetchAdd(11, .monotonic);
_ = stats.retry_relay_fallback_total.fetchAdd(12, .monotonic);
stats.backfill_workers_active.store(4, .monotonic);
stats.backfill_queue_depth.store(23, .monotonic);
_ = stats.import_jobs_ok_total.fetchAdd(1, .monotonic);
stats.import_phase.store(2, .monotonic);
_ = stats.import_rows_mutated_total.fetchAdd(12, .monotonic);
stats.subscribe_active.getPtr(.zstd).store(2, .monotonic);
_ = stats.subscribe_events_sent.getPtr(.zstd).fetchAdd(3, .monotonic);
_ = stats.subscribe_bytes_sent.getPtr(.zstd).fetchAdd(400, .monotonic);
_ = stats.subscribe_bytes_encoded.getPtr(.zstd).fetchAdd(800, .monotonic);
_ = stats.subscribe_events_filtered_total.fetchAdd(5, .monotonic);
_ = stats.subscribe_events_oversize_total.fetchAdd(6, .monotonic);
_ = stats.subscribe_events_skipped_sync_total.fetchAdd(7, .monotonic);
_ = stats.subscribe_events_skipped_resync_total.fetchAdd(8, .monotonic);
_ = stats.subscribe_encode_errors_total.fetchAdd(9, .monotonic);
_ = stats.subscribe_options_update_errors.getPtr(.invalid_options).fetchAdd(10, .monotonic);
_ = stats.subscribe_cursor_requests.getPtr(.seq).fetchAdd(11, .monotonic);
stats.observeCursorResolve(400);
_ = stats.subscribe_hot_reads_total.fetchAdd(12, .monotonic);
_ = stats.subscribe_cold_reads_total.fetchAdd(13, .monotonic);
_ = stats.subscribe_adversarial_drops_total.fetchAdd(14, .monotonic);
_ = stats.subscribe_clean_disconnects_total.fetchAdd(15, .monotonic);
_ = stats.subscribe_options_updates_total.fetchAdd(16, .monotonic);
stats.observeSegmentSeal(20_000);
stats.observeHttp(.xrpc, .get, 200, 12_000);
stats.observeGetBlock(200, 321, 800);
stats.observeGetBlock(404, 0, 200);
stats.manifest_segments_loaded.store(3, .monotonic);
stats.manifest_resident_bytes.store(4096, .monotonic);
stats.observeCompactionRewriteAge(100_000); // 1d < 100k s <= 3d bucket
stats.compaction_last_pass_unix_s.store(1_786_300_000, .monotonic);
_ = stats.compaction_fold_segments_total.fetchAdd(7, .monotonic);
_ = stats.manifest_block_index_cache_hits_total.fetchAdd(4, .monotonic);
_ = stats.manifest_block_index_cache_misses_total.fetchAdd(5, .monotonic);
stats.observeManifestLoad(400);
stats.observeStore(.get, .ok, 200);
stats.observeStore(.get, .notfound, 400);
stats.observeStore(.set, .error_result, 800);
stats.setOrchestratorPhase(.steady_state);
stats.observeOrchestratorTransition(.bootstrap, .merging);
stats.observeOrchestratorState(.merge, 20_000);
_ = stats.orchestrator_merge_events_kept_total.fetchAdd(17, .monotonic);
_ = stats.orchestrator_merge_events_dropped_total.fetchAdd(18, .monotonic);
_ = stats.orchestrator_merge_segments_consumed_total.fetchAdd(19, .monotonic);
_ = stats.orchestrator_merge_did_lookups_total.fetchAdd(20, .monotonic);
_ = stats.orchestrator_merge_repo_revs_updated_total.fetchAdd(21, .monotonic);
_ = stats.orchestrator_merge_dids_discovered_post_bootstrap_total.fetchAdd(22, .monotonic);
stats.pipeline_submitted.store(20, .monotonic);
stats.pipeline_claimed.store(17, .monotonic);
stats.pipeline_emitted.store(11, .monotonic);
stats.pipeline_fatal.store(1, .monotonic);
_ = stats.pipeline_failures.getPtr(.cursor).fetchAdd(2, .monotonic);
var buf: [64 * 1024]u8 = undefined;
const out = format(&buf, &stats, 2, .{
.entries = 5,
.bytes = 100,
.pinned_bytes = 70,
.pinned_overrun_bytes = 6,
.base = 1,
.tip = 6,
}, 60, .{
.cpu_us = 1_250_000,
.resident_memory_bytes = 4096,
.virtual_memory_bytes = 8192,
.threads = 7,
.open_fds = 11,
.max_fds = 1024,
.minor_page_faults = 31,
.major_page_faults = 2,
.malloc_system_bytes = 5555,
.malloc_free_total_bytes = 444,
.malloc_arena_heaps = 3,
.voluntary_context_switches = 41,
.involuntary_context_switches = 3,
}, 123_456, .{ .complete = 90, .pending = 6, .failed = 3, .unavailable = 1, .not_started = 0 });
try std.testing.expect(std.mem.indexOf(u8, out, "stream_events_total 7") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_verify_total{result=\"valid\"} 3") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_dropped_events_total{reason=\"invalid_rev\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_ingest_dropped_events_total{source=\"live\",reason=\"invalid_rev\"} 1") != null);
// Durable progress is the restart-stable series: it comes from the store,
// not from this process's counters.
try std.testing.expect(std.mem.indexOf(u8, out, "stream_backfill_repos_durable{status=\"complete\"} 90") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_backfill_repos_durable_total 100") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_ingest_dropped_events_total{source=\"backfill\",reason=\"invalid_rkey\"} 2") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_build_info{git_sha=") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_subscribers_active 2") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_ingest_readable_log_bytes 100") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_ingest_readable_log_pinned_bytes 70") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_ingest_readable_log_pinned_overrun_bytes 6") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "process_start_time_seconds 0") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "process_cpu_seconds_total 1.250000") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "process_resident_memory_bytes 4096") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "process_virtual_memory_bytes 8192") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_malloc_system_bytes 5555") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_malloc_free_total_bytes 444") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_malloc_arena_heaps 3") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_process_threads 7") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "process_open_fds 11") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "process_max_fds 1024") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "process_minor_page_faults_total 31") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "process_major_page_faults_total 2") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "process_voluntary_context_switches_total 41") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "process_involuntary_context_switches_total 3") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_data_dir_free_bytes 123456") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_segment_seal_duration_seconds_sum 0.020000") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_segment_seal_duration_seconds_bucket{le=\"0.02\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_segment_seal_duration_seconds_count 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_http_request_duration_seconds_count{handler=\"xrpc/\",method=\"GET\",code=\"200\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_http_request_duration_seconds_bucket{handler=\"xrpc/\",method=\"GET\",code=\"200\",le=\"0.025\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_getblock_requests_total{result=\"ok\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_getblock_requests_total{result=\"not_found\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_getblock_served_bytes_total 321") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_getblock_duration_seconds_count 2") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_manifest_segments_loaded 3") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_manifest_resident_bytes 4096") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_compaction_rewritten_age_seconds_count 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_compaction_last_pass_timestamp_seconds 1786300000") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_compaction_fold_segments_total 7") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_compaction_rewritten_age_seconds_bucket{le=\"86400\"} 0") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_compaction_rewritten_age_seconds_bucket{le=\"259200\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_compaction_rewritten_age_seconds_bucket{le=\"+Inf\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_manifest_block_index_cache_hits_total 4") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_manifest_block_index_cache_misses_total 5") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_manifest_block_index_load_seconds_bucket{le=\"0.0004\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_manifest_block_index_load_seconds_count 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_store_op_duration_seconds_bucket{op=\"get\",status=\"ok\",le=\"0.0002\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_store_op_duration_seconds_count{op=\"get\",status=\"notfound\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_store_op_duration_seconds_count{op=\"set\",status=\"error\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_store_op_duration_seconds_count{op=\"delete\",status=\"error\"} 0") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_orchestrator_phase 3") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_orchestrator_phase_transitions_total{from=\"bootstrap\",to=\"merging\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_orchestrator_state_duration_seconds_bucket{state=\"merge\",le=\"0.02\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_orchestrator_state_duration_seconds_sum{state=\"merge\"} 0.020000") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_orchestrator_merge_events_kept_total 17") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_orchestrator_merge_events_dropped_total 18") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_orchestrator_merge_segments_consumed_total 19") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_orchestrator_merge_did_lookups_total 20") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_orchestrator_merge_repo_revs_updated_total 21") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_orchestrator_merge_dids_discovered_post_bootstrap_total 22") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_pipeline_ticket{stage=\"submitted\"} 20") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_pipeline_stage_gap{boundary=\"submitted_to_claimed\"} 3") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_pipeline_stage_gap{boundary=\"claimed_to_emitted\"} 6") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_pipeline_stage_gap{boundary=\"submitted_to_emitted\"} 9") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_pipeline_fatal 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_pipeline_failures_total{stage=\"cursor\"} 2") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_backfill_repos_total{result=\"complete\"} 11") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_backfill_workers_active 4") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_backfill_queue_depth 23") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_build_info{version=") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_completed_total 11") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_discovered_total 2") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_active_flips_total 3") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_on_fail_store_errors_total 4") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_handle_repo_duration_seconds_bucket{le=\"0.02\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_handle_repo_duration_seconds_count 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_progress_completed 11") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_completion_queued_total 12") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_completion_queue_depth 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_completion_durable_batches_total 6") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_completion_durable_repos_total 11") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_completion_stage_errors_total 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_completion_queue_wait_seconds_bucket{le=\"0.04\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_completion_queue_wait_seconds_count 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_forced_checkpoint_flushes_total 7") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_failed_repo_retry_passes_total 8") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_failed_repo_retry_candidates_total 9") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_failed_repo_retry_skipped_host_parked_total 10") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_backfill_failed_repo_retry_pds_direct_total 11") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "stream_backfill_failed_repo_retry_relay_fallback_total 12") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_ingest_blocks_flushed_total 6") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_ingest_segments_rotated_total 7") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_ingest_append_errors_total 8") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_ingest_active_segment_bytes 9000") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_livestream_decode_errors_total 2") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_livestream_reconnects_total 3") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_livestream_sequence_gaps_total 4") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_livestream_sequence_gap_missed_seqs_total 5") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_livestream_unknown_events_total 6") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_livestream_stream_error_frames_total{code=\"FutureCursor\"} 7") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_livestream_last_seen_upstream_event_timestamp_seconds 1234") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_livestream_verify_queue_dropped_events_total 9") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_import_jobs_total{result=\"ok\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_import_phase 2") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_import_rows_mutated_total 12") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_subscribers{compression=\"zstd\"} 2") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_events_sent_total{compression=\"zstd\"} 3") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_bytes_sent_total{compression=\"zstd\"} 400") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_bytes_encoded_total{compression=\"zstd\"} 800") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_events_filtered_total 5") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_events_oversize_total 6") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_events_skipped_total{reason=\"sync\"} 7") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_events_skipped_total{reason=\"resync_replacement\"} 8") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_encode_errors_total 9") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_options_update_errors_total{reason=\"invalid_options\"} 10") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_cursor_requests_total{mode=\"seq\"} 11") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_cursor_resolve_seconds_bucket{le=\"0.000400\"} 1") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_hot_reads_total 12") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_cold_reads_total 13") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_adversarial_drops_total 14") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_clean_disconnects_total 15") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_subscribe_options_updates_total 16") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_livestream_replayed_account_events_dropped_total 3") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_livestream_replayed_identity_events_dropped_total 4") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_backfill_failed_repo_retry_attempts_total 5") != null);
try std.testing.expect(std.mem.indexOf(u8, out, "jetstream_verifier_failures_total{kind=\"invalid\"}") != null);
}