feat(ingest): label er_ingest_events_total skipped_noise by rule_id
CI / Test api (push) Successful in 54s
CI / Test ingest-api (push) Successful in 57s
CI / Lint and typecheck admin-ui (push) Successful in 1m48s
CI / Validate Docker build (push) Successful in 5m19s

Break down noise filter counters per noise policy rule for Prometheus observability.

Paperclip-Agent: David Santos (urlKey david-santos; id 0b1fcf92-5fe3-4ac0-9f29-df4ab72f5376)
Paperclip-Issue: BIT-26791
Paperclip-Run: cea24469-2886-457d-9f6f-09d83aaf9e4a
This commit is contained in:
David Santos committed 2026-07-17 23:01:35 +00:00
1 parent caeb37ff0a
commit 23704d2e59
7 files changed
+43 -11

No files matched your search

+15 -7
View File
@@ -239,16 +239,20 @@ export async function buildApp(input: { env: IngestEnv; pool: Pool }): Promise<F
idempotencyKey: _idempotencyKey,
bodyHash: _bodyHash,
});
// Track event outcomes
// Track event outcomes (rule_id on skipped_noise for BIT-26791)
if (_out.body && typeof _out.body === "object" && "results" in _out.body) {
const results = (_out.body as { results: Array<{ skipped?: boolean }> }).results;
const results = (
_out.body as { results: Array<{ skipped?: boolean; rule_id?: string }> }
).results;
let stored = 0;
let skipped = 0;
let _maxOccurredSec = 0;
const skippedByRule = new Map<string, number>();
for (let _i = 0; _i < results.length; _i++) {
const r = results[_i]!;
if (r.skipped) {
skipped++;
const _ruleId =
typeof r.rule_id === "string" && r.rule_id !== "" ? r.rule_id : "unknown";
skippedByRule.set(_ruleId, (skippedByRule.get(_ruleId) ?? 0) + 1);
continue;
}
stored++;
@@ -262,8 +266,12 @@ export async function buildApp(input: { env: IngestEnv; pool: Pool }): Promise<F
}
}
}
if (stored > 0) ingestEventsTotal.inc({ outcome: "stored" }, stored);
if (skipped > 0) ingestEventsTotal.inc({ outcome: "skipped_noise" }, skipped);
if (stored > 0) {
ingestEventsTotal.inc({ outcome: "stored", rule_id: "" }, stored);
}
for (const [_ruleId, _n] of skippedByRule) {
ingestEventsTotal.inc({ outcome: "skipped_noise", rule_id: _ruleId }, _n);
}
const _slug = request.ingestAuth.projectSlug;
if (_slug !== "" && _maxOccurredSec > 0) {
errorHubLastEventTimestamp.set({ project_slug: _slug }, _maxOccurredSec);
@@ -284,7 +292,7 @@ export async function buildApp(input: { env: IngestEnv; pool: Pool }): Promise<F
message: "occurred_at must be a valid ISO-8601 timestamp.",
});
}
ingestEventsTotal.inc({ outcome: "error" }, _body.events.length);
ingestEventsTotal.inc({ outcome: "error", rule_id: "" }, _body.events.length);
const _slugErr = request.ingestAuth?.projectSlug ?? "";
if (_slugErr !== "") {
errorHubIngestFailuresTotal.inc({ project_slug: _slugErr }, _body.events.length);
@@ -242,6 +242,11 @@ describe.skipIf(!_testUrl)("two-project passive ingest (BIT-179)", () => {
expect(_body.noise_filtered_count).toBe(1);
expect(_body.results[0]?.skipped).toBe(true);
expect(_body.results[0]?.rule_id).toBe("resize_observer_loop");
const _metrics = await _app.inject({ method: "GET", url: "/metrics" });
expect(_metrics.statusCode).toBe(200);
expect(_metrics.body).toContain(
'er_ingest_events_total{outcome="skipped_noise",rule_id="resize_observer_loop"}',
);
const [after] = await _pool.execute<RowDataPacket[]>(
`SELECT COUNT(*) AS c FROM er_incidents WHERE project_id = ?`,
[_projectIdA],
@@ -0,0 +1,15 @@
import { describe, expect, it } from "vitest";
import { ingestEventsTotal, prometheusRegistry } from "./prometheus.js";
describe("er_ingest_events_total rule_id label (BIT-26791)", () => {
it("records skipped_noise with rule_id", async () => {
ingestEventsTotal.inc(
{ outcome: "skipped_noise", rule_id: "resize_observer_loop" },
1,
);
const _text = await prometheusRegistry.metrics();
expect(_text).toContain(
'er_ingest_events_total{outcome="skipped_noise",rule_id="resize_observer_loop"}',
);
});
});
+2 -1
View File
@@ -34,7 +34,8 @@ export const ingestDuration = new Histogram({
export const ingestEventsTotal = new Counter({
name: "er_ingest_events_total",
help: "Total events ingested",
labelNames: ["outcome"] as const, // stored, skipped_noise, error
// rule_id is set for skipped_noise (noise policy id); empty for stored/error
labelNames: ["outcome", "rule_id"] as const,
registers: [register],
});