main
1// Shared helpers for the worker-mem harness: paths, the cf CLI (always without CLOUDFLARE_API_TOKEN), redaction.
2import { spawnSync } from 'node:child_process';
3import { mkdirSync, openSync, writeSync, closeSync, existsSync, readFileSync } from 'node:fs';
4import { randomBytes } from 'node:crypto';
5import { homedir } from 'node:os';
6import { dirname, join } from 'node:path';
7import { fileURLToPath } from 'node:url';
9export const HERE = dirname(fileURLToPath(import.meta.url));
10export const ROOT = join(HERE, '..', '..');
11export const DATA = join(HERE, '.data');
12export const REPORTS = join(HERE, 'reports');
13export const WORKER = 'ply-memlab';
14export const NAMESPACE = 'ply-loadgen';
15export const TOKEN_FILE = join(homedir(), '.config', 'ply', 'memlab-token');
17const ART = /art_v\d+_[^\s"'\\]+/g;
18const secrets = new Set();
19export const remember = s => { if (s) secrets.add(s); return s; };
20export function redact(text) {
21 let out = String(text).replace(ART, '[redacted]');
22 for (const s of secrets) out = out.split(s).join('[redacted]');
23 return out;
24}
26const cfEnv = () => {
27 const env = { ...process.env };
28 delete env.CLOUDFLARE_API_TOKEN;
29 return env;
30};
32// Runs cf; returns { code, stdout, stderr } with secrets redacted from stderr only (stdout may carry minted tokens).
33export function cfRaw(args, opts = {}) {
34 const r = spawnSync('cf', args, { encoding: opts.encoding ?? 'utf8', env: cfEnv(), cwd: opts.cwd ?? HERE, maxBuffer: 256 * 1024 * 1024, input: opts.input });
35 return { code: r.status ?? 1, stdout: r.stdout ?? '', stderr: redact(r.stderr ?? '') };
36}
38export function cfJson(args, opts = {}) {
39 const r = cfRaw(args, opts);
40 if (r.code !== 0) throw new Error(`cf ${args.slice(0, 4).join(' ')} failed: ${r.stderr.slice(0, 600)}`);
41 const at = r.stdout.search(/[[{]/);
42 return at < 0 ? null : JSON.parse(r.stdout.slice(at));
43}
45// Writes a secret to a 0600 file without ever echoing it.
46export function writeSecret(path, value) {
47 mkdirSync(dirname(path), { recursive: true });
48 const fd = openSync(path, 'w', 0o600);
49 writeSync(fd, value);
50 closeSync(fd);
51}
53// The bearer for the ply-memlab Worker, generated once.
54export function memlabToken() {
55 if (!existsSync(TOKEN_FILE)) writeSecret(TOKEN_FILE, randomBytes(32).toString('hex'));
56 return remember(readFileSync(TOKEN_FILE, 'utf8').trim());
57}
59export const sleep = ms => new Promise(r => setTimeout(r, ms));
60export const stamp = () => new Date().toISOString().replace(/[-:]/g, '').replace(/\..*/, 'Z');
62export function quantiles(xs) {
63 const v = xs.filter(x => typeof x === 'number' && Number.isFinite(x)).sort((a, b) => a - b);
64 if (v.length === 0) return null;
65 const at = p => v[Math.min(v.length - 1, Math.floor(p * v.length))];
66 return { n: v.length, min: v[0], p50: at(0.5), p90: at(0.9), max: v[v.length - 1] };
67}
Diagnostics4 git calls · 240 ms
CallStatusSizeTime0240 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch 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 · hit2 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=2 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 1020038 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=235 git.response.bytes=38434 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=19912563f540228593df0c489082e5e2508e21e4 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=38434 git.pkt.payload.max=38339 git.sideband.band1.bytes=38338 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=63 git.pack.bytes=38338 git.pack.ofs_delta=0 git.pack.ref_delta=8 git.pack.chain.max=8 git.pack.trailer=0bc36ab7adf82d3109177f11f1ea93f1ce071f77 git.pack.full=55Open pack map
fetch2001.4 KiB235 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1385 git.response.cache=MISS git.response.duration_ms=235 git.fetch.wants=bd62cc0a29068185f1714c0e4630380ca9fe61fa 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=1385 git.pkt.payload.max=1364 git.sideband.band1.bytes=1363 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.git
- Ref
- refs/heads/main
- Commit
- 19912563f540228593df0c489082e5e2508e21e4
- cf-ray
- a5e35593af68994c
- Request
- b088f748…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format