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
#!/usr/bin/env python3
"""Deterministically adapt Jetstream's dashboard for the Stream runtime."""
from __future__ import annotations
import copy
import hashlib
import json
import pathlib
import sys
ROOT = pathlib.Path(__file__).resolve().parents[1]
SOURCE = ROOT / "deploy/grafana/jetstream-upstream.json"
OUTPUT = ROOT / "deploy/grafana/stream.json"
SOURCE_SHA256 = "ef6033c182d8c3f9d88af7d91e61126724efbe72e6b940984c9de12e9530cd91"
def target(template: dict, expr: str, legend: str, ref_id: str) -> dict:
value = copy.deepcopy(template)
value.update(expr=expr, legendFormat=legend, refId=ref_id)
return value
def pipeline_panel(template: dict, panel_id: int, title: str, description: str, x: int) -> dict:
panel = copy.deepcopy(template)
panel.update(
id=panel_id,
title=title,
description=description,
gridPos={"h": 8, "w": 8, "x": x, "y": 176},
)
panel["fieldConfig"]["defaults"]["unit"] = "short"
panel["fieldConfig"]["defaults"]["min"] = 0
panel["fieldConfig"]["overrides"] = []
return panel
def progress_panel(template: dict) -> dict:
panel = copy.deepcopy(template)
panel.update(
id=81,
type="timeseries",
title="Backfill repositories over time",
description=(
"Absolute repository counts across the current backfill run. listRepos is fetched in pages "
"of 1,000; Stream follows upstream Jetstream V2 by accumulating about 100,000 "
"entries before shuffling and dispatching a batch. Durably committed advances only "
"after that batch checkpoint. These lines are not a percentage of the full network."
),
gridPos={"h": 8, "w": 24, "x": 0, "y": 171},
)
panel["fieldConfig"]["defaults"]["unit"] = "short"
panel["fieldConfig"]["defaults"]["min"] = 0
panel["options"] = {
"legend": {
"calcs": ["lastNotNull"],
"displayMode": "table",
"placement": "bottom",
"showLegend": True,
},
"tooltip": {"mode": "multi", "sort": "desc"},
}
discovered = panel["targets"][0]
discovered.update(
expr=(
'sum(jetstream_backfill_discovered_total'
'{job=~"$job",instance=~"$instance"})'
),
legendFormat="discovered",
refId="A",
range=True,
instant=False,
)
processed = copy.deepcopy(discovered)
processed.update(
expr=(
'sum(jetstream_backfill_completion_queued_total'
'{job=~"$job",instance=~"$instance"})'
),
legendFormat="processed",
refId="B",
)
# jetstream_backfill_progress_completed is process-local: it resets to zero
# on restart and climbs again, so a series labelled "durably committed" was
# showing this process's work rather than the archive's. That mislabel is
# what made a restart read as progress in July. The durable series is read
# from the metadata store at scrape time and continues across a restart.
durable = copy.deepcopy(discovered)
durable.update(
expr=(
'sum(stream_backfill_repos_durable{status="complete",'
'job=~"$job",instance=~"$instance"})'
),
legendFormat="durably committed",
refId="C",
range=True,
instant=False,
)
panel["targets"] = [discovered, processed, durable]
return panel
def adapt(raw: bytes) -> bytes:
digest = hashlib.sha256(raw).hexdigest()
if digest != SOURCE_SHA256:
raise ValueError(f"upstream dashboard checksum mismatch: expected {SOURCE_SHA256}, got {digest}")
dashboard = json.loads(raw)
panels = {panel.get("id"): panel for panel in dashboard["panels"]}
expected = {
3: "Uptime",
69: "CPU",
70: "Memory",
71: "Goroutines & threads",
72: "File descriptors",
73: "GC pauses",
74: "Process network I/O",
75: "Process & Go runtime",
}
for panel_id, title in expected.items():
if panels.get(panel_id, {}).get("title") != title:
raise ValueError(f"upstream runtime panel {panel_id} is no longer {title!r}")
selector = '{job=~"$job",instance=~"$instance"}'
rate = "[$__rate_interval]"
panels[75]["title"] = "Process runtime"
# Standard process collector families retain their upstream meaning.
panels[69]["targets"] = [copy.deepcopy(panels[69]["targets"][0])]
memory_template = panels[70]["targets"][0]
panels[70]["targets"] = [
target(memory_template, f"max(process_resident_memory_bytes{selector})", "RSS", "A"),
target(memory_template, f"max(process_virtual_memory_bytes{selector})", "virtual", "B"),
]
thread_template = panels[71]["targets"][0]
panels[71]["title"] = "Threads"
panels[71]["targets"] = [
target(thread_template, f"max(stream_process_threads{selector})", "OS threads", "A")
]
fault_template = panels[73]["targets"][0]
panels[73]["title"] = "Page faults"
panels[73]["targets"] = [
target(fault_template, f"sum(rate(process_minor_page_faults_total{selector}{rate}))", "minor/s", "A"),
target(fault_template, f"sum(rate(process_major_page_faults_total{selector}{rate}))", "major/s", "B"),
]
panels[73]["fieldConfig"]["defaults"]["unit"] = "ops"
switch_template = panels[74]["targets"][0]
panels[74]["title"] = "Context switches"
panels[74]["targets"] = [
target(
switch_template,
f"sum(rate(process_voluntary_context_switches_total{selector}{rate}))",
"voluntary/s",
"A",
),
target(
switch_template,
f"sum(rate(process_involuntary_context_switches_total{selector}{rate}))",
"involuntary/s",
"B",
),
]
panels[74]["fieldConfig"]["defaults"]["unit"] = "ops"
# Show absolute repository counts over time. The upstream completion ratio
# remains in its original panel, but it is approximate while listRepos is
# still expanding the denominator.
progress_row = copy.deepcopy(panels[75])
progress_row.update(
id=80,
title="Backfill progress over time",
description="The final network denominator is unknown until listRepos discovery finishes.",
gridPos={"h": 1, "w": 24, "x": 0, "y": 170},
)
progress_template = next(panel for panel in dashboard["panels"] if panel.get("type") == "timeseries")
progress = progress_panel(progress_template)
# Upstream has no scheduler between its websocket reader and archive
# writer. Stream does, so retain every upstream protocol/lifecycle panel
# byte-for-byte and append a clearly Stream-specific diagnostics row.
diagnostics_row = copy.deepcopy(panels[75])
diagnostics_row.update(
id=76,
title="Stream pipeline diagnostics",
description="Live during bootstrap and steady state; gaps and terminal failures are never inferred from archive throughput.",
gridPos={"h": 1, "w": 24, "x": 0, "y": 175},
)
tickets = pipeline_panel(
panels[69],
77,
"Pipeline tickets",
"Cumulative scheduler boundaries. Emitted is the historical name for every settled ticket, including explicit drops and verifier rejections.",
0,
)
tickets["targets"] = [
target(
panels[69]["targets"][0],
f'max(stream_pipeline_ticket{selector}) by (stage)',
"{{stage}}",
"A",
)
]
gaps = pipeline_panel(
panels[69],
78,
"Pipeline stage gaps",
"Current unsettled work split between the unclaimed verifier queue and claimed work awaiting settlement. Their sum is submitted-to-emitted.",
8,
)
gaps["targets"] = [
target(
panels[69]["targets"][0],
f'max(stream_pipeline_stage_gap{selector}) by (boundary)',
"{{boundary}}",
"A",
)
]
failures = pipeline_panel(
panels[69],
79,
"Pipeline terminal failures",
"Any non-zero value is deployment-significant. The gauge marks the current pipeline fatal; the counters retain its first failing stage.",
16,
)
failures["targets"] = [
target(
panels[69]["targets"][0],
f'max(stream_pipeline_fatal{selector})',
"fatal",
"A",
),
target(
panels[69]["targets"][0],
f'sum(stream_pipeline_failures_total{selector}) by (stage)',
"{{stage}} failures",
"B",
),
]
failures["fieldConfig"]["defaults"]["thresholds"] = {
"mode": "absolute",
"steps": [
{"color": "green", "value": None},
{"color": "red", "value": 1},
],
}
failures["fieldConfig"]["defaults"]["custom"]["thresholdsStyle"] = {"mode": "line"}
dashboard["panels"].extend([progress_row, progress, diagnostics_row, tickets, gaps, failures])
dashboard["title"] = "Stream / Jetstream V2"
dashboard["uid"] = "stream-jetstream-v2"
dashboard["tags"] = ["stream", "jetstream", "atproto"]
dashboard["description"] = (
"Stream operational dashboard adapted from the checksum-pinned Jetstream V2 dashboard. "
"Protocol and lifecycle rows are unchanged; the runtime row uses Stream process metrics, "
"and final Stream-only rows expose backfill work over time and scheduler health."
)
return (json.dumps(dashboard, indent=2, ensure_ascii=False) + "\n").encode()
def main() -> int:
generated = adapt(SOURCE.read_bytes())
if len(sys.argv) == 2 and sys.argv[1] == "--check":
if not OUTPUT.exists() or OUTPUT.read_bytes() != generated:
print(f"{OUTPUT} is stale; run tools/adapt_dashboard.py", file=sys.stderr)
return 1
print(f"stream dashboard sha256={hashlib.sha256(generated).hexdigest()}")
return 0
if len(sys.argv) != 1:
print("usage: tools/adapt_dashboard.py [--check]", file=sys.stderr)
return 2
OUTPUT.write_bytes(generated)
print(f"wrote {OUTPUT} sha256={hashlib.sha256(generated).hexdigest()}")
return 0
if __name__ == "__main__":
raise SystemExit(main())