Tài liệu này dùng làm checklist chuẩn cho agent khi xử lý các sự cố dashboard thiếu dữ liệu dù DB vẫn có traffic.
Chạy playbook nếu có ít nhất 1 dấu hiệu:
- UI thiếu model/key mới (vd:
gpt-5.3-codex, keyclaude) dù hệ thống đang phát sinh usage. daily_statsđứng im hoặc tăng bất thường chậm.- Collector log có lỗi ghi DB (
numeric field overflow,out of range,invalid input syntax, v.v.). - API
/rest/v1/daily_statstrả dữ liệu cũ hơn snapshot mới nhất.
docker compose ps- Collector phải
healthy, Postgres/PostgREST/frontend phảiUp.
docker logs cliproxy-collector --tail=300- Check các chuỗi:
- Có
Stored snapshot ...đều đặn mỗi chu kỳ. - Không còn lỗi kiểu overflow/casting.
- Có log migration mới được apply nếu vừa deploy (
Migration applied: ...).
- Có
- So sánh snapshot mới nhất với
daily_statshôm nay:usage_snapshotscó bản ghi mới trong vòng 1 chu kỳ poll.daily_stats.stat_date=todaycóupdated_atmới.
- Cost columns có đủ lớn không?
usage_snapshots.cumulative_cost_usdmodel_usage.estimated_cost_usddaily_stats.estimated_cost_usd
- Counter columns có phải
BIGINTkhông?usage_snapshots.total_requests/success_count/failure_countmodel_usage.request_countdaily_stats.total_requests/success_count/failure_count
- Đã cập nhật cả hai chưa?
init-db/schema.sql(fresh install)collector/migrations/*.sql(existing DB)
- Collector startup có chạy
run_migrations()và apply file mới không?
- Frontend đọc từ
daily_statshay bảng khác? daily_statscó thể lệch dùmodel_usageđã mới.- PostgREST có cần restart để refresh metadata sau schema change.
TIMEZONE_OFFSET_HOURScollector đúng với expectation chưa (mặc định7).- Query “today” phải dùng cùng mốc timezone giữa DB check, collector, và UI.
- Mở rộng kiểu cost →
NUMERIC(20,6). - Nâng request counters →
BIGINT. - Không đổi business logic trừ khi cần thiết; ưu tiên schema fix.
- Migration chỉ widening type, không drop column/table.
- Đặt tên migration tăng dần (
000N_...sql). - Verify local diff chỉ chạm file cần thiết.
- Backup DB trước khi deploy (
pg_dumphoặc snapshot volume). - Pull image mới.
- Chạy
docker compose up -dđể khởi động theo dependency graph release-safe. - Xác nhận thứ tự boot kỳ vọng:
postgreshealthy.collectorhealthy (migrations đã apply xong).postgrestchỉ start sau collector healthy.frontendchỉ start sau postgrest start.
- Theo dõi logs:
- Collector có
Migration appliedhoặc migration skip hợp lệ. - Không còn lỗi overflow.
- Không có lỗi PostgREST kiểu missing column/table ngay sau startup.
- Collector có
- Chạy smoke API:
GET /api/collector/healthGET /rest/v1/daily_stats?...limit=1POST /api/collector/triggerrồi verify lại read path.
model_usage/usage_snapshotscó dữ liệu mới, nhưngdaily_statsthấp rõ rệt/đứng im.
- Rebuild
daily_statschotodaytừ dữ liệu cumulative:- Dùng
first snapshot of dayvàlatest snapshot of day. - Delta = latest - first (restart-safe: nếu âm thì dùng latest).
- Dùng
- Rebuild
breakdown.modelsvàbreakdown.endpointstừmodel_usagetương ứng. - Upsert đúng
stat_date=today.
- Restart
postgrest+frontend. - Verify API
/rest/v1/daily_stats?...stat_date=eq.todaytrả số mới. - Refresh UI Today để confirm.
- Không còn lỗi overflow/cast trong collector logs 300 dòng gần nhất.
- Có ít nhất 2 chu kỳ
Stored snapshot ...thành công sau deploy.
information_schema.columnsxác nhận đúng kiểu mới.daily_stats(today)cập nhật mới theo chu kỳ poll.model_usagesnapshot mới nhất có model/endpoint kỳ vọng (vdgpt-5.3-codex+claude).credential_daily_statscó key kỳ vọng (api_key_name='claude') và token tăng.
GET /rest/v1/daily_stats?...không còn đứng ở mốc cũ.- UI Today khớp DB (requests/cost/model breakdown).
- Nếu migration lỗi do lock:
- Tạm dừng collector.
- Gỡ lock/đợi transaction.
- Chạy lại collector để migration apply.
- Nếu app lỗi sau deploy nhưng migration đã thành công:
- Có thể rollback image collector/frontend (schema widening vẫn tương thích).
- Full DB restore chỉ dùng khi bất khả kháng.
Chỉ được đóng incident khi đủ tất cả:
- Collector logs sạch lỗi overflow tối thiểu 2 chu kỳ.
-
daily_stats(today)cập nhật mới. - API trả dữ liệu mới.
- UI phản ánh đúng model/key mới.
- Đã ghi nhận nguyên nhân gốc + migration đã merge/push.