Skip to content

convex/kpis.ts

Purpose

Periodic rollup of per‑minute KPIs (runs, errors, p95 latency, cost) into kpis_1m.

Public Surface

  • rollup1m(ctx): internal mutation called by cron every minute.
  • crons.interval("rollup-1m", { minutes: 1 }, internal.kpis.rollup1m)

Behavior & Invariants

  • Scans runs_live created within the last closed minute, buckets by projectId.
  • Computes p95 defensively (max for small samples).

Dependencies

  • Depends on: runs_live with by_created_time index.
  • Used by: UI (future) for faster KPI charts.

TODO / Technical Debt

  • Provide queries to fetch kpis_1m for dashboards.