Files
Peter Spark 8767e40bb6 docs(ops): hub parity tooling — HTTP contracts, runbooks, Prometheus
Add canonical HTTP_CONTRACTS with curl for hub + ingest endpoints, operator
runbooks for ingest debugging and five common hub flows, and Grafana/Prometheus
scraping notes. Extend ERROR_MONITORING_PUBLIC_API with stats + curl examples;
align purge and resolve-by-pattern docs with the Fastify implementation.
Add optional smoke scripts under scripts/examples/.

Paperclip-Agent: 5d084b36-f38f-42a5-a92a-520005afda4f
Paperclip-Issue: BIT-736
Paperclip-Run: ad2c5129-df54-44aa-afd4-6f9f7486c1a1
Made-with: Cursor
2026-04-02 20:36:57 +00:00

73 lines
2.9 KiB
Markdown

# Admin API — operational statistics (`/v1/stats/*`)
**Audience:** `errors.bitreport.pt` admin UI, internal dashboards, automation.
**Auth:** Same as other admin routes — JWT cookie (`__Host-access`) and permission `errors:read`.
**Base URL:** `ERROR_REPORTING_ADMIN_API_BASE` (Fastify service, typically port `3200` behind `/admin/` proxy).
## `GET /v1/stats/summary`
Aggregates over **all incidents** (current state), optional filter by project.
| Query | Description |
|--------|-------------|
| `project` | Optional. Project `slug`; omit for all projects. |
### Response
- `byProject[]`: per slug — `total` (incident count), `open`, `investigating`, `resolved`, `ignored`, `critical` (incidents with `severity = critical`, any state).
- `bySeverity`: global counts keyed by severity.
- `resolvedLast24h`: distinct incidents moved to `resolved` in the last 24 hours (state history).
- `totalLast24h`: occurrence rows in the last 24 hours.
## `GET /v1/stats/trend`
Occurrence counts bucketed by time and severity.
| Query | Description |
|--------|-------------|
| `granularity` | `day` (default) or `hour`. |
| `days` | With `granularity=day`: window length, default `30`, max `366`. |
| `hours` | With `granularity=hour`: number of UTC hour buckets ending at the current hour, default `24`, max `168`. |
| `project` | Optional project `slug`. |
### Response — daily (`granularity=day`)
- `granularity`: `"day"`
- `dates`: UTC calendar dates `YYYY-MM-DD` (inclusive window).
- `series`: for each severity, an array of counts aligned with `dates`.
### Response — hourly (`granularity=hour`)
- `granularity`: `"hour"`
- `hours`: UTC hour bucket labels `YYYY-MM-DD HH:00:00` (start of bucket).
- `series`: same shape as daily, aligned with `hours`.
Hourly buckets use `CONVERT_TZ(..., @@session.time_zone, '+00:00')` so labels match UTC wall-clock when the DB session timezone is configured consistently.
## `GET /v1/stats/recurrence`
Ranks incidents by **how many occurrence rows** they received in a sliding window (recurrence / noise hotspots).
| Query | Description |
|--------|-------------|
| `project` | Optional project `slug`. |
| `days` | Window length in days, default `7`, max `90`. |
| `limit` | Max rows, default `15`, max `100`. |
### Response
- `windowDays`, `rangeStart`, `rangeEndExclusive`: bounds used for the query (MySQL `DATETIME(6)` strings).
- `top[]`: `id`, `projectSlug`, `fingerprint`, `title`, `severity`, `currentState`, `hitsInWindow`, `lifetimeOccurrences`.
## Indexes
Heavy queries use:
- `er_incident_occurrences (project_id, occurred_at DESC)` — filtered trends and recurrence by project.
- `er_incident_occurrences (occurred_at DESC)` — global time-range scans (see migration `20260402103000_add_occurred_at_for_stats`).
## Related
- Curl examples (cookie login + `/v1/stats/*`): [`docs/HTTP_CONTRACTS.md`](HTTP_CONTRACTS.md).
- Public ingest / `recent-errors`: `docs/` in this repo and Paperclip `ERROR_REPORTING_HUB_CONTRACT.md`.