main
ply4 git calls60 ms43 KiB3 cachedprotocol v2
187 lines7.4 KiBRaw
1import { readFile } from 'node:fs/promises'
2import { parseEvent, type CdEvent } from './log.ts'
3import type { Fault } from './result.ts'
5export type FinishedRun = {
6 readonly runId: string
7 readonly at: string
8 readonly verdict: 'pass' | 'fail'
9 readonly rolledBack: boolean
10 readonly versionId: string | null
11 readonly plyMergedAt: string | null
12 readonly liveAt: string | null
13 readonly failedAt: string | null
14 readonly restoredAt: string | null
15 readonly fault: Fault | null
16 readonly stages: readonly { readonly name: string; readonly durationMs: number }[]
19/** run_finished lines are the delivery record. Other events are ignored here. */
20export function finishedRuns(events: readonly CdEvent[]): FinishedRun[] {
21 const runs: FinishedRun[] = []
22 for (const event of events) {
23 if (event.kind !== 'lifecycle') continue
24 const payload = event.payload
25 if (payload.event !== 'run_finished') continue
26 const stages = payload.stages.map(stage => ({ name: stage.name, durationMs: stage.durationMs }))
27 runs.push({
28 runId: event.run_id,
29 at: event.ts,
30 verdict: payload.verdict,
31 rolledBack: payload.rolledBack,
32 versionId: payload.versionId,
33 plyMergedAt: payload.plyMergedAt,
34 liveAt: payload.liveAt,
35 failedAt: payload.failedAt,
36 restoredAt: payload.restoredAt,
37 fault: payload.fault,
38 stages,
39 })
40 }
41 return runs
44export function quantile(values: readonly number[], p: number): number | null {
45 const sorted = values.filter(value => Number.isFinite(value)).slice().sort((a, b) => a - b)
46 if (sorted.length === 0) return null
47 return sorted[Math.floor((sorted.length - 1) * p)] ?? null
50function seconds(ms: number | null): string {
51 if (ms === null) return '-'
52 return `${Math.round(ms / 1000)}s`
55function stamp(value: string | null): number | null {
56 if (!value) return null
57 const parsed = Date.parse(value)
58 return Number.isFinite(parsed) ? parsed : null
61type Aside = 'aborted' | 'held' | 'harness_fault'
63export type FalsePositive = {
64 readonly runId: string
65 readonly reason: string
68/** The latest false-positive note for each run. An annotation does not delete the run_finished line. */
69export function falsePositives(events: readonly CdEvent[]): FalsePositive[] {
70 const notes = new Map<string, string>()
71 for (const event of events) {
72 if (event.kind !== 'annotation' || event.payload.note !== 'false_positive') continue
73 notes.set(event.run_id, event.payload.reason)
74 }
75 return [...notes].map(([runId, reason]) => ({ runId, reason }))
78/** A deploy reached 100% and was not a harness fault. Aborted, held, and harness_fault runs are not deploys. */
79function isDeploy(run: FinishedRun): boolean {
80 return run.liveAt !== null && run.fault !== 'harness_fault'
83function asideOf(run: FinishedRun): Aside {
84 if (run.fault === 'harness_fault') return 'harness_fault'
85 if (run.fault === 'state_conflict' || (run.verdict === 'fail' && !run.rolledBack)) return 'held'
86 return 'aborted'
89/**
90 * DORA figures from run_finished events.
91 * A deploy reached 100% (`liveAt`) and is not a harness_fault. Aborted, held, and
92 * harness_fault runs are counted separately and are not deploys.
93 * Frequency is deploys / days between the first and last deploy. One timestamp has no rate.
94 * Lead time is plyMergedAt → liveAt on a passing deploy.
95 * Change failure is rollbacks / deploys. A run annotated as a false positive is in neither number.
96 * Time to restore is failedAt → restoredAt on a rolled-back deploy.
97 */
98export function doraText(events: readonly CdEvent[]): string {
99 const notes = falsePositives(events)
100 const annotated = new Set(notes.map(note => note.runId))
101 const finished = finishedRuns(events)
102 if (finished.length === 0 && notes.length === 0) return 'no run_finished events in the ledger\n'
103 const counted = finished.filter(run => !annotated.has(run.runId))
104 const fpRuns = finished.filter(run => annotated.has(run.runId))
105 const deploys = counted.filter(isDeploy)
106 const aside = counted.filter(run => !isDeploy(run))
107 const asideCount = (kind: Aside) => aside.filter(run => asideOf(run) === kind).length
108 const lines = [
109 `runs: ${finished.length}`,
110 `deploys: ${deploys.length}`,
111 `excluded from deploys: ${aside.length + fpRuns.length}`,
112 ` aborted: ${asideCount('aborted')}`,
113 ` held: ${asideCount('held')}`,
114 ` harness_fault: ${asideCount('harness_fault')}`,
115 ` false_positive: ${fpRuns.length}`,
116 `false positives: ${notes.length}`,
117 ]
118 for (const note of notes) lines.push(` ${note.runId}: ${note.reason}`)
119 if (notes.length > 0) lines.push(' excluded from deploys and from change failure rate')
120 const times = deploys.map(run => stamp(run.at)).filter((value): value is number => value !== null).sort((a, b) => a - b)
121 const first = times[0]
122 const last = times[times.length - 1]
123 if (deploys.length >= 2 && first !== undefined && last !== undefined && last > first) {
124 const days = (last - first) / 86_400_000
125 lines.push(`deployment frequency: ${(deploys.length / days).toFixed(3)} / day`)
126 lines.push(` ${deploys.length} deploys / ${days.toFixed(2)} days between the first and last deploy that reached 100%`)
127 } else {
128 lines.push('deployment frequency: -')
129 lines.push(' needs two deploys with different timestamps')
130 }
131 const leads = deploys.flatMap(run => {
132 if (run.verdict !== 'pass') return []
133 const merged = stamp(run.plyMergedAt)
134 const live = stamp(run.liveAt)
135 if (merged === null || live === null || live < merged) return []
136 return [live - merged]
137 })
138 lines.push(`lead time p50: ${seconds(quantile(leads, 0.5))} p90: ${seconds(quantile(leads, 0.9))}`)
139 lines.push(` ply merge → 100% live, ${leads.length} passing deploy${leads.length === 1 ? '' : 's'} with both timestamps`)
140 const failed = deploys.filter(run => run.rolledBack).length
141 const rate = deploys.length === 0 ? 0 : failed / deploys.length
142 lines.push(`change failure rate: ${rate.toFixed(3)}`)
143 lines.push(` ${failed} rollbacks / ${deploys.length} deploys`)
144 const restores = deploys.flatMap(run => {
145 if (!run.rolledBack) return []
146 const from = stamp(run.failedAt)
147 const to = stamp(run.restoredAt)
148 if (from === null || to === null || to < from) return []
149 return [to - from]
150 })
151 lines.push(`time to restore p50: ${seconds(quantile(restores, 0.5))} p90: ${seconds(quantile(restores, 0.9))}`)
152 lines.push(` failure → rollback complete, ${restores.length} rollback${restores.length === 1 ? '' : 's'} with both timestamps`)
153 const byStage = new Map<string, number[]>()
154 for (const run of finished) {
155 for (const stage of run.stages) {
156 const list = byStage.get(stage.name) ?? []
157 list.push(stage.durationMs)
158 byStage.set(stage.name, list)
159 }
160 }
161 lines.push('stage durations:')
162 for (const [name, values] of byStage) {
163 lines.push(` ${name} p50 ${seconds(quantile(values, 0.5))} p90 ${seconds(quantile(values, 0.9))} (n=${values.length})`)
164 }
165 return lines.join('\n') + '\n'
168export async function reportLedger(path: string): Promise<string> {
169 let text = ''
170 try {
171 text = await readFile(path, 'utf8')
172 } catch {
173 return `no ledger at ${path}\n`
174 }
175 const events: CdEvent[] = []
176 let skipped = 0
177 for (const line of text.split('\n')) {
178 if (!line.trim()) continue
179 try {
180 events.push(parseEvent(JSON.parse(line) as unknown))
181 } catch {
182 skipped += 1
183 }
184 }
185 const body = doraText(events)
186 return skipped ? `${body}${skipped} ledger line${skipped === 1 ? '' : 's'} skipped\n` : body
Diagnostics4 git calls · 60 ms
CallStatusSizeTime060 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200145 B · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 KiB · hit7 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=41349
git.response.cache=HIT
git.response.duration_ms=7
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=41349
git.pkt.payload.max=41254
git.sideband.band1.bytes=41253
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=61
git.pack.bytes=41253
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c
git.pack.full=61
Open pack map
fetch2002.5 KiB · hit50 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=50
git.response.bytes=2550
git.response.cache=HIT
git.response.duration_ms=50
git.fetch.wants=c2239bf80e78ade0e0d0ba719f26be33d4631342
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=2550
git.pkt.payload.max=2529
git.sideband.band1.bytes=2528
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
Ref
refs/heads/main
Commit
526b305930b8ef382f2d7a1f9c0238730a585921
cf-ray
a5e2cf429b71efad
Request
b569d5bf…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format