Skip to content

Commit 68d5e8b

Browse files
authored
Split header time from body-read time on the docs upstream (#1674)
fetch() resolves when headers arrive, so the earlier probe returned ~1ms without ever reading a body. Both genuinely slow operations read one: the docs proxy reads a 179KB page and the JWKS store calls hit.json(). Time headers and body separately on the exact upstream the docs proxy uses, gated to /robots.txt so normal traffic never pays for it.
1 parent fde4450 commit 68d5e8b

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

apps/cloud/src/server.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,31 @@ const cloudflareHandler: ExportedHandler<Env> = {
224224
}
225225
const fetchProbeMs = Date.now() - fetchStartedAt;
226226

227+
// `fetch()` above resolves when HEADERS arrive — it never reads a body,
228+
// which is why it returns in ~1ms while the request it lives in takes
229+
// seconds. Both genuinely slow operations read a body: the docs proxy
230+
// reads a 179KB page, and the JWKS store does `hit.json()`. Split header
231+
// time from body time on the exact URL the docs proxy uses.
232+
//
233+
// Gated to one cheap path so normal traffic never pays for the probe.
234+
let bodyHeadersMs = -1;
235+
let bodyReadMs = -1;
236+
let bodyBytes = -1;
237+
if (probeUrl.pathname === "/robots.txt") {
238+
// oxlint-disable-next-line executor/no-try-catch-or-throw -- temporary diagnostic: a probe failure must not affect the request
239+
try {
240+
const h0 = Date.now();
241+
const probeRes = await fetch("https://executor.mintlify.dev/docs/concepts/policies");
242+
bodyHeadersMs = Date.now() - h0;
243+
const b0 = Date.now();
244+
const text = await probeRes.text();
245+
bodyReadMs = Date.now() - b0;
246+
bodyBytes = text.length;
247+
} catch {
248+
// ignored — the timing is the signal
249+
}
250+
}
251+
227252
console.log(
228253
JSON.stringify({
229254
probe: "clock-sync",
@@ -232,6 +257,9 @@ const cloudflareHandler: ExportedHandler<Env> = {
232257
cacheProbeMs,
233258
timerProbeMs,
234259
fetchProbeMs,
260+
bodyHeadersMs,
261+
bodyReadMs,
262+
bodyBytes,
235263
}),
236264
);
237265

0 commit comments

Comments
 (0)