diff --git a/README.md b/README.md index d3827ed..bbdc36a 100644 --- a/README.md +++ b/README.md @@ -39,8 +39,9 @@ npx wrangler secret put DATADOG_SITE -c worker/wrangler.jsonc npm run worker:tail ``` -`GET /health` on the Worker returns whether each sink is configured and -emits structured lines through the Pegma adapters. +`GET /health` on the Worker uses `@pegma/health` (process + logging sink +booleans), returns the shared JSON shape, and emits `health.ok` through the +Pegma adapters with the checks registered today. ## The content rule diff --git a/package-lock.json b/package-lock.json index ad36675..b89f980 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "pegma.dev", "version": "0.1.0", "dependencies": { + "@pegma/health": "file:worker-vendor/pegma-health-0.1.0.tgz", "@pegma/logger-cloudflare": "^0.1.1", "@pegma/logger-datadog": "^0.1.1", "@pegma/logger-tee": "^0.1.1", @@ -1390,6 +1391,19 @@ "dev": true, "license": "MIT" }, + "node_modules/@pegma/health": { + "version": "0.1.0", + "resolved": "file:worker-vendor/pegma-health-0.1.0.tgz", + "integrity": "sha512-AKaBqt4iu65pnd0imMgg3DSfI3Xwnlr3SLTrVCJ6Vzhvi6XKWVowUwYRR74qx3adGAmIt7STWzdQnAlGWZ8LQA==", + "license": "MIT", + "dependencies": { + "@pegma/spine": "0.1.1", + "@pegma/storage-core": "0.3.0" + }, + "engines": { + "node": ">=22" + } + }, "node_modules/@pegma/logger-cloudflare": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@pegma/logger-cloudflare/-/logger-cloudflare-0.1.1.tgz", @@ -1435,6 +1449,15 @@ "node": ">=22" } }, + "node_modules/@pegma/storage-core": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@pegma/storage-core/-/storage-core-0.3.0.tgz", + "integrity": "sha512-XcSIAxjC1JV+Pt3dpSrLZELSejckO/COWLZ03BfYQv0Hem4QL/7XCq5gb5dxEymKVufQuIqGtuDPZi2UPfqnuQ==", + "license": "MIT", + "engines": { + "node": ">=22" + } + }, "node_modules/@poppinss/colors": { "version": "4.1.6", "resolved": "https://registry.npmjs.org/@poppinss/colors/-/colors-4.1.6.tgz", diff --git a/package.json b/package.json index 54f1ea5..76e4da6 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "worker:tail": "wrangler tail pegma-dev-api" }, "dependencies": { + "@pegma/health": "file:worker-vendor/pegma-health-0.1.0.tgz", "@pegma/logger-cloudflare": "^0.1.1", "@pegma/logger-datadog": "^0.1.1", "@pegma/logger-tee": "^0.1.1", diff --git a/src/data/components.ts b/src/data/components.ts index 2fe1f93..83e0031 100644 --- a/src/data/components.ts +++ b/src/data/components.ts @@ -249,4 +249,24 @@ export const components: readonly PegmaComponent[] = [ now: '0.1.1 on npm; trusted publishing configured. Host tee wiring next.', plan: 'docs/PROJECT_PLAN.md', }, + { + repo: 'health', + title: 'Health', + packages: ['@pegma/health'], + status: 'in development', + summary: + 'Composable health probes and HTTP responses for public liveness checks.', + owns: [ + 'Check contracts, aggregation, and HTTP status mapping', + 'Process, detail, and injected Store ping helpers', + 'Spine log events health.ok / health.degraded / health.failed', + ], + refuses: [ + 'Owning a storage adapter or inventing domain collections', + 'Autodiscovery of checks — hosts register them at the composition root', + 'Metrics, APM, or alert fan-out', + ], + now: 'Phase 1 implemented (0.1.0, public API unstable).', + plan: 'docs/PROJECT_PLAN.md', + }, ]; diff --git a/worker-vendor/README.md b/worker-vendor/README.md new file mode 100644 index 0000000..50bba9c --- /dev/null +++ b/worker-vendor/README.md @@ -0,0 +1,13 @@ +# Vendored Health package + +`pegma-health-0.1.0.tgz` is the exact npm-pack artifact from +`pegma-dev/health` commit `35a878b` (`@pegma/health` 0.1.0). + +Generated with: + +```text +npm ci +npm pack --workspace @pegma/health --pack-destination /worker-vendor +``` + +Remove this bridge when `@pegma/health` has a public npm release. diff --git a/worker-vendor/pegma-health-0.1.0.tgz b/worker-vendor/pegma-health-0.1.0.tgz new file mode 100644 index 0000000..37e8e29 Binary files /dev/null and b/worker-vendor/pegma-health-0.1.0.tgz differ diff --git a/worker/README.md b/worker/README.md index 9d7b394..2b32b4e 100644 --- a/worker/README.md +++ b/worker/README.md @@ -1,6 +1,7 @@ # pegma-dev-api Worker -Thin Cloudflare Worker that proves pegma.dev's Pegma logging composition: +Thin Cloudflare Worker that proves pegma.dev's Pegma logging composition and +hosts the public health endpoint via `@pegma/health`: ```ts createTeeLogger( @@ -39,5 +40,33 @@ token needs **Workers:Edit** in addition to **Pages:Edit**. ## Endpoints -- `GET /` or `GET /health` — JSON health; emits `request.received` and - `health.ok` through the teed Spine logger. +- `GET /` or `GET /health` — JSON from `@pegma/health` + (`createProcessCheck` + logging sink booleans). Emits `request.received` + and, with the checks registered today, `health.ok` through the teed Spine + logger (both checks are always `ok`; an absent Datadog key is detail only). + Package mapping for when a check reports otherwise: HTTP `200` for status + `ok`/`degraded`, `503` for status `fail` (log event `health.failed`). + No storage probe yet (D1 consumer still gated). + +Example body: + +```json +{ + "ok": true, + "status": "ok", + "service": "pegma-dev-api", + "checkedAt": "2026-07-27T21:00:00.000Z", + "checks": { + "process": { "status": "ok" }, + "logging": { + "status": "ok", + "detail": { "cloudflare": true, "datadog": true } + } + } +} +``` + +## Vendored `@pegma/health` + +Until `@pegma/health` is on npm, the Worker depends on +`worker-vendor/pegma-health-0.1.0.tgz` packed from `pegma-dev/health`. diff --git a/worker/src/index.ts b/worker/src/index.ts index c55920d..81ff458 100644 --- a/worker/src/index.ts +++ b/worker/src/index.ts @@ -1,3 +1,9 @@ +import { + createDetailCheck, + createProcessCheck, + runHealthChecks, + toHealthResponse, +} from '@pegma/health'; import { createAppLogger, type LoggerEnv } from './logger'; export interface Env extends LoggerEnv {} @@ -24,18 +30,19 @@ export default { }); if (request.method === 'GET' && (path === '/' || path === '/health')) { - logger.log('info', 'health.ok', { path }); - return Response.json( - { - ok: true, - service: 'pegma-dev-api', - logging: { + const result = await runHealthChecks({ + service: 'pegma-dev-api', + logger, + checks: [ + createProcessCheck(), + createDetailCheck('logging', { cloudflare: true, datadog: Boolean(env.DATADOG_API_KEY), - }, - }, - { status: 200 }, - ); + }), + ], + }); + const { status, body } = toHealthResponse(result); + return Response.json(body, { status }); } logger.log('warn', 'request.not_found', { method: request.method, path });