From d47a0613993df72bbdada0b48a0cceee5398e4ae Mon Sep 17 00:00:00 2001 From: Peter Spark Date: Sun, 5 Apr 2026 04:33:08 +0000 Subject: [PATCH] ingest-api: allow unknown event JSON fields for forward-compatible clients - Relax Fastify/AJV schema on ingest events (additionalProperties: true) so CRM/deploy smokes sending extra keys no longer fail validation with 400. - Add integration test when ERROR_REPORTING_TEST_DATABASE_URL is set. - Document BIT-SMOKE / BIT-931 triage in RUNBOOK_INGEST_DEBUG; note in ingest-hardening-runbook. Paperclip-Agent: 0b1fcf92-5fe3-4ac0-9f29-df4ab72f5376 Paperclip-Issue: 35542fda-44d4-4154-b95d-1a7de3566204 Paperclip-Run: 3682ff13-02fc-4749-a460-6414830dccc7 Made-with: Cursor --- docs/RUNBOOK_INGEST_DEBUG.md | 23 ++++++++++++++++ docs/operations/ingest-hardening-runbook.md | 5 ++++ ingest-api/src/buildApp.ts | 3 ++- .../src/integration.twoProjects.test.ts | 27 +++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/docs/RUNBOOK_INGEST_DEBUG.md b/docs/RUNBOOK_INGEST_DEBUG.md index 23a0422..84ca40d 100644 --- a/docs/RUNBOOK_INGEST_DEBUG.md +++ b/docs/RUNBOOK_INGEST_DEBUG.md @@ -5,6 +5,29 @@ --- +## 0. Deploy smoke: `BIT-SMOKE error hub ingest live check` (wdmi-store / CRM) + +**Symptoms:** Hub incident titled like **`BIT-SMOKE error hub ingest live check`** (ex.: [BIT-931](/BIT/issues/BIT-931), `ERRSIG:0dfffa22f758`) — the application’s post-deploy probe could not complete a successful **`POST /v1/ingest/events`** (or treated the response as failure). + +**Not the same as** feed/XML upload failures — those hit catalog APIs; see [RUNBOOK_REPORTER_WDMI_FEED_UPLOAD.md](RUNBOOK_REPORTER_WDMI_FEED_UPLOAD.md). + +**Checks (in order)** + +1. **From the reporter host** (same egress as the app), run [scripts/examples/ingest_smoke.sh](../scripts/examples/ingest_smoke.sh) with production `INGEST_API_BASE` and the **same** ingest key as the app (read token from a file; avoid shell history). +2. **URL:** must be the ingest service base (no path suffix in env) — clients append `/v1/ingest/events` themselves (see [clients/php/ErrorReporter.php](../clients/php/ErrorReporter.php), [HTTP_CONTRACTS.md](HTTP_CONTRACTS.md)). +3. **Credentials:** `Authorization: Bearer ` or `X-Api-Key`; key must be **active** and **unexpired** in `er_ingest_keys` (§2). +4. **HTTP codes:** `401` / `429` / `5xx` / timeouts — use sections below; CRM cURL timeouts are short (e.g. 4s) — slow proxies can fail smokes before the hub responds. +5. **HTTP 400 from schema validation** should be rare; the hub ignores unknown **event-level** JSON keys and only requires `schema_version`, `occurred_at`, `level`, `message`. + +**After the root cause is fixed** + +```bash +./scripts/er-cli.sh list-open --project wdmi-store --q "ERRSIG:0dfffa22f758" +./scripts/er-cli.sh resolve --note "ingest smoke restored; verified POST /v1/ingest/events from wdmi-store" --assigned-to "oncall" +``` + +--- + ## 1. Quick health ```bash diff --git a/docs/operations/ingest-hardening-runbook.md b/docs/operations/ingest-hardening-runbook.md index a9fa713..8e45198 100644 --- a/docs/operations/ingest-hardening-runbook.md +++ b/docs/operations/ingest-hardening-runbook.md @@ -16,6 +16,11 @@ Use this after deploying ingest API or changing fingerprint / noise / rate-limit Per-key overrides: set `rate_limit_max` and/or `rate_limit_window_ms` on the key row; NULL means inherit the corresponding env default. +## Request schema (forward compatibility) + +- Top-level body must remain `{ "events": [ … ] }` only (no extra root keys). +- Each **event** object must include `schema_version`, `occurred_at`, `level`, and `message`. Additional event-level properties are **accepted and ignored** by the processor so integrators can attach metadata without breaking validation. + ## Fingerprint quality - Server-side fingerprint policy version is returned on each ingest response as `fingerprint_policy_version`. diff --git a/ingest-api/src/buildApp.ts b/ingest-api/src/buildApp.ts index 9e353db..080339e 100644 --- a/ingest-api/src/buildApp.ts +++ b/ingest-api/src/buildApp.ts @@ -19,7 +19,8 @@ import prometheusPlugin, { const _ingestEventSchema = { type: "object", - additionalProperties: false, + /** Ignore unknown keys so integrators (CRM smoke checks, SDKs) can add forward-compatible metadata without 400. */ + additionalProperties: true, required: ["schema_version", "occurred_at", "level", "message"], properties: { schema_version: { type: "integer", minimum: 1, maximum: 1 }, diff --git a/ingest-api/src/integration.twoProjects.test.ts b/ingest-api/src/integration.twoProjects.test.ts index 22860bd..8d1b9db 100644 --- a/ingest-api/src/integration.twoProjects.test.ts +++ b/ingest-api/src/integration.twoProjects.test.ts @@ -132,6 +132,33 @@ describe.skipIf(!_testUrl)("two-project passive ingest (BIT-179)", () => { expect(Number((checkB[0] as { c: number }).c)).toBe(1); }); + it("accepts unknown event-level fields (forward-compatible for CRM / deploy smokes)", async () => { + const _res = await _app.inject({ + method: "POST", + url: "/v1/ingest/events", + headers: { authorization: `Bearer ${_tokenA}` }, + payload: { + events: [ + { + schema_version: 1, + occurred_at: "2026-03-22T10:05:00.000Z", + level: "error", + message: "probe with extra keys", + fingerprint: "fp-extra-keys-1", + release: "1.0.0", + environment: "production", + }, + ], + }, + }); + expect(_res.statusCode).toBe(200); + const _body = JSON.parse(_res.body) as { + results: Array<{ incident_id: string; fingerprint: string }>; + }; + expect(_body.results).toHaveLength(1); + expect(_body.results[0]?.fingerprint).toBe("fp-extra-keys-1"); + }); + it("skips known browser noise without inserting rows", async () => { const [before] = await _pool.execute( `SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,