Extend GET /v1/stats/trend with granularity=hour (UTC buckets) and granularity=day response envelope. Enrich GET /v1/stats/summary per-project totals and critical counts. Add GET /v1/stats/recurrence for top incidents by occurrence volume in a sliding window. Add index on er_incident_occurrences(occurred_at) for range queries. Wire admin dashboard to summary, 24h/14d trends, and recurrence table. Document contract in docs/ADMIN_STATS_API.md. Paperclip-Agent: Pedro Alves (urlKey pedro-alves; id d706f4e6-5d05-4cec-b6e8-f8fb1f203aae) Paperclip-Issue: BIT-728 Paperclip-Run: 948904bb-20d7-4d29-9cd7-4c22544f7570 Made-with: Cursor
2.8 KiB
2.8 KiB
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 withseverity = critical, any state).bySeverity: global counts keyed by severity.resolvedLast24h: distinct incidents moved toresolvedin 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 datesYYYY-MM-DD(inclusive window).series: for each severity, an array of counts aligned withdates.
Response — hourly (granularity=hour)
granularity:"hour"hours: UTC hour bucket labelsYYYY-MM-DD HH:00:00(start of bucket).series: same shape as daily, aligned withhours.
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 (MySQLDATETIME(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 migration20260402103000_add_occurred_at_for_stats).
Related
- Public ingest /
recent-errors:docs/in this repo and PaperclipERROR_REPORTING_HUB_CONTRACT.md.