Files
errors.bitreport.pt/docs/RUNBOOK_SLO.md
T
Peter Spark c6e4305c79 feat(observability): stats endpoint, Prometheus metrics, SLO tracking, Grafana dashboard (BIT-734)
- GET /api/error-monitoring/stats: 24h ingestion volume, severity
  distribution, per-project metrics with resolution rates, hourly trend
- Prometheus /metrics on both api (port 3200) and ingest-api (port 3041)
  with HTTP request duration histograms, ingest SLO latency (p50/p95/p99),
  event throughput counters, domain gauges
- Grafana dashboard JSON (deploy/grafana/) with SLO panels, error volume,
  severity/state distribution, per-project charts, Node.js process metrics
- SLO runbook (docs/RUNBOOK_SLO.md): alert rules, scrape config,
  triage procedures for latency, error rate, and availability breaches

Paperclip-Agent: Peter Spark (urlKey peter-spark; id 49ce66f8-6be6-4644-afd3-eb6d8d0d4b3e)
Paperclip-Issue: BIT-734
Paperclip-Run: f45bcdc4-4757-4829-8e75-b60a8f9a7be4
2026-04-02 18:26:24 +00:00

5.5 KiB

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:

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"

Prometheus Scrape Config

Add to prometheus.yml:

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.

    SHOW STATUS LIKE 'Threads_%';
    SHOW PROCESSLIST;
    
  4. Slow queries: check if large batches are locking er_incidents or er_incident_occurrences.

    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

# Ingest throughput (events/sec)
sum(rate(er_ingest_events_total[5m])) by (outcome)

# 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))