145_ops_metrics_ttft_sample_count.sql 955 B

123456789101112131415161718192021
  1. -- Add ttft_sample_count to ops_metrics_hourly / ops_metrics_daily.
  2. --
  3. -- first_token_ms (TTFT) is only recorded for streaming requests, but the
  4. -- dashboard previously weighted merged TTFT percentiles by success_count
  5. -- (all successful requests, streaming + non-streaming). That diluted/skewed
  6. -- the merged TTFT figures whenever non-streaming traffic was present.
  7. --
  8. -- Store the real streaming sample count per bucket so TTFT percentiles can be
  9. -- weighted by the number of rows that actually contributed a first_token_ms.
  10. --
  11. -- Existing rows default to 0; they will be repopulated on the next hourly
  12. -- re-aggregation pass. Migration is idempotent and safe to re-run.
  13. SET LOCAL lock_timeout = '5s';
  14. SET LOCAL statement_timeout = '10min';
  15. ALTER TABLE ops_metrics_hourly
  16. ADD COLUMN IF NOT EXISTS ttft_sample_count BIGINT NOT NULL DEFAULT 0;
  17. ALTER TABLE ops_metrics_daily
  18. ADD COLUMN IF NOT EXISTS ttft_sample_count BIGINT NOT NULL DEFAULT 0;