main
1// The ramp's observability query is lossy the same way a probe is.
2// Run 2026-11-01T19-17-18-170Z (web 07568e0, ply 1743461) reached 100% with 0 errors
3// and 0 probe loss, then `cf o11y telemetry query --body` exited 1 with
4// APIError "timeout" Envelope Error. That one miss rolled the release back.
5import { assertNever } from '../../src/never.ts'
6import { activeLog, type ObservationRef, type RunLog } from './log.ts'
8/** One `cf o11y telemetry query` invocation, timed by the caller. */
9export type QueryCommand = {
10 readonly code: number
11 readonly stdout: string
12 readonly stderr: string
13 readonly latencyMs: number
14}
16/** Exit 0 is the page. Anything else is retried until the policy bound. */
17export type QueryAttempt =
18 | { readonly kind: 'ok'; readonly latencyMs: number; readonly stdout: string }
19 | { readonly kind: 'transient'; readonly latencyMs: number; readonly detail: string }
21/** `attempts` is the bound. The wait before retry n is `backoffMs * 2^(n-1)`. */
22export type QueryBound = {
23 readonly attempts: number
24 readonly backoffMs: number
25}
27export type QueryResult =
28 | { readonly kind: 'ok'; readonly stdout: string; readonly attempts: readonly QueryAttempt[] }
29 | { readonly kind: 'lost'; readonly attempts: readonly QueryAttempt[] }
31export type QueryStep =
32 | { readonly kind: 'call' }
33 | { readonly kind: 'wait'; readonly waitMs: number }
34 | { readonly kind: 'done'; readonly result: QueryResult }
36export type QueryIo = {
37 readonly once: () => Promise<QueryCommand>
38 readonly sleep: (ms: number) => Promise<void>
39}
41type QueryLog = {
42 observation(input: {
43 readonly measurement: unknown
44 readonly query: unknown
45 readonly from: number
46 readonly to: number
47 readonly raw: string
48 }): Promise<ObservationRef>
49}
51function clip(text: string, code: number): string {
52 const flat = text.replace(/\s+/g, ' ').trim()
53 if (flat.length === 0) return `exit ${code}`
54 return flat.slice(0, 240)
55}
57/** A non-zero exit is transient, including APIError "timeout" Envelope Error. The page is exit 0. */
58export function classifyQuery(command: QueryCommand): QueryAttempt {
59 if (command.code === 0) return { kind: 'ok', latencyMs: command.latencyMs, stdout: command.stdout }
60 return { kind: 'transient', latencyMs: command.latencyMs, detail: clip(`${command.stdout}\n${command.stderr}`, command.code) }
61}
63function succeeded(attempts: readonly QueryAttempt[]): QueryAttempt | null {
64 for (const attempt of attempts) {
65 switch (attempt.kind) {
66 case 'ok':
67 return attempt
68 case 'transient':
69 break
70 default:
71 return assertNever(attempt)
72 }
73 }
74 return null
75}
77/** Stop on the first page, or when `bound.attempts` is exhausted. Exhaustion is a lost query. */
78export function queryStep(attempts: readonly QueryAttempt[], bound: QueryBound): QueryStep {
79 const page = succeeded(attempts)
80 if (page && page.kind === 'ok') return { kind: 'done', result: { kind: 'ok', stdout: page.stdout, attempts } }
81 if (attempts.length >= bound.attempts) return { kind: 'done', result: { kind: 'lost', attempts } }
82 if (attempts.length === 0) return { kind: 'call' }
83 return { kind: 'wait', waitMs: bound.backoffMs * 2 ** (attempts.length - 1) }
84}
86export async function retryQuery(bound: QueryBound, io: QueryIo): Promise<QueryResult> {
87 const attempts: QueryAttempt[] = []
88 for (;;) {
89 const step = queryStep(attempts, bound)
90 switch (step.kind) {
91 case 'done':
92 return step.result
93 case 'wait':
94 await io.sleep(step.waitMs)
95 attempts.push(classifyQuery(await io.once()))
96 break
97 case 'call':
98 attempts.push(classifyQuery(await io.once()))
99 break
100 default:
101 return assertNever(step)
102 }
103 }
104}
106export function currentLog(): RunLog | null {
107 const log = activeLog()
108 if (!log) return null
109 return log
110}
112function attemptDetail(attempt: QueryAttempt): string {
113 switch (attempt.kind) {
114 case 'transient':
115 return attempt.detail
116 case 'ok':
117 return ''
118 default:
119 return assertNever(attempt)
120 }
121}
123/** One observation per invocation. The latency is the measurement; a miss is not a decision by itself. */
124export async function recordQueryAttempt(log: QueryLog | null, ordinal: number, attempt: QueryAttempt): Promise<void> {
125 if (log === null) return
126 const to = Date.now()
127 const measurement = {
128 source: 'telemetry-query',
129 attempt: ordinal,
130 kind: attempt.kind,
131 latencyMs: attempt.latencyMs,
132 detail: attemptDetail(attempt),
133 }
134 await log.observation({
135 measurement,
136 query: { source: 'telemetry-query' },
137 from: to - attempt.latencyMs,
138 to,
139 raw: JSON.stringify(measurement),
140 })
141}
Diagnostics4 git calls · 28 ms
CallStatusSizeTime028 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 · hit3 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=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 · hit22 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=22 git.response.bytes=1645 git.response.cache=HIT git.response.duration_ms=22 git.fetch.wants=53e3307d741ebe8e307f0c748df5f24c0f79014e 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=1645 git.pkt.payload.max=1624 git.sideband.band1.bytes=1623 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
- a5e2e74d9ccdecfa
- Request
- a7d9828f…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format