Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
2.1 kB ยท 73 lines
TypeScript
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374import type { Region } from "@openstatus/db/src/schema/constants";
import type { Timing } from "@/lib/checker/utils";import { wait } from "@/lib/utils";
import { PROBE_TIMEOUT_MS, mapCheckToCdnResult } from "./probe";import type { CdnRegionResponse } from "./schema";
function makeTiming(ttfb: number, total: number): Timing { return { dnsStart: 0, dnsDone: 0, connectStart: 0, connectDone: 0, tlsHandshakeStart: 0, tlsHandshakeDone: 0, firstByteStart: 0, firstByteDone: ttfb, transferStart: ttfb, transferDone: total, };}
// dev runs without CRON_SECRET so the checker fleet is unreachable: probe the// URL directly from the local machine instead. Headers and cache status are// real; the vantage point is not โ every "region" sees the same nearest edge.export async function devProbeCdnRegion({ url, region,}: { url: string; region: Region;}): Promise<CdnRegionResponse> { // jitter so rows stream progressively like the real fan-out await wait(50 + Math.random() * 800);
try { const start = performance.now(); const response = await fetch(url, { method: "GET", redirect: "follow", cache: "no-store", signal: AbortSignal.timeout(PROBE_TIMEOUT_MS), }); const ttfb = Math.round(performance.now() - start); const body = await response.arrayBuffer(); const total = Math.round(performance.now() - start);
const headers: Record<string, string> = {}; response.headers.forEach((value, key) => { headers[key] = value; }); // fetch strips content-length on decompressed responses headers["content-length"] ??= String(body.byteLength);
return mapCheckToCdnResult({ type: "http", state: "success", region, status: response.status, latency: total, timestamp: Date.now(), timing: makeTiming(ttfb, total), headers, }); } catch (error) { return { state: "error", region, message: error instanceof Error ? error.message : "Request failed", }; }}