main
ply4 git calls30 ms44 KiB3 cachedprotocol v2
92 lines4.2 KiBRaw
1// The thin adapter: span events of one Worker over a window, through the CD's own query path (scripts/cd/o11y.ts:
2// `cf o11y telemetry query`, paged, retried per the rollout policy's telemetry.query bound). cf reads the account and
3// token the CD uses (CLOUDFLARE_API_TOKEN / CLOUDFLARE_ACCOUNT_ID, or a `cf` login). Long windows are cut into slices so
4// each stays under the CD's page ceiling (TELEMETRY_MAX_PAGES x TELEMETRY_PAGE events).
5import { queryAll, type QueryRetry } from '../cd/o11y.ts'
6import { API_ROUTES } from '../../src/api-routes.ts'
7import { serviceFilter, spanTypeFilter, telemetryQuery, type Filter } from '../cd/telemetry.ts'
9export type SpanQuery = {
10 readonly worker: string
11 readonly from: number
12 readonly to: number
13 /** Slice length. Each slice is one paged query. */
14 readonly sliceMs: number
15 /**
16 * Keep only these `ply.route` values. Null means the default allowlist
17 * (`DEFAULT_CALIBRATE_ROUTES`) unless `includeNoisy` is true.
18 */
19 readonly routes: readonly string[] | null
20 /** When true and `routes` is null, do not allowlist: return every span of the Worker. */
21 readonly includeNoisy: boolean
24export type Slice = { readonly from: number; readonly to: number }
26/** [from, to) cut into consecutive slices of at most `sliceMs`. */
27export function slices(from: number, to: number, sliceMs: number): Slice[] {
28 if (!(sliceMs > 0)) throw new Error('slice must be positive')
29 if (!(to > from)) throw new Error('window must end after it starts')
30 const out: Slice[] = []
31 for (let at = from; at < to; at += sliceMs) out.push({ from: at, to: Math.min(to, at + sliceMs) })
32 return out
35/**
36 * Routes that dominate Workers Observability under the million-client rate/viewer load (issue #73 loop
37 * 2026-11-08): ~18M viewer + ~4.8M rate.* spans / 24h vs tens of thousands of /v1 spans. Child spans of
38 * those routes often omit `ply.route`, so a `neq` exclude still pages them and overflows TELEMETRY_MAX_PAGES
39 * even on a one-hour slice. Default queries therefore allowlist the calibration routes (every /v1 git
40 * route plus `GET /`); pass `includeNoisy: true` (or `--include-noisy`) for an unfiltered span query, and
41 * shrink `--slice` when you do.
42 */
43export const NOISY_ROUTES = ['viewer', 'rate.check', 'rate.flush', 'rate.refresh'] as const
45/** Default allowlist: every /v1 git route plus the unauthenticated root probe. */
46export const DEFAULT_CALIBRATE_ROUTES: readonly string[] = [...API_ROUTES, 'GET /']
48export type SpanFilterOpts = {
49 /** Keep only these `ply.route` values (`in`/`eq`). Null keeps DEFAULT_CALIBRATE_ROUTES unless includeNoisy. */
50 readonly routes: readonly string[] | null
51 /** When true and `routes` is null, do not allowlist: return every span of the Worker. */
52 readonly includeNoisy: boolean
55const DEFAULT_SPAN_FILTER_OPTS: SpanFilterOpts = { routes: null, includeNoisy: false }
57/** The filters every calibration query uses: this Worker's span events (ply's spans and the runtime's request spans). */
58export function spanFilters(worker: string, opts: SpanFilterOpts = DEFAULT_SPAN_FILTER_OPTS): Filter[] {
59 const filters: Filter[] = [serviceFilter(worker), spanTypeFilter()]
60 const routes = opts.routes
61 if (routes !== null && routes.length > 0) {
62 filters.push({
63 key: 'ply.route',
64 operation: routes.length === 1 ? 'eq' : 'in',
65 type: 'string',
66 value: routes.join(','),
67 })
68 return filters
69 }
70 if (opts.includeNoisy) return filters
71 filters.push({
72 key: 'ply.route',
73 operation: 'in',
74 type: 'string',
75 value: DEFAULT_CALIBRATE_ROUTES.join(','),
76 })
77 return filters
80/** The query body of the first slice: what a citation names as its `query`. */
81export function citedQuery(query: SpanQuery): ReturnType<typeof telemetryQuery> {
82 return telemetryQuery('events', query.from, query.to, spanFilters(query.worker, query), null)
85export async function querySpanEvents(query: SpanQuery, retry: QueryRetry, secrets: readonly string[] = []): Promise<unknown[]> {
86 const out: unknown[] = []
87 const filters = spanFilters(query.worker, query)
88 for (const slice of slices(query.from, query.to, query.sliceMs)) {
89 out.push(...await queryAll('events', slice.from, slice.to, filters, retry, secrets))
90 }
91 return out
Diagnostics4 git calls · 30 ms
CallStatusSizeTime030 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 · 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 1020042 KiB · hit5 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=5
git.response.bytes=42585
git.response.cache=HIT
git.response.duration_ms=5
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=262b639aa1b258fc1777c3a66ba8f811df3a3da2
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=42585
git.pkt.payload.max=42490
git.sideband.band1.bytes=42489
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=61
git.pack.bytes=42489
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=7dbf576d97429022615f79aa46b440d9da603496
git.pack.full=61
Open pack map
fetch2001.8 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=1811
git.response.cache=HIT
git.response.duration_ms=21
git.fetch.wants=75eecbab85ded2a9bd306d0a0992919f421ef733
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=1811
git.pkt.payload.max=1790
git.sideband.band1.bytes=1789
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
262b639aa1b258fc1777c3a66ba8f811df3a3da2
cf-ray
a5e1c660286ac6f8
Request
f1e2d1dd…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format