From d90dfca1d09af89c334f73dcd2d66c5e50d198bc Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 20:50:38 +0000 Subject: [PATCH] UF3: ready to instantiate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The README says what is here and how to run it: configuring the monitors (uptime.config.ts, every check kind, what reaches the browser), getting started, watching a check run under `wrangler dev --test-scheduled`, a private status page through the STATUS_PAGE_PASSWORD secret, how it maps to UptimeFlare's own Pages-plus-Worker deployment, how the database reaches the Worker, and CI. IMPLEMENTATION-STATUS records every PR and every departure from upstream — thirteen, each with its reason — and what was verified offline and what only a live bootstrap can prove. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_019PcpNVpFBcbeiX3EHdXfmn --- README.md | 166 +++++++++++++++++- .../uptimeflare/IMPLEMENTATION-STATUS.md | 48 ++++- specs/epics/uptimeflare/README.md | 2 +- 3 files changed, 204 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 448dce5..a573e69 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,161 @@ # uptimeflare -[UptimeFlare](https://github.com/lyc8503/UptimeFlare) — lyc8503's uptime -monitor and status page — on **one Cloudflare Worker**: the status page built -by [`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare), its checks -on a **Cron Trigger** of the same Worker, their state in a **Cloudflare D1** -database provisioned by Terraform through [Orun](https://github.com/sourceplane/orun), -and packaged, once it is built, as an **Orun baseline**. +lyc8503's [UptimeFlare](https://github.com/lyc8503/UptimeFlare) — an uptime +monitor and status page: HTTP, HTTPS and TCP checks every minute, 90 days of +uptime bars, twelve hours of latency charts, incident history, scheduled +maintenances, webhook notifications and a JSON API — running as **one +Cloudflare Worker**: the status page built by +[`@opennextjs/cloudflare`](https://opennext.js.org/cloudflare) into Workers + +Static Assets, and the checks on a **Cron Trigger** of the same Worker, their +state in a **Cloudflare D1** database provisioned by Terraform through +[Orun](https://github.com/sourceplane/orun) and its schema applied by +migrations. -Being built in reviewed steps; the plan and its status are in -[`specs/epics/uptimeflare`](specs/epics/uptimeflare/README.md). +Upstream already runs on Cloudflare, as two deployables — a Pages project +built by `@cloudflare/next-on-pages` for the page and a second Worker for the +checks, sharing one D1 database. Here they are one Worker: its custom entry +(`apps/web/worker.ts`) re-exports OpenNext's `fetch` and adds `scheduled`, +which runs upstream's checker loop unchanged. The Durable Object remote +checker (geo-specific checks) is left out. See +[`specs/epics/uptimeflare`](specs/epics/uptimeflare/README.md) for the +design, the milestones and the as-built status. -UptimeFlare is © lyc8503 and contributors, under the Apache License 2.0. +## What is here + +| Surface | Where | +|---|---| +| The status page, the incidents page, their components and translations | `apps/web/pages`, `apps/web/components`, `apps/web/locales` | +| The monitors, links, maintenances and notifications | `apps/web/uptime.config.ts` (every option: `uptime.config.full.ts`) | +| The page's name and source link | `apps/web/lib/site.ts` | +| The checker: HTTP(S) and TCP checks, incidents, notifications, the compacted state | `apps/web/monitor/` (upstream's `worker/src`) | +| The Worker entry: OpenNext's `fetch` + the checker's `scheduled` | `apps/web/worker.ts` | +| The JSON API and the status badge | `apps/web/pages/api/data.ts`, `apps/web/pages/api/badge.ts` | +| The password gate (optional) | `apps/web/proxy.ts` | +| Workers build, trigger, bindings and deploy contract | `apps/web/next.config.mjs`, `open-next.config.ts`, `wrangler.template.jsonc` + `wiring.fixture.json` (→ the committed `wrangler.jsonc`), `component.yaml` | +| The D1 database (stage, prod) | `infra/terraform/cloudflare-d1` | +| The schema (migrations) and the runner that applies them over the D1 REST API | `packages/db`, run by `infra/db-migrate` | +| The wrangler renderer, the Worker-secrets helper, the migration helpers | `tooling/wire`, `tooling/migrations` | +| Tests | `tests/web` (the state, the checker against SQLite, the API, the gate), `tests/db` (the migrations into real SQLite) | + +## Configuring the monitors + +Everything a status page shows is in `apps/web/uptime.config.ts`, as upstream +has it: `pageConfig` (title, header links, groups, logo, footer), +`workerConfig` (the monitors, the write cooldown, notifications, callbacks) +and `maintenances`. It ships with three public monitors — Cloudflare and +GitHub over HTTPS, Google Public DNS over TCP — so a new page has something +to check; replace them with your own. Each monitor's `id` keys its history: +keep it and the history stays, change it and the monitor starts over. + +| Monitor kind | `method` | `target` | +|---|---|---| +| HTTP(S), with optional `expectedCodes`, `headers`, `body`, `responseKeyword`, `responseForbiddenKeyword`, `timeout` | `GET`, `HEAD`, `POST`, … | a URL | +| TCP connect | `TCP_PING` | `host:port` | + +A check through a proxy (`checkProxy`) works for `globalping://` and +`http(s)://` proxies; `worker://`, upstream's Durable Object, is not +part of this port — such a monitor reports why it is down, or is checked from +the Worker itself with `checkProxyFallback: true`. + +Only `id`, `name`, `tooltip`, `statusPageLink` and `hideLatencyChart` reach +the browser (the CVE-2026-29779 fix, kept); a test holds that list. A webhook +whose URL embeds a token is still a credential in this file, as upstream +designs it — keep the repository private, or send notifications from a +`callbacks` function, which receives the Worker's `env`. + +## Getting started + +```bash +pnpm install +pnpm run wire:fixture # render apps/web/wrangler.jsonc from the offline fixture +pnpm typecheck +pnpm lint +pnpm test +pnpm build # next build + opennextjs-cloudflare build → apps/web/.open-next +``` + +```bash +pnpm --filter @app/web db:migrate:local # create the monitor_state table in wrangler's local D1 +pnpm --filter @app/web dev # http://localhost:3000 — the pages, against that D1 (no scheduler) +pnpm --filter @app/web preview # wrangler dev over the built Worker, same local D1 +``` + +## Watching a check run + +`wrangler dev` never runs the clock; `--test-scheduled` adds a +`/__scheduled` endpoint that fires the handler: + +```bash +cd apps/web +pnpm exec wrangler dev --port 8808 --config wrangler.jsonc --test-scheduled + +curl http://127.0.0.1:8808/api/data # {"error":"No data available"} — nothing checked yet +curl "http://127.0.0.1:8808/__scheduled?cron=*+*+*+*+*" # runs the checker once +curl http://127.0.0.1:8808/api/data # {"up":…,"down":…,"updatedAt":…,"monitors":{…}} +``` + +Deployed, the trigger fires every minute; the state is written when a status +changes and otherwise every three minutes (`kvWriteCooldownMinutes`). +Workers → the Worker → Triggers shows the one Cron Trigger; its logs show +each check. + +## A private status page + +Store `user:password` as the product's Orun secret `STATUS_PAGE_PASSWORD` +for an environment and redeploy it: the build hands it to the Worker as a +secret (`tooling/wire/worker-secrets.mjs`, the value over stdin, never in a +bundle), and `apps/web/proxy.ts` asks every request for those credentials, +the API's included. Locally, put the same line in `apps/web/.dev.vars` +(`.dev.vars.example`). Removing the Orun secret does not remove the Worker's +copy: delete it with `wrangler secret delete STATUS_PAGE_PASSWORD --name +` too. + +## How it maps to UptimeFlare's own deployment + +| Upstream | Here | +|---|---| +| A Pages project built by `@cloudflare/next-on-pages` | The same pages on Workers + Static Assets, built by `@opennextjs/cloudflare` (Next 16, pages router); `runtime = 'edge'` gone — OpenNext runs the Node runtime, and the two API routes are Node API routes | +| A second Worker (`worker/`) with a Cron Trigger | The same Worker: `worker.ts` adds `scheduled`, which runs the checker (`monitor/`), on one every-minute trigger | +| `env.UPTIMEFLARE_D1`, read through `process.env` on Pages | `env.DB`, read through `getCloudflareContext()` | +| The `uptimeflare(key, value)` table, created by `deploy/init_d1.py` | `monitor_state(key, value)`, created by the migration `010_monitor_state` before the Worker deploys | +| `deploy.tf`: the database, the Worker, its trigger, the Pages project | `infra/terraform/cloudflare-d1` for the database; the Worker, its trigger and its assets in one `wrangler deploy` | +| The `RemoteChecker` Durable Object (`worker://` geo checks) | Left out (no Orun composition places a Durable Object); `globalping://` and `http(s)://` proxies unchanged | +| `workerConfig.passwordProtection`, a string in the committed config | The optional Orun secret `STATUS_PAGE_PASSWORD`, a Worker secret | +| The page title in `uptime.config.ts` | `SITE_NAME` in `lib/site.ts`, which `pageConfig.title` reads; the server-rendered page carries the title too | +| GitHub Actions: build, init D1, Terraform apply | Orun: one convergence per merge applies the database, migrates it and deploys `-web-{stage,prod}`, smoke-tested on a check the trigger recorded | + +## How the database reaches the Worker + +``` +infra/terraform/cloudflare-d1 ──apply──► orun secret WIRING_CLOUDFLARE_D1 (stage, prod) + ▼ +infra/db-migrate dependsOn cloudflare-d1 (enforced on main) · secretEnv WIRING_CLOUDFLARE_D1 + apply: packages/db's runner → POST …/d1/database//query, each pending migration once + ▼ +apps/web dependsOn cloudflare-d1 + db-migrate (enforced on main) · secretEnv WIRING_CLOUDFLARE_D1_ + build: tooling/wire/live.mjs → wrangler.jsonc with the environment's database id + (dev, verify-only, renders the fixture) → next build → opennextjs-cloudflare + deploy: worker.ts (fetch + scheduled) and its one trigger, * * * * * + smoke: /api/data carries an updatedAt the trigger's checks wrote, no older than ten minutes +``` + +`wrangler.jsonc` is committed as the fixture render of +`wrangler.template.jsonc`, because the deploy lane's `verify-app-structure` +step checks the config exists before it builds. + +## CI + +`ci.yml` is the Orun pipeline: `orun plan --changed`, then one job per lane. +A pull request runs the verify lanes (the packages type-checked, linted, +tested and built, both test suites, the D1 root planned, the Worker built and +dry-deployed per environment); a merge applies the D1 database, migrates it, +then deploys stage → prod. It plans nothing while `intent.yaml` names the +placeholder workspace `ws_CHANGE_ME`, as this repository does. A manual run +(Orunbase's Deploy button, or Run workflow on `main`) plans the environment +and components it names under the push-to-main trigger, so they deploy as a +merge deploys them. + +## Licence + +UptimeFlare is © lyc8503 and its contributors, under the Apache License 2.0 +(`apps/web/LICENSE`); the code here derived from it keeps that licence. diff --git a/specs/epics/uptimeflare/IMPLEMENTATION-STATUS.md b/specs/epics/uptimeflare/IMPLEMENTATION-STATUS.md index 0bf0ef6..74c7e55 100644 --- a/specs/epics/uptimeflare/IMPLEMENTATION-STATUS.md +++ b/specs/epics/uptimeflare/IMPLEMENTATION-STATUS.md @@ -6,6 +6,50 @@ As built, kept apart from the plan. |---|---|---| | UF0 — the spec | ✅ shipped | [#1](https://github.com/sourceplane/uptimeflare/pull/1) | | UF1 — the monitor on Workers | ✅ shipped | [#2](https://github.com/sourceplane/uptimeflare/pull/2) | -| UF2 — the D1 database and its schema | ✅ this pull request | UF2 | -| UF3 — ready to instantiate | planned | — | +| UF2 — the D1 database and its schema | ✅ shipped | [#3](https://github.com/sourceplane/uptimeflare/pull/3) | +| UF3 — ready to instantiate | ✅ this pull request | UF3 | | UF4 — a baseline | planned | — | + +## Upstream + +[lyc8503/UptimeFlare](https://github.com/lyc8503/UptimeFlare) at `8035521` +(2026-10-21), Apache-2.0 — after the CVE-2026-29779 fix (2026-03-04). The +licence ships as `apps/web/LICENSE`. + +## Departures from upstream, each deliberate + +| # | Upstream | Here | Why | +|---|---|---|---| +| 1 | Pages project (`@cloudflare/next-on-pages`) + a checker Worker | One Worker: OpenNext's `fetch` + `scheduled` (`worker.ts`) | One deployable, one binding, one trigger; next-on-pages is deprecated | +| 2 | Next 14, `runtime = 'edge'` pages and API routes | Next 16 pages router on OpenNext's Node runtime; Node API routes with the same headers and bodies | OpenNext runs no edge runtime | +| 3 | Bindings on `process.env` | `getCloudflareContext()` | OpenNext's way to the Worker's env | +| 4 | Binding `UPTIMEFLARE_D1`, table `uptimeflare` | Binding `DB`, table `monitor_state`, same columns | The lowercase slug is this repository's identity: the rename engine rewrites it in a product and refuses the upper-case env prefix | +| 5 | `init.sql` run by `deploy/init_d1.py` | Migration `010_monitor_state`, applied by db-migrate before each deploy | The schema ships with the product and applies itself | +| 6 | `RemoteChecker` Durable Object for `worker://` proxies | Left out; such a monitor reports "not available in this port", or checks locally under `checkProxyFallback` | No Orun composition places a Durable Object | +| 7 | `workerConfig.passwordProtection` in the committed config | The optional Orun secret `STATUS_PAGE_PASSWORD`, a Worker secret | Credentials are Orun secrets, never committed | +| 8 | `middleware.ts` | `proxy.ts` (Next 16's name), same gate | Next 16 renamed middleware | +| 9 | The page's `` set only in the browser | Also in the server-rendered page (`_app.tsx`) | A product's name is in its HTML; nothing else changes | +| 10 | Example monitors pointing at `example.com` and `1.2.3.4:22`, an active test maintenance | Cloudflare and GitHub over HTTPS, Google Public DNS over TCP; no maintenance | A new status page checks real, public things and shows no fake banner | +| 11 | `@mantine/ds` dependency, unused | Dropped | Nothing imports it | +| 12 | `NoSsr`'s children typed with React 18's `PromiseLikeOfReactNode` | `React.ReactNode` | React 19's types dropped that member | +| 13 | — | `next.config.mjs` traces react-textarea-autosize's edge-light build into the standalone output | OpenNext bundles under the `workerd` condition, which Next's tracing (under Node's conditions) does not follow | + +Everything else — the checker loop, the compacted state, the check kinds, +incidents, grace periods, notifications, callbacks, maintenances, the pages, +components, styles and translations, the badge and data APIs — is upstream's. + +## Verified + +- UF1: `pnpm install`, `wire:fixture` (no diff), `typecheck`, `lint`, `test`, + `build`; `wrangler dev --test-scheduled` — a fired trigger checked every + monitor and wrote the state, `/api/data` read it back, the component's own + smoke command passed (and, with a password set, refused a request without + it); no monitor config in the client bundle. +- UF2: `terraform validate`; the migrations into real SQLite; `db:migrate:local` + creates `monitor_state` in wrangler's local D1; a local `orun plan` for a + push to main orders `cloudflare-d1 → db-migrate → web` per environment. + +## Not verified offline + +The D1 apply, the migrations against a real database, the deploy, and the +first Cron Trigger firing on Cloudflare (risk UF-E) — a live bootstrap's. diff --git a/specs/epics/uptimeflare/README.md b/specs/epics/uptimeflare/README.md index 05d3a12..cad1f35 100644 --- a/specs/epics/uptimeflare/README.md +++ b/specs/epics/uptimeflare/README.md @@ -8,7 +8,7 @@ The port keeps the status page, the incident history, the latency charts, the ba | Field | Value | |-------|-------| -| Status | UF0–UF1 shipped (#1, #2); UF2 in review | +| Status | UF0–UF2 shipped (#1–#3); UF3 in review | | Cluster | **UF** (UF0–UF4) | | Owner(s) | `apps/web` (the status page, `worker.ts`, `monitor/`, `uptime.config.ts`) · `tests/web` · `infra/terraform/cloudflare-d1` · `packages/db` + `infra/db-migrate` · `tests/db` | | Builds on | `cron-starter` (one OpenNext Worker with a `scheduled` handler on its own Cron Trigger), `turso-starter` (the `cloudflare-d1` root, the D1 migration runner and `db-migrate`), `cirrus-baseline` (the `@@wiring(...)@@` deploy-time render) |