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

+2 -2
View File
@@ -72,7 +72,7 @@ Automation or Grafana can **poll** that endpoint on an interval (with read key)
|--------|--------|---------|
| `er_ingest_request_duration_seconds` | `status_code` | End-to-end POST latency (SLO: watch p95/p99) |
| `er_ingest_requests_total` | `status_code` | Request volume by outcome class |
| `er_ingest_events_total` | `outcome` | `stored`, `skipped_noise`, `error` |
| `er_ingest_events_total` | `outcome`, `rule_id` | `stored` / `error` use empty `rule_id`; `skipped_noise` sets noise policy id (e.g. `resize_observer_loop`) |
| `er_ingest_batch_size` | — | Histogram of events per request |
| `er_ingest_active_connections` | — | In-flight requests (gauge) |
@@ -84,7 +84,7 @@ Plus `er_ingest_*` process defaults from `prom-client`.
1. **Ingest availability:** `sum(rate(er_ingest_requests_total[5m])) by (status_code)`.
2. **Ingest latency:** histogram quantiles on `er_ingest_request_duration_seconds` (e.g. `histogram_quantile(0.95, …)`).
3. **Noise vs stored:** `rate(er_ingest_events_total{outcome="stored"}[5m])` vs `skipped_noise`.
3. **Noise vs stored:** `rate(er_ingest_events_total{outcome="stored"}[5m])` vs `skipped_noise`. Per-rule noise: `sum(rate(er_ingest_events_total{outcome="skipped_noise"}[5m])) by (rule_id)`.
4. **Open incidents:** `er_incidents_total` by `state` (after stats refresh).
5. **Hub HTTP errors:** `sum(rate(er_api_http_requests_total{status_code=~"5.."}[5m]))`.
+1 -1
View File
@@ -121,7 +121,7 @@ When **`Idempotency-Key`** is reused with a **different** JSON body, the API ret
## 7. Noise rules — events “disappear”
If the response shows `results[]` entries with `"skipped": true`, the event matched a **noise rule** (`rule_id`, `reason`). This is expected for filtered traffic. Check `noise_filtered_count` and compare with `er_ingest_events_total{outcome="skipped_noise"}` in Prometheus.
If the response shows `results[]` entries with `"skipped": true`, the event matched a **noise rule** (`rule_id`, `reason`). This is expected for filtered traffic. Check `noise_filtered_count` and compare with `er_ingest_events_total{outcome="skipped_noise"}` in Prometheus (series also carry `rule_id`).
---
+3
View File
@@ -203,6 +203,9 @@ scrape_configs:
# Ingest throughput (events/sec)
sum(rate(er_ingest_events_total[5m])) by (outcome)
# Noise skips by rule (BIT-26791)
sum(rate(er_ingest_events_total{outcome="skipped_noise"}[5m])) by (rule_id)
# Ingest request rate by status
sum(rate(er_ingest_requests_total[5m])) by (status_code)
+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],
});