main
1import { strict as assert } from 'node:assert'
2import { test } from 'node:test'
3import { loadPolicy, DEFAULT_POLICY_PATH } from '../scripts/cd/policy.ts'
4import { statsFromEvents } from '../scripts/cd/telemetry.ts'
5import { judgeStep, type StepInput } from '../scripts/cd/slo.ts'
7type CfEvent = Record<string, unknown>
9function randLCG(seed: number): () => number {
10 let s = seed >>> 0
11 return () => {
12 s = (1664525 * s + 1013904223) >>> 0
13 return s / 0xffffffff
14 }
15}
17function fetchEvent(version: string, outcome: string): CfEvent {
18 return {
19 $metadata: { type: 'cf-worker-event' },
20 $workers: {
21 eventType: 'fetch',
22 scriptVersion: { id: version },
23 outcome,
24 },
25 }
26}
28function logEvent(version: string, status: number): CfEvent {
29 return {
30 $metadata: { level: status >= 500 ? 'error' : 'info' },
31 $workers: { scriptVersion: { id: version } },
32 source: { msg: 'ply.request', http: { response: { statusCode: status } } },
33 }
34}
36function eventVersion(e: CfEvent): string | null {
37 const w = (e as any).$workers
38 if (!w || typeof w !== 'object') return null
39 const sv = (w as any).scriptVersion
40 if (!sv || typeof sv !== 'object') return null
41 const id = (sv as any).id
42 return typeof id === 'string' ? id : null
43}
45function asStepInput(stats: ReturnType<typeof statsFromEvents>): StepInput {
46 return {
47 requests: stats.requests,
48 invocations: stats.invocations,
49 exceptions: stats.exceptions,
50 errors: stats.errors,
51 fivexx: stats.fivexx,
52 errorLogs: stats.errorLogs,
53 wallMs: stats.wallMs,
54 v1: stats.v1,
55 }
56}
58test('1000x: client-caused outcomes (canceled/clientDisconnected/responseStreamDisconnected) never roll back (old or new)', () => {
59 const { policy } = loadPolicy(DEFAULT_POLICY_PATH)
60 // The fixtures split traffic evenly between the versions; judge them at the split they model.
61 const targetPercent = 50
62 const rand = randLCG(0x12345678)
63 const NEW = 'new-ver'
64 const OLD = 'old-ver'
65 const clientOutcomes = ['canceled', 'clientDisconnected', 'responseStreamDisconnected'] as const
67 let rollbacks = 0
68 for (let i = 0; i < 1000; i++) {
69 const events: CfEvent[] = []
70 const nOld = 100 + Math.floor(rand() * 50)
71 // Within the 50% share band (z=3): the routed-share gate is not what this test is about.
72 const nNew = nOld + Math.floor(rand() * 11) - 5
73 for (let j = 0; j < nOld; j++) events.push(fetchEvent(OLD, clientOutcomes[j % clientOutcomes.length]))
74 for (let j = 0; j < nNew; j++) events.push(fetchEvent(NEW, clientOutcomes[(j + 1) % clientOutcomes.length]))
75 const next = asStepInput(statsFromEvents(events.filter(e => eventVersion(e) === NEW), []))
76 const previous = asStepInput(statsFromEvents(events.filter(e => eventVersion(e) === OLD), []))
77 const aggregate = asStepInput(statsFromEvents(events, []))
78 const decision = judgeStep({ next, previous, aggregate, targetPercent, policy })
79 if (decision.outcome === 'rollback') rollbacks += 1
80 }
81 assert.equal(rollbacks, 0, `expected 0 rollbacks for client-caused outcomes, saw ${rollbacks}`)
82})
84test('1000x: new-version worker faults roll back (exception or 5xx)', () => {
85 const { policy } = loadPolicy(DEFAULT_POLICY_PATH)
86 // The fixtures split traffic evenly between the versions; judge them at the split they model.
87 const targetPercent = 50
88 const rand = randLCG(0xC0FFEE)
89 const NEW = 'new-ver'
90 const OLD = 'old-ver'
92 // A: exceptions on new
93 let rollbackExceptions = 0
94 for (let i = 0; i < 500; i++) {
95 const events: CfEvent[] = []
96 const nOld = 100 + Math.floor(rand() * 50)
97 const nNew = 100 + Math.floor(rand() * 50)
98 for (let j = 0; j < nOld; j++) events.push(fetchEvent(OLD, 'ok'))
99 for (let j = 0; j < nNew; j++) events.push(fetchEvent(NEW, j === 0 ? 'exception' : 'ok'))
100 const next = asStepInput(statsFromEvents(events.filter(e => eventVersion(e) === NEW), []))
101 const previous = asStepInput(statsFromEvents(events.filter(e => eventVersion(e) === OLD), []))
102 const aggregate = asStepInput(statsFromEvents(events, []))
103 const decision = judgeStep({ next, previous, aggregate, targetPercent, policy })
104 if (decision.outcome === 'rollback') rollbackExceptions += 1
105 }
107 // B: 5xx on new (via logs)
108 let rollback5xx = 0
109 for (let i = 0; i < 500; i++) {
110 const events: CfEvent[] = []
111 const nOld = 100 + Math.floor(rand() * 50)
112 const nNew = 100 + Math.floor(rand() * 50)
113 for (let j = 0; j < nOld; j++) events.push(fetchEvent(OLD, 'ok'))
114 for (let j = 0; j < nNew; j++) events.push(fetchEvent(NEW, 'ok'))
115 // one 5xx log on NEW
116 events.push(logEvent(NEW, 503))
117 const next = asStepInput(statsFromEvents(events.filter(e => eventVersion(e) === NEW), []))
118 const previous = asStepInput(statsFromEvents(events.filter(e => eventVersion(e) === OLD), []))
119 const aggregate = asStepInput(statsFromEvents(events, []))
120 const decision = judgeStep({ next, previous, aggregate, targetPercent, policy })
121 if (decision.outcome === 'rollback') rollback5xx += 1
122 }
124 assert.equal(rollbackExceptions, 500, `expected 100% rollback with exceptions on new, saw ${rollbackExceptions}/500`)
125 assert.equal(rollback5xx, 500, `expected 100% rollback with 5xx on new, saw ${rollback5xx}/500`)
126})
128test('regression: 021b436e — two timed-out probes (2/2000) do not roll back', () => {
129 const { policy } = loadPolicy(DEFAULT_POLICY_PATH)
130 // The fixtures split traffic evenly between the versions; judge them at the split they model.
131 const targetPercent = 50
132 const NEW = 'new-ver'
133 const OLD = 'old-ver'
134 const events: CfEvent[] = []
135 // 1998 ok fetches split evenly, plus 2 client timeouts on old
136 for (let i = 0; i < 999; i++) events.push(fetchEvent(NEW, 'ok'))
137 for (let i = 0; i < 999; i++) events.push(fetchEvent(OLD, 'ok'))
138 events.push(fetchEvent(OLD, 'canceled'))
139 events.push(fetchEvent(OLD, 'clientDisconnected'))
140 const next = asStepInput(statsFromEvents(events.filter(e => eventVersion(e) === NEW), []))
141 const previous = asStepInput(statsFromEvents(events.filter(e => eventVersion(e) === OLD), []))
142 const aggregate = asStepInput(statsFromEvents(events, []))
143 const decision = judgeStep({ next, previous, aggregate, targetPercent, policy })
144 assert.notEqual(decision.outcome, 'rollback')
145})
Diagnostics4 git calls · 27 ms
CallStatusSizeTime027 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 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 · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=41349 git.response.cache=HIT git.response.duration_ms=3 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=61Open pack map
fetch2001.6 KiB · hit21 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=21 git.response.bytes=1688 git.response.cache=HIT git.response.duration_ms=21 git.fetch.wants=73bb716d78c36fa717fae429657e6fb6d1fefcfe 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=1688 git.pkt.payload.max=1667 git.sideband.band1.bytes=1666 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
- a5e3339fad4cf485
- Request
- bc658d9e…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format