From 2d1f665d7b4a1a2138de626fb7417633eeba2aec Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Fri, 27 Nov 2026 00:42:00 +0530 Subject: [PATCH 1/2] Adoption retries failed warehouse refreshes Allow the warehouse time to resume from idle and keep fallback responses out of the cache. Signed-off-by: Lareb Zafar --- deploy/telemetry/README.md | 13 +++++----- docs/lib/adoption-data.mjs | 17 +++++++++++-- docs/lib/adoption-data.test.mjs | 44 ++++++++++++++++++++++++++++++++- docs/pages/adoption.astro | 16 +++++++----- 4 files changed, 75 insertions(+), 15 deletions(-) diff --git a/deploy/telemetry/README.md b/deploy/telemetry/README.md index 81b4011486..ba2c85c5d9 100644 --- a/deploy/telemetry/README.md +++ b/deploy/telemetry/README.md @@ -65,12 +65,13 @@ Authorize a dedicated API key for the endpoint and set `/run/` URL from the endpoint configuration. Redeploy the site after saving the variables. -Vercel caches the aggregate page for an hour. The site fetches repository and release counts -from GitHub, SDK downloads from PyPI Stats and npm, and container pulls from -the public package page. Stored registry metrics fill gaps when the public -sources are unavailable. The page shows the latest observation date for each -metric and compares reporting periods when both periods have coverage on -every date. +The site caches pages with warehouse data for an hour. + +The site fetches repository and release counts from GitHub, SDK downloads from +PyPI Stats and npm, and container pulls from the public package page. Stored +registry metrics fill gaps when the public sources are unavailable. The page +shows the latest observation date for each metric and compares reporting +periods when both periods have coverage on every date. The public page supports 30-, 90-, and 365-day windows. Its chart links preserve the selected filters. CSV links export aggregate activity, lifecycle, download, diff --git a/docs/lib/adoption-data.mjs b/docs/lib/adoption-data.mjs index 0bcdb7280c..fbee4990b9 100644 --- a/docs/lib/adoption-data.mjs +++ b/docs/lib/adoption-data.mjs @@ -9,7 +9,7 @@ async function readSource(url, options, decode = (response) => response.json()) const response = await fetch(url, { ...options, redirect: "error", - signal: AbortSignal.timeout(5000), + signal: options?.signal ?? AbortSignal.timeout(5_000), }); if (response.ok) return await decode(response); } catch { @@ -36,6 +36,8 @@ async function loadWarehouse(env) { url.searchParams.set("format", "JSON"); const response = await readSource(url, { headers: { Authorization: `Basic ${Buffer.from(`${keyId}:${keySecret}`).toString("base64")}` }, + // An idle warehouse needs time to resume before it runs the query. + signal: AbortSignal.timeout(30_000), }); const row = response?.data?.[0]; if (datasets.every((name) => Array.isArray(row?.[name]))) { @@ -168,7 +170,18 @@ let published; export function loadPublishedAdoption() { const now = Date.now(); if (!published || now >= published.expires) { - published = { expires: now + 5 * 60_000, data: loadAdoption(process.env, new Date(now)) }; + const refresh = { expires: now + 5 * 60_000 }; + refresh.data = loadAdoption(process.env, new Date(now)).then( + (data) => { + if (data.selfHosted.totals === undefined) refresh.expires = 0; + return data; + }, + (error) => { + refresh.expires = 0; + throw error; + }, + ); + published = refresh; } return published.data; } diff --git a/docs/lib/adoption-data.test.mjs b/docs/lib/adoption-data.test.mjs index b4597fd673..460b85d74c 100644 --- a/docs/lib/adoption-data.test.mjs +++ b/docs/lib/adoption-data.test.mjs @@ -1,7 +1,7 @@ import assert from "node:assert/strict"; import { test } from "node:test"; -import { loadAdoption } from "./adoption-data.mjs"; +import { loadAdoption, loadPublishedAdoption } from "./adoption-data.mjs"; import { summarizeOss } from "./adoption-view.mjs"; test("calls the saved aggregate endpoint and reports monthly coverage and missing data", async (t) => { @@ -97,3 +97,45 @@ test("keeps Query API credentials off unrecognized endpoint URLs", async (t) => assert.ok(requests.every(([host, authorization]) => host !== "external.example" && authorization === undefined)); assert.equal(result.selfHosted.totals, undefined); }); + +test("retries a timed-out warehouse and caches the next successful refresh", async (t) => { + const originalEnv = process.env; + t.after(() => { + process.env = originalEnv; + }); + process.env = { + ...originalEnv, + LOOM_ADOPTION_QUERY_ENDPOINT_URL: "https://queries.clickhouse.cloud/run/00000000-0000-0000-0000-000000000001", + LOOM_ADOPTION_QUERY_KEY_ID: "fixture-id", + LOOM_ADOPTION_QUERY_KEY_SECRET: "fixture-secret", + }; + t.mock.method(console, "warn", () => {}); + const timeoutBySignal = new Map(); + t.mock.method(AbortSignal, "timeout", (delay) => { + const { signal } = new AbortController(); + timeoutBySignal.set(signal, delay); + return signal; + }); + const publicTimeouts = new Set(); + const warehouseTimeouts = []; + t.mock.method(globalThis, "fetch", async (input, init) => { + if (new URL(input).hostname !== "queries.clickhouse.cloud") { + publicTimeouts.add(timeoutBySignal.get(init.signal)); + return new Response(null, { status: 502 }); + } + warehouseTimeouts.push(timeoutBySignal.get(init.signal)); + if (warehouseTimeouts.length === 1) throw new DOMException("Warehouse wake-up timed out", "TimeoutError"); + return Response.json({ data: [{ totals: [], versions: [], retention: [], activity: [], lifecycle: [], oss: [] }] }); + }); + + const first = loadPublishedAdoption(); + assert.equal(loadPublishedAdoption(), first); + assert.equal((await first).selfHosted.totals, undefined); + + const retry = loadPublishedAdoption(); + assert.notEqual(retry, first); + assert.deepEqual((await retry).selfHosted.totals, []); + assert.equal(loadPublishedAdoption(), retry); + assert.deepEqual(warehouseTimeouts, [30_000, 30_000]); + assert.deepEqual([...publicTimeouts], [5_000]); +}); diff --git a/docs/pages/adoption.astro b/docs/pages/adoption.astro index 940a4a0296..edfcdbec25 100644 --- a/docs/pages/adoption.astro +++ b/docs/pages/adoption.astro @@ -20,12 +20,16 @@ import { export const prerender = false; -Astro.response.headers.set("Cache-Control", "public, max-age=0, must-revalidate"); -Astro.response.headers.set("Vercel-CDN-Cache-Control", "public, s-maxage=3600, stale-while-revalidate=86400"); - const filters = adoptionFilters(Astro.url.searchParams); const { today, refreshedAt, selfHosted, openSource } = await loadPublishedAdoption(); const { totals: summaries, retention, versions, activity, lifecycle } = selfHosted; +const warehouseAvailable = Array.isArray(summaries); +if (warehouseAvailable) { + Astro.response.headers.set("Cache-Control", "public, max-age=0, must-revalidate"); + Astro.response.headers.set("Vercel-CDN-Cache-Control", "public, s-maxage=3600, stale-while-revalidate=86400"); +} else { + Astro.response.headers.set("Cache-Control", "no-store"); +} const totals = summaries?.find(({ range_days, comparison }) => range_days === filters.days && comparison === "current"); const previous = summaries?.find( ({ range_days, comparison }) => range_days === filters.days && comparison === "previous", @@ -71,7 +75,7 @@ if (dataset) { headers: { "Content-Type": "text/csv; charset=utf-8", "Content-Disposition": `attachment; filename="loom-${dataset}.csv"`, - "Cache-Control": "public, max-age=300", + "Cache-Control": warehouseAvailable ? "public, max-age=300" : "no-store", }, }); } @@ -196,8 +200,8 @@ const overview = [ ; })} - {!Array.isArray(summaries) &&

Self-hosted metrics will appear when the telemetry warehouse is connected.

} - {Array.isArray(summaries) && !totals &&

No installations reported in this period.

} + {!warehouseAvailable &&

Self-hosted metrics will appear when the telemetry warehouse is connected.

} + {warehouseAvailable && !totals &&

No installations reported in this period.

} {totals &&

Latest reporting date UTC. Period changes appear when both windows have a report on every date.

}
From 4a50c04a755b4680036408ba1e3dc4966b484258 Mon Sep 17 00:00:00 2001 From: Lareb Zafar Date: Fri, 27 Nov 2026 00:45:31 +0530 Subject: [PATCH 2/2] Adoption pauses between failed warehouse refreshes Share a failed refresh briefly so an outage cannot repeatedly exhaust registry quotas. Signed-off-by: Lareb Zafar --- docs/lib/adoption-data.mjs | 5 +++-- docs/lib/adoption-data.test.mjs | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/lib/adoption-data.mjs b/docs/lib/adoption-data.mjs index fbee4990b9..dbdc20441d 100644 --- a/docs/lib/adoption-data.mjs +++ b/docs/lib/adoption-data.mjs @@ -166,6 +166,7 @@ export async function loadAdoption(env = process.env, now = new Date()) { }; } +const failedRefreshTtlMs = 15_000; let published; export function loadPublishedAdoption() { const now = Date.now(); @@ -173,11 +174,11 @@ export function loadPublishedAdoption() { const refresh = { expires: now + 5 * 60_000 }; refresh.data = loadAdoption(process.env, new Date(now)).then( (data) => { - if (data.selfHosted.totals === undefined) refresh.expires = 0; + if (data.selfHosted.totals === undefined) refresh.expires = Date.now() + failedRefreshTtlMs; return data; }, (error) => { - refresh.expires = 0; + refresh.expires = Date.now() + failedRefreshTtlMs; throw error; }, ); diff --git a/docs/lib/adoption-data.test.mjs b/docs/lib/adoption-data.test.mjs index 460b85d74c..6a1ae21436 100644 --- a/docs/lib/adoption-data.test.mjs +++ b/docs/lib/adoption-data.test.mjs @@ -99,6 +99,8 @@ test("keeps Query API credentials off unrecognized endpoint URLs", async (t) => }); test("retries a timed-out warehouse and caches the next successful refresh", async (t) => { + let now = Date.UTC(2026, 10, 27); + t.mock.method(Date, "now", () => now); const originalEnv = process.env; t.after(() => { process.env = originalEnv; @@ -130,8 +132,14 @@ test("retries a timed-out warehouse and caches the next successful refresh", asy const first = loadPublishedAdoption(); assert.equal(loadPublishedAdoption(), first); + now += 30_000; assert.equal((await first).selfHosted.totals, undefined); + now += 14_999; + assert.equal(loadPublishedAdoption(), first); + assert.equal(warehouseTimeouts.length, 1); + + now += 1; const retry = loadPublishedAdoption(); assert.notEqual(retry, first); assert.deepEqual((await retry).selfHosted.totals, []);