Commit f9dffb6
authored
feat(db): per-day status/audit for the replay archive (Postgres, no deletion) (#423)
* feat(db): per-day status/audit for the replay archive (Postgres, no deletion)
Track the session-replay CH->Azure-Blob archive per day so we can see what's
archived/verified/failed and later verify by hand before any deletion. The job
records; it never drops a CH partition.
- Prisma model ReplayArchiveDay (@@Map replay_archive_days) + migration. One row
per day (= the CH partition unit toYYYYMMDD(started_at) and the verifyDay
unit). deletedAt column reserved for a future delete phase; never written here.
- replay-archive-day.service.ts: reconcileArchiveDay / markArchiving /
markVerified / markVerifyFailed / listArchiveDays.
- archive-replay-chunks.ts wiring:
* reconcileAllStatus() at start upserts EVERY settled day from counts (so days
archived before this existed are recorded too).
* per processed day: archiving -> archived+verifiedAt (verify passed) /
verify_failed+reason.
* all status writes are best-effort (status() wrapper): a Postgres hiccup or a
pod without DATABASE_URL logs a WARN and NEVER fails an archive run.
- status:replay CLI prints the table (day, status, ch/blob, drift, verifiedAt,
error) + a summary. Read-only.
No DROP PARTITION, no DELETE_AFTER_DAYS, no delete gate — observability only.
Rollout: run the migration first, then deploy; add DATABASE_URL to the archive
cron/backfill pods (openpanel repo manifests) so they can write.
* fix(db): address CodeRabbit — export-throw + unreadable-count status writes
- archiveProject signals failure by THROWING (never returns false), so the old
`if (!archiveProject)` branch was dead code and an export failure left the day
stuck at status='archiving'. Wrap the project loop in try/catch: record the
failure (without clobbering counts) and return false so the day retries and
the other days still run.
- verifyDay: reject unreadable/sentinel counts (idxN=-1, srcN=-2) before the
completeness check — otherwise `idxN < srcN` was false and a day with no
readable counts was marked archived with negative counts.
- markVerifyFailed: counts are now optional so the export-throw path doesn't
overwrite a real blob count with 0.1 parent 74327b7 commit f9dffb6
6 files changed
Lines changed: 339 additions & 7 deletions
File tree
- packages/db
- prisma
- migrations/20260818120000_add_replay_archive_days
- src
- cli
- services
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
569 | 569 | | |
570 | 570 | | |
571 | 571 | | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
35 | 41 | | |
36 | 42 | | |
37 | 43 | | |
| |||
415 | 421 | | |
416 | 422 | | |
417 | 423 | | |
418 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
419 | 427 | | |
420 | 428 | | |
421 | 429 | | |
| |||
431 | 439 | | |
432 | 440 | | |
433 | 441 | | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
434 | 449 | | |
435 | 450 | | |
436 | 451 | | |
| |||
442 | 457 | | |
443 | 458 | | |
444 | 459 | | |
445 | | - | |
| 460 | + | |
446 | 461 | | |
447 | 462 | | |
448 | 463 | | |
| |||
457 | 472 | | |
458 | 473 | | |
459 | 474 | | |
460 | | - | |
| 475 | + | |
461 | 476 | | |
462 | 477 | | |
463 | 478 | | |
464 | 479 | | |
465 | 480 | | |
466 | | - | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
467 | 495 | | |
468 | 496 | | |
469 | 497 | | |
| |||
479 | 507 | | |
480 | 508 | | |
481 | 509 | | |
482 | | - | |
483 | | - | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
484 | 525 | | |
485 | | - | |
| 526 | + | |
| 527 | + | |
486 | 528 | | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
487 | 535 | | |
488 | 536 | | |
| 537 | + | |
| 538 | + | |
489 | 539 | | |
490 | 540 | | |
491 | 541 | | |
492 | 542 | | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
493 | 574 | | |
494 | 575 | | |
495 | 576 | | |
496 | 577 | | |
497 | 578 | | |
498 | 579 | | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
499 | 583 | | |
500 | 584 | | |
501 | 585 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
0 commit comments