Files
errors.bitreport.pt/docs/OBSERVABILITY_PROMETHEUS.md
David Santos b29f72bef4
CI / Test ingest-api (push) Has been cancelled
CI / Test api (push) Has been cancelled
CI / Lint and typecheck admin-ui (push) Has been cancelled
CI / Validate Docker build (push) Has been cancelled
feat(api): BIT-2601 rate-limit typing, login preset, and rejection metrics
Align hub rate-limit error context with @fastify/rate-limit types, parse RATE_*
and body-size env vars via parsePositiveIntEnv, wire POST /admin/auth/login to
the login preset, increment er_api_rate_limit_rejections_total per bucket, and
document ingest_token_id plus Prometheus scraping notes.

Made-with: Cursor
2026-04-12 11:29:31 +00:00

4.2 KiB
Raw Permalink Blame History

Observability — Prometheus & Grafana (errors.bitreport.pt)

Audience: DevOps, SRE.
Scope: Two processes expose GET /metrics in Prometheus text format:

Service Typical scrape URL Metric prefix (node defaults)
Hub API (api/) http://<hub-host>:3200/metrics er_api_*, plus domain gauges er_*
Ingest API (ingest-api/) http://<ingest-host>:<port>/metrics er_ingest_*

Scrape both targets in Prometheus; use Grafana for dashboards and alerts.


1. Scraping configuration (Prometheus)

Add two static_configs jobs (names are examples):

scrape_configs:
  - job_name: errors_hub_api
    metrics_path: /metrics
    static_configs:
      - targets: ['10.10.50.x:3200']
        labels:
          service: errors_hub
          env: production

  - job_name: errors_ingest_api
    metrics_path: /metrics
    static_configs:
      - targets: ['10.10.50.y:3210']
        labels:
          service: errors_ingest
          env: production

If TLS or auth is fronted by Nginx, scrape the internal listener or enable mTLS/network policy as per your standard.


2. Hub API — key metrics

HTTP traffic

  • er_api_http_requests_total — labels: method, route, status_code.
  • er_api_http_request_duration_seconds — histogram for latency SLOs.
  • er_api_rate_limit_rejections_total — labels: bucket (global, ingest, login, mutation). Increments when @fastify/rate-limit returns 429 (or 403 when ban applies) for that policy. Use alongside status_code="429" on the HTTP counter to alert on abuse vs. organic load.

Domain gauges (refreshed when GET /api/error-monitoring/stats runs)

Automation or Grafana can poll that endpoint on an interval (with read key) to keep gauges warm, or you rely on natural admin/UI traffic.

Metric Labels Meaning
er_incidents_total state Count by open, investigating, resolved, ignored
er_incidents_by_severity severity Count by severity
er_occurrences_last_24h — Occurrence rows in last 24h
er_resolved_last_24h — Distinct incidents resolved in last 24h
er_project_incidents_total project, state Per-project counts
er_project_resolution_rate project Resolved ÷ total (0..1)

Node/process defaults

collectDefaultMetrics runs with prefix er_api_ — includes event loop delay, heap, GC, etc. Use for generic health.


3. Ingest API — key metrics

Metric Labels Meaning
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_batch_size — Histogram of events per request
er_ingest_active_connections — In-flight requests (gauge)

Plus er_ingest_* process defaults from prom-client.


4. Grafana — starter panels

  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.
  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])).

5. Linking to the observability “stats” stream

The hub’s GET /api/error-monitoring/stats JSON payload is the operational summary humans use; Prometheus mirrors a subset as gauges when that route is called. For Grafana:

  • Prefer metrics for trends and alerting.
  • Use the JSON endpoint (with api_key) for ad-hoc checks or scripted reports — see HTTP_CONTRACTS.md.