From 82f549adbcd740970a4b888223b0778f51f2cc5f Mon Sep 17 00:00:00 2001 From: Peter Spark Date: Sun, 5 Apr 2026 05:23:32 +0000 Subject: [PATCH] ingest: filter BIT-SMOKE- intentional probe events Reserved BIT-SMOKE- messages (e.g. wdmi-store /smoke/wdmi.js direct-ingest checks) are skipped at every ingest level so they do not open incidents or trigger BIT-309 loops. Bump noise ruleset to 1.0.2; extend unit and integration tests and ingest hardening runbook. Paperclip-Issue: BIT-942 Made-with: Cursor --- docs/operations/ingest-hardening-runbook.md | 2 +- .../src/integration.twoProjects.test.ts | 36 +++++++++++++++++++ ingest-api/src/lib/noisePolicy.test.ts | 26 ++++++++++++++ ingest-api/src/lib/noisePolicy.ts | 13 +++++-- 4 files changed, 74 insertions(+), 3 deletions(-) diff --git a/docs/operations/ingest-hardening-runbook.md b/docs/operations/ingest-hardening-runbook.md index 8e45198..6ac654f 100644 --- a/docs/operations/ingest-hardening-runbook.md +++ b/docs/operations/ingest-hardening-runbook.md @@ -32,7 +32,7 @@ Per-key overrides: set `rate_limit_max` and/or `rate_limit_window_ms` on the key - Rules live in `ingest-api/src/lib/noisePolicy.ts`; ruleset id: `noise_ruleset_version` in the ingest response. - **Check:** send a known-noise payload (for example ResizeObserver message at non-fatal level); expect `skipped: true`, `noise_filtered_count` incremented, and no new `er_incidents` row. -- **Check:** send the same pattern at `fatal` / `critical` level; expect **not** skipped (noise rules do not hide critical). +- **Check:** send the same pattern at `fatal` / `critical` level; expect **not** skipped (noise rules do not hide critical), **except** messages containing reserved substring `BIT-SMOKE-` (intentional reporter smoke, e.g. wdmi-store `/smoke/wdmi.js`) — those are skipped at every level (`rule_id`: `bitreport_smoke_marker`). ## Rate limits diff --git a/ingest-api/src/integration.twoProjects.test.ts b/ingest-api/src/integration.twoProjects.test.ts index 16526e0..b182380 100644 --- a/ingest-api/src/integration.twoProjects.test.ts +++ b/ingest-api/src/integration.twoProjects.test.ts @@ -222,6 +222,42 @@ describe.skipIf(!_testUrl)("two-project passive ingest (BIT-179)", () => { expect(Number((after[0] as { c: number }).c)).toBe(_nBefore); }); + it("skips BIT-SMOKE- intentional probe events without inserting rows", async () => { + const [before] = await _pool.execute( + `SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`, + [_projectIdA], + ); + const _nBefore = Number((before[0] as { c: number }).c); + const _res = await _app.inject({ + method: "POST", + url: "/v1/ingest/events", + headers: { authorization: `Bearer ${_tokenA}` }, + payload: { + events: [ + { + schema_version: 1, + occurred_at: "2026-04-05T10:00:00.000Z", + level: "error", + message: "Error: BIT-SMOKE-WDMI-DIRECT-INGEST", + }, + ], + }, + }); + expect(_res.statusCode).toBe(200); + const _body = JSON.parse(_res.body) as { + noise_filtered_count: number; + results: Array<{ skipped?: boolean; rule_id?: string }>; + }; + expect(_body.noise_filtered_count).toBe(1); + expect(_body.results[0]?.skipped).toBe(true); + expect(_body.results[0]?.rule_id).toBe("bitreport_smoke_marker"); + const [after] = await _pool.execute( + `SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`, + [_projectIdA], + ); + expect(Number((after[0] as { c: number }).c)).toBe(_nBefore); + }); + it("replays identical idempotent requests", async () => { const _payload = { events: [ diff --git a/ingest-api/src/lib/noisePolicy.test.ts b/ingest-api/src/lib/noisePolicy.test.ts index 970f4cb..eb82f85 100644 --- a/ingest-api/src/lib/noisePolicy.test.ts +++ b/ingest-api/src/lib/noisePolicy.test.ts @@ -75,4 +75,30 @@ describe("evaluateNoise", () => { }); expect(_r).toEqual({ matched: false }); }); + + it("matches reserved BIT-SMOKE- probe messages (wdmi direct ingest smoke)", () => { + const _r = evaluateNoise({ + level: "error", + message: "Error: BIT-SMOKE-WDMI-DIRECT-INGEST", + filePathHint: "/smoke/wdmi.js", + }); + expect(_r).toEqual({ + matched: true, + ruleId: "bitreport_smoke_marker", + reason: "filtered_intentional_smoke_event", + }); + }); + + it("suppresses BIT-SMOKE- even at critical ingest level", () => { + const _r = evaluateNoise({ + level: "critical", + message: "BIT-SMOKE-WDMI-DIRECT-INGEST", + filePathHint: "", + }); + expect(_r).toEqual({ + matched: true, + ruleId: "bitreport_smoke_marker", + reason: "filtered_intentional_smoke_event", + }); + }); }); diff --git a/ingest-api/src/lib/noisePolicy.ts b/ingest-api/src/lib/noisePolicy.ts index ee32466..863df66 100644 --- a/ingest-api/src/lib/noisePolicy.ts +++ b/ingest-api/src/lib/noisePolicy.ts @@ -4,7 +4,7 @@ import { normalizeLevelToSeverity } from "./normalize.js"; * Versioned ruleset id (document in release notes when rules change). * Rule inventory and validation steps: `docs/operations/ingest-hardening-runbook.md`. */ -export const NOISE_RULESET_VERSION = "1.0.1"; +export const NOISE_RULESET_VERSION = "1.0.2"; export type NoiseEvaluation = | { matched: false } @@ -127,6 +127,8 @@ const _RULES: NoiseRule[] = [ /** * Conservative: never classify fatal/critical ingest levels as noise (avoid hiding real outages). + * Exception: reserved `BIT-SMOKE-` messages are intentional end-to-end probes (e.g. wdmi-store + * `/smoke/wdmi.js`) and are filtered at every ingest level so they do not open incidents. */ export function evaluateNoise(input: { level: string; @@ -134,11 +136,18 @@ export function evaluateNoise(input: { context?: Record; filePathHint: string; }): NoiseEvaluation { + const _msg = input.message.trim(); + if (_msg.includes("BIT-SMOKE-")) { + return { + matched: true, + ruleId: "bitreport_smoke_marker", + reason: "filtered_intentional_smoke_event", + }; + } const _sev = normalizeLevelToSeverity(input.level); if (_sev === "critical") { return { matched: false }; } - const _msg = input.message; const _msgLower = _msg.toLowerCase(); const _file = input.filePathHint; const _fileLower = _file.toLowerCase();