main
ply4 git calls49 ms43 KiB3 cachedprotocol v2
127 lines5.8 KiBRaw
1// Row identity and paging of Workers Observability event queries (scripts/cd/o11y.ts, scripts/cd/telemetry.ts).
2// `$metadata.id` is a millisecond plus a per-invocation row position, so distinct rows share it (2026-11-08 ramp runs).
3import assert from 'node:assert/strict'
4import { test } from 'node:test'
5import { TELEMETRY_PAGE } from '../scripts/cd/baseline.ts'
6import { useCfRunner, type CfResult } from '../scripts/cd/cf.ts'
7import { queryCaptured, queryCapturedSliced, type QueryRetry } from '../scripts/cd/o11y.ts'
8import { dedupeRows, pageCursor, rowKey } from '../scripts/cd/telemetry.ts'
10type Meta = Record<string, string | null>
11const row = (meta: Meta, extra: object = {}) => ({ $metadata: meta, ...extra })
12const metaOf = (value: unknown) => (value as { $metadata: Meta }).$metadata
14const RETRY: QueryRetry = { bound: { attempts: 1, backoffMs: 0 }, sleep: async () => {}, note: async () => {} }
16/** The real index: newest id first, `offset` returns only ids strictly below it, `limit` per page. */
17function serve(rows: readonly unknown[]): void {
18 const sorted = [...rows].sort((a, b) => {
19 const x = String(metaOf(a).id)
20 const y = String(metaOf(b).id)
21 return x < y ? 1 : x > y ? -1 : 0
22 })
23 useCfRunner(async (args): Promise<CfResult> => {
24 const body = JSON.parse(String(args[4])) as Record<string, unknown>
25 const offset = 'offset' in body ? String(body.offset) : null
26 const page = sorted.filter(item => offset === null || String(metaOf(item).id) < offset).slice(0, Number(body.limit))
27 return { code: 0, stdout: JSON.stringify({ events: { events: page } }), stderr: '' }
28 })
31function serveSlices(slices: readonly (readonly unknown[])[]): void {
32 let call = 0
33 useCfRunner(async (): Promise<CfResult> => {
34 const page = call < slices.length ? slices[call] : []
35 call += 1
36 return { code: 0, stdout: JSON.stringify({ events: { events: page } }), stderr: '' }
37 })
40test('two invocations in the same ms and row position are two rows', async () => {
41 const a = row({ id: 'X', requestId: 'r1', traceId: 't1' })
42 const b = row({ id: 'X', requestId: 'r2', traceId: 't2' })
43 try {
44 serveSlices([[a, b]])
45 const got = await queryCapturedSliced('events', 0, 1000, [], RETRY)
46 assert.equal(got.events.length, 2)
47 } finally {
48 useCfRunner(null)
49 }
50})
52test('the same row in two overlapping slices is one row', async () => {
53 const a = row({ id: 'X', requestId: 'r1', traceId: 't1' })
54 try {
55 serveSlices([[a], [a]])
56 const got = await queryCapturedSliced('events', 0, 20_000, [], RETRY)
57 assert.equal(got.events.length, 1)
58 } finally {
59 useCfRunner(null)
60 }
61})
63test('span rows have a null requestId: same id, different spans stay; the same span twice is one', () => {
64 const first = row({ id: 'S', requestId: null, traceId: 't1', spanId: 'a' })
65 const other = row({ id: 'S', requestId: null, traceId: 't2', spanId: 'b' })
66 const sameTraceOtherSpan = row({ id: 'S', requestId: null, traceId: 't1', spanId: 'c' })
67 assert.equal(dedupeRows([first, other, sameTraceOtherSpan]).length, 3)
68 assert.equal(dedupeRows([first, first]).length, 1)
69})
71test('a row with no id is never compared', () => {
72 assert.equal(rowKey(row({})), null)
73 assert.equal(rowKey({ traceId: 't' }), null)
74 const noId = row({})
75 assert.equal(dedupeRows([noId, noId]).length, 2)
76})
78test('pageCursor steps back past the final id so a split same-id group is re-read', () => {
79 assert.equal(pageCursor([row({ id: 'C' }), row({ id: 'B' }), row({ id: 'A' })]), 'B')
80 assert.equal(pageCursor([row({ id: 'C' }), row({ id: 'A', requestId: '1' }), row({ id: 'A', requestId: '2' })]), 'C')
81 assert.equal(pageCursor([row({ id: 'A', requestId: '1' }), row({ id: 'A', requestId: '2' })]), null, 'all one id: no way to advance')
82 assert.equal(pageCursor([row({})]), null)
83 assert.equal(pageCursor([]), null)
84})
86test('a page boundary inside a same-id group neither skips nor repeats a row', async () => {
87 // Newest first: page 1 ends on the first of the pair `P`; the second of it sorts onto page 2.
88 const fill = (n: number, from: number) => Array.from({ length: n }, (_, i) => row({ id: `Z${String(from + i).padStart(5, '0')}`, requestId: `f${from + i}` }))
89 const newer = fill(TELEMETRY_PAGE - 1, 0)
90 const pair = [row({ id: 'M', requestId: 'p1', traceId: 't1' }), row({ id: 'M', requestId: 'p2', traceId: 't2' })]
91 const older = [row({ id: 'A', requestId: 'o1' }), row({ id: 'A', requestId: 'o2' })]
92 try {
93 serve([...newer, ...pair, ...older])
94 const got = await queryCaptured('events', 0, 1000, [], RETRY)
95 const ids = got.events.map(event => `${String(metaOf(event).id)}/${String(metaOf(event).requestId)}`)
96 assert.equal(new Set(ids).size, ids.length, 'no repeats')
97 assert.equal(ids.length, newer.length + pair.length + older.length, 'no skips')
98 assert.ok(ids.includes('M/p1') && ids.includes('M/p2'))
99 } finally {
100 useCfRunner(null)
101 }
102})
104test('a full page of one id cannot page further and fails loudly rather than looping', async () => {
105 const all = Array.from({ length: TELEMETRY_PAGE }, (_, i) => row({ id: 'X', requestId: `r${i}` }))
106 try {
107 serve(all)
108 await assert.rejects(queryCaptured('events', 0, 1000, [], RETRY), /no usable \$metadata\.id cursor/)
109 } finally {
110 useCfRunner(null)
111 }
112})
114test('adjacent slices share their edge millisecond: the timeframe excludes both endpoints', async () => {
115 const frames: { from: number; to: number }[] = []
116 useCfRunner(async (args): Promise<CfResult> => {
117 const body = JSON.parse(String(args[4])) as { timeframe: { from: number; to: number } }
118 frames.push(body.timeframe)
119 return { code: 0, stdout: JSON.stringify({ events: { events: [] } }), stderr: '' }
120 })
121 try {
122 await queryCapturedSliced('events', 0, 25_000, [], RETRY)
123 } finally {
124 useCfRunner(null)
125 }
126 assert.deepEqual(frames, [{ from: 0, to: 10_001 }, { from: 10_000, to: 20_001 }, { from: 20_000, to: 25_001 }])
127})
Diagnostics4 git calls · 49 ms
CallStatusSizeTime049 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 · hit12 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=12
git.response.bytes=41349
git.response.cache=HIT
git.response.duration_ms=12
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.0 KiB · hit34 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=34
git.response.bytes=2059
git.response.cache=HIT
git.response.duration_ms=34
git.fetch.wants=32cd42244f5ba61ffa80703dc28ceb64a6b40b0c
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=2059
git.pkt.payload.max=2038
git.sideband.band1.bytes=2037
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
a5e328c369294628
Request
d37793c8…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format