main
ply4 git calls30 ms42 KiB3 cachedprotocol v2
117 lines6.3 KiBRaw
1import { describe, expect, it } from 'vitest';
2import { none } from '../../src/option.ts';
3import { emitEval, evalLog, resolveLog, type EvalSample, type SpanLike } from '../../src/flags/telemetry.ts';
4import { MEASUREMENT, flagLogQuery, renderReport, reportFromEvents } from '../../src/flags/report.ts';
5import { measureRounds } from '../../src/flags/propagation.ts';
7/** One property. A null receiver and a missing key are holes. A stored null stays null. */
8function slot(receiver: unknown, key: string): unknown {
9 if (receiver === null || receiver === void 0) return void 0;
10 if (typeof receiver !== 'object' && typeof receiver !== 'function') return void 0;
11 return (receiver as Record<string, unknown>)[key];
14const sample: EvalSample = {
15 cacheStatus: 'MISS',
16 revision: '"abc"',
17 evalMs: 0,
18 resolveMs: 8,
19 r2ReadMs: 4,
20 unitId: 'unit-DO-NOT-LEAK',
21 resolutions: [{ key: 'ply.usage.note', variantKind: 'boolean', variantValue: 'false', reason: 'default', bucket: 2849 }],
22};
24describe('telemetry', () => {
25 it('puts the unit id on the eval span only', () => {
26 const spans: { name: string; attrs: Record<string, string | number | boolean> }[] = [];
27 const lines: string[] = [];
28 const tracing = {
29 enterSpan(name: string): SpanLike {
30 const attrs: Record<string, string | number | boolean> = {};
31 return {
32 setAttribute: (key, value) => { attrs[key] = value; },
33 end: () => { spans.push({ name, attrs }); },
34 };
35 },
36 };
37 emitEval(tracing, sample, line => lines.push(line), none());
38 const parent = spans.find(span => span.name === 'flags.eval');
39 const child = spans.find(span => span.name === 'flags.resolve');
40 expect(slot(slot(parent, 'attrs'), 'flags.unit_id')).toBe('unit-DO-NOT-LEAK');
41 expect(slot(slot(parent, 'attrs'), 'flags.cache_status')).toBe('MISS');
42 expect(slot(slot(parent, 'attrs'), 'flags.resolve_ms')).toBe(8);
43 expect(slot(slot(parent, 'attrs'), 'flags.eval_ms')).toBe(0);
44 expect(slot(slot(parent, 'attrs'), 'flags.r2_read_ms')).toBe(4);
45 expect(slot(slot(child, 'attrs'), 'flags.unit_id')).toBeUndefined();
46 expect(slot(slot(child, 'attrs'), 'flags.reason')).toBe('default');
47 for (const line of lines) expect(line).not.toContain('unit-DO-NOT-LEAK');
48 expect(JSON.parse(evalLog(sample)).msg).toBe('flags.eval');
49 expect(JSON.parse(evalLog(sample)).resolve_ms).toBe(8);
50 expect(JSON.parse(evalLog(sample)).eval_ms).toBe(0);
51 expect(JSON.parse(resolveLog(sample, sample.resolutions[0]!)).bucket).toBe(2849);
52 });
54 it('reports p50/p95/p99 per cache status and variants per flag and revision', () => {
55 const events = [
56 { msg: 'flags.eval', cache_status: 'HIT', eval_ms: 1, revision: '"a"' },
57 { msg: 'flags.eval', cache_status: 'HIT', eval_ms: 2, revision: '"a"' },
58 { msg: 'flags.eval', cache_status: 'HIT', eval_ms: 3, revision: '"a"' },
59 { msg: 'flags.eval', cache_status: 'HIT', eval_ms: 4, revision: '"a"' },
60 { msg: 'flags.eval', cache_status: 'HIT', eval_ms: 10, revision: '"a"' },
61 { msg: 'flags.eval', cache_status: 'MISS', eval_ms: 10, revision: '"a"', r2_read_ms: 8 },
62 { source: { msg: 'flags.resolve', key: 'ply.usage.note', revision: '"a"', variant_kind: 'boolean', variant_value: 'true', reason: 'bucket', unit_id: 'one' } },
63 { source: { msg: 'flags.resolve', key: 'ply.usage.note', revision: '"a"', variant_kind: 'boolean', variant_value: 'true', reason: 'bucket', unit_id: 'two' } },
64 { source: { msg: 'flags.resolve', key: 'ply.usage.note', revision: '"b"', variant_kind: 'boolean', variant_value: 'false', reason: 'default' } },
65 { msg: 'flags.resolve', key: 'ply.usage.note', revision: '"a"', variant_kind: 'boolean', variant_value: 'true', reason: 'bucket', resolve_ms: 999, cache_status: 'HIT' },
66 ];
67 const report = reportFromEvents(events);
68 const hit = report.cache.find(row => row.cacheStatus === 'HIT');
69 expect(hit).toMatchObject({ n: 5, p50: 3, p95: 4, p99: 4 });
70 expect(slot(report.cache.find(row => row.cacheStatus === 'MISS'), 'p50')).toBe(10);
71 expect(report.variants).toEqual([
72 { key: 'ply.usage.note', revision: '"a"', variantKind: 'boolean', variantValue: 'true', reason: 'bucket', count: 3 },
73 { key: 'ply.usage.note', revision: '"b"', variantKind: 'boolean', variantValue: 'false', reason: 'default', count: 1 },
74 ]);
75 expect(renderReport(report)).toContain('ply.usage.note');
76 expect(renderReport(report)).not.toContain('unit_id');
77 const query = JSON.stringify(flagLogQuery('ply', 'flags.resolve', 0, 1, null));
78 expect(query).not.toContain('unit');
79 expect(query).toContain('flags.resolve');
80 });
82 it('uses resolve_ms, then a positive eval_ms, then wall time, and skips zeros', () => {
83 const preferred = reportFromEvents([
84 { msg: 'flags.eval', cache_status: 'MISS', resolve_ms: 7, eval_ms: 1, wallTimeMs: 100 },
85 ]);
86 expect(preferred.cache.find(row => row.cacheStatus === 'MISS')).toMatchObject({ n: 1, p50: 7 });
87 const legacy = reportFromEvents([
88 { msg: 'flags.eval', cache_status: 'HIT', eval_ms: 4 },
89 ]);
90 expect(slot(legacy.cache.find(row => row.cacheStatus === 'HIT'), 'p50')).toBe(4);
91 const wall = reportFromEvents([
92 { msg: 'flags.eval', cache_status: 'STALE', resolve_ms: 0, eval_ms: 0, $workers: { wallTimeMs: 30 } },
93 ]);
94 expect(slot(wall.cache.find(row => row.cacheStatus === 'STALE'), 'p50')).toBe(30);
95 const span = reportFromEvents([
96 { name: 'flags.eval', cache_status: 'UPDATING', resolve_ms: 0, eval_ms: 0, durationMs: 11 },
97 ]);
98 expect(slot(span.cache.find(row => row.cacheStatus === 'UPDATING'), 'p50')).toBe(11);
99 const frozen = reportFromEvents([
100 { msg: 'flags.eval', cache_status: 'HIT', resolve_ms: 0, eval_ms: 0, durationMs: 0 },
101 ]);
102 expect(frozen.cache).toEqual([]);
103 expect(MEASUREMENT).toContain('resolve_ms');
104 expect(MEASUREMENT).toContain('FlagsCache');
105 });
106});
108describe('propagation', () => {
109 it('sees the new revision after invalidate and keeps the old one without it', async () => {
110 let clock = 0;
111 const measured = await measureRounds(3, () => clock++);
112 expect(measured.staleWithoutInvalidate).toBe(true);
113 expect(measured.rounds).toHaveLength(3);
114 for (const round of measured.rounds) expect(round.to).not.toBe(round.from);
115 expect(measured.p50).not.toBeNull();
116 });
117});
Diagnostics4 git calls · 30 ms
CallStatusSizeTime030 ms
discover200152 B4 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=4
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 · hit4 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=4
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=4
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 · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=41349
git.response.cache=HIT
git.response.duration_ms=4
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
fetch2001.8 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=1850
git.response.cache=HIT
git.response.duration_ms=22
git.fetch.wants=03387e135537908bd61053863bc38b1a81db1725
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=1850
git.pkt.payload.max=1829
git.sideband.band1.bytes=1828
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
a5e2ea359ab34bc2
Request
980f698a…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format