Files
David Santos 23704d2e59
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
feat(ingest): label er_ingest_events_total skipped_noise by rule_id
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
2026-07-17 23:01:35 +00:00

224 lines
7.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Runbook: Error Monitoring SLO Alerts
Service: `errors.bitreport.pt` (api + ingest-api)
Dashboard: Grafana `er-ops-slo` (import `deploy/grafana/error-monitoring-dashboard.json`)
---
## SLO Targets
| Metric | Target | Alert Threshold |
|--------|--------|-----------------|
| Ingest p95 latency | < 500 ms | > 500 ms for 5 min |
| Ingest p99 latency | < 1 s | > 1 s for 5 min |
| Ingest error rate | < 1% | > 1% for 5 min |
| API uptime | 99.5% | /health fails for 30 s |
---
## Prometheus Alert Rules
Add to your Prometheus `rules.yml`:
```yaml
groups:
- name: er_ingest_slo
interval: 30s
rules:
- alert: IngestP95LatencyHigh
expr: >
histogram_quantile(0.95,
sum(rate(er_ingest_request_duration_seconds_bucket[5m])) by (le)
) > 0.5
for: 5m
labels:
severity: warning
service: ingest-api
annotations:
summary: "Ingest p95 latency exceeds 500ms SLO"
description: >
p95 ingest latency is {{ $value | humanizeDuration }}.
Check DB query time, connection pool, and active connections.
- alert: IngestP99LatencyHigh
expr: >
histogram_quantile(0.99,
sum(rate(er_ingest_request_duration_seconds_bucket[5m])) by (le)
) > 1.0
for: 5m
labels:
severity: critical
service: ingest-api
annotations:
summary: "Ingest p99 latency exceeds 1s SLO"
description: >
p99 ingest latency is {{ $value | humanizeDuration }}.
Immediate investigation required.
- alert: IngestErrorRateHigh
expr: >
sum(rate(er_ingest_requests_total{status_code=~"5.."}[5m]))
/
sum(rate(er_ingest_requests_total[5m]))
> 0.01
for: 5m
labels:
severity: warning
service: ingest-api
annotations:
summary: "Ingest error rate exceeds 1%"
description: >
{{ $value | humanizePercentage }} of ingest requests are failing.
- alert: IngestApiDown
expr: up{job="ingest-api"} == 0
for: 30s
labels:
severity: critical
service: ingest-api
annotations:
summary: "Ingest API is unreachable"
- alert: ErrorApiDown
expr: up{job="error-api"} == 0
for: 30s
labels:
severity: critical
service: api
annotations:
summary: "Error monitoring API is unreachable"
```
### Collector → ingest resilience ([BIT-2600](/BIT/issues/BIT-2600))
The **collector-worker** pushes batched events to **ingest-api** (`POST /v1/ingest/events`). Large or bursty payloads (for example many “feed upload” failure reports from upstream jobs) benefit from tunable timeouts and client-side retries before the worker applies source-level backoff.
| Variable | Default (code / compose) | Role |
|----------|--------------------------|------|
| `INGEST_PUSH_TIMEOUT_MS` | `60000` | Per-attempt HTTP timeout (abort + retry if transient). |
| `INGEST_PUSH_MAX_RETRIES` | `3` | Extra attempts after the first failure (cap 12 in code). |
| `INGEST_PUSH_RETRY_BASE_MS` | `500` | Base delay; delay before retry *k* is `base * 2^k` + jitter. |
| `INGEST_PUSH_RETRY_MAX_JITTER_MS` | `250` | Random jitter upper bound (inclusive) added to each delay. |
Transient failures retried: HTTP `408`, `425`, `429`, `5xx`, timeouts, and common Node `fetch` network errors. Non-transient `4xx` (except those listed) are not retried.
**Structured logs:** on failure, `collector_ingest_failed` includes `ingest_push_attempts` (total HTTP attempts in that cycle) and `consecutive_failures` (scheduler backoff counter). On success after retries, `collector_cycle_complete` still includes `ingest_push_attempts` when it was greater than one.
**Alerting ideas**
- **Ingest SLO:** keep using `IngestErrorRateHigh` on `er_ingest_requests_total` — sustained 5xx/429 from the collector’s perspective show up here.
- **Log / trace backend:** alert when `msg="collector_ingest_failed"` and `consecutive_failures` stays above a threshold (for example ≥ 5) for longer than your SLO window, which indicates the source is failing every poll even after ingest push retries.
---
## Prometheus Scrape Config
Add to `prometheus.yml`:
```yaml
scrape_configs:
- job_name: error-api
scrape_interval: 15s
static_configs:
- targets: ['api:3200']
metrics_path: /metrics
- job_name: ingest-api
scrape_interval: 15s
static_configs:
- targets: ['ingest-api:3041']
metrics_path: /metrics
```
---
## Triage: IngestP95LatencyHigh / IngestP99LatencyHigh
1. **Check Grafana dashboard** `er-ops-slo` > Ingestion SLO row.
2. **Active connections**: `er_ingest_active_connections` — if high, requests are queuing.
3. **DB pool saturation**: check MariaDB `Threads_running` and `Threads_connected`.
```sql
SHOW STATUS LIKE 'Threads_%';
SHOW PROCESSLIST;
```
4. **Slow queries**: check if large batches are locking `er_incidents` or `er_incident_occurrences`.
```sql
SHOW FULL PROCESSLIST;
SELECT * FROM information_schema.INNODB_TRX;
```
5. **Resource pressure**: check container CPU/memory via `docker stats` or node exporter.
6. **Mitigation**:
- Scale DB connection pool: `DB_POOL_MAX` (api), `connectionLimit` (ingest-api `server.ts`).
- Reduce `INGEST_RATE_LIMIT_MAX` to shed load.
- Restart ingest-api pod if event loop is stuck.
---
## Triage: IngestErrorRateHigh
1. Check ingest-api logs: `docker compose logs ingest-api --tail=200`
2. Filter 5xx: look for `ingest_failed` log entries.
3. Common causes:
- MariaDB connection refused (pool exhausted or DB down).
- Schema validation failures from malformed payloads.
- Deadlocks on `er_incidents` UPSERT (fingerprint contention).
4. **Mitigation**:
- If DB down: restart MariaDB, verify healthcheck.
- If deadlocks: check for hot fingerprints receiving concurrent writes.
- If payload issues: check collector-worker for malformed source data.
---
## Triage: IngestApiDown / ErrorApiDown
1. Check container status: `docker compose ps`
2. Check logs: `docker compose logs <service> --tail=50`
3. Common causes:
- OOM kill (check `dmesg | grep -i oom`).
- Port conflict.
- DB migration failure blocking startup.
4. **Mitigation**: `docker compose restart <service>`
---
## Key Endpoints for Manual Checks
| Check | Command |
|-------|---------|
| API health | `curl -sf http://localhost:3200/health` |
| Ingest health | `curl -sf http://localhost:3041/health` |
| API Prometheus | `curl -sf http://localhost:3200/metrics` |
| Ingest Prometheus | `curl -sf http://localhost:3041/metrics` |
| Operational stats | `curl -sf 'http://localhost:3200/api/error-monitoring/stats?api_key=...'` |
---
## Useful PromQL Queries
```promql
# 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)
# Average batch size
rate(er_ingest_batch_size_sum[5m]) / rate(er_ingest_batch_size_count[5m])
# Incidents by severity (gauge)
er_incidents_by_severity
# Resolution rate per project
er_project_resolution_rate
# API HTTP latency p95
histogram_quantile(0.95, sum(rate(er_api_http_request_duration_seconds_bucket[5m])) by (le, route))
```