feat(revenue-recovery): Add retry stats migration API - #13908
Open
AnuthaDev wants to merge 1 commit into
Open
Conversation
Changed Files
|
Contributor
|
[should-fix] Please reject duplicate [should-fix] Please make the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Description
Adds an admin-only migration API to backfill the revenue_recovery_retry_stats table from historical payment/billing data, so the revenue-recovery retry decider has informed statistics from day one instead of starting from an empty table.
Endpoint: POST /v2/recovery/data-backfill/retry-stats (multipart CSV, field file), authenticated with the existing V2AdminApiAuth, v2-gated.
Design:
Supporting refactors (behavior of the live recording path is unchanged):
Additional Changes
Adds a new endpoint (admin-only): crates/router/src/routes/app.rs, crates/router/src/routes/revenue_recovery_data_backfill.rs; request/response types in crates/api_models/src/revenue_recovery_data_backfill.rs. The revenue_recovery_retry_stats table already exists (v2_compatible_migrations/2026-08-13-000001) and is not modified; no config changes (reuses AdminApiKey auth and existing revenue_recovery.retry_stats_lock settings).
Motivation and Context
Retry-decision quality for revenue recovery depends on retry-outcome statistics aggregated per cluster key (standardised error code) and time slot (docs/revenue-recovery-data-model.md). A fresh deployment records these only from live webhook ingestion, so the decider has no evidence for weeks. Merchants/ops already hold historical billing exports (e.g., Chargebee/Stripe transaction CSVs); preprocessing them with scripts/generate_retry_stats_sql.py produces the same document shape the live recorder writes. This API provides the safe load path for those precomputed documents.
How did you test it?
Manually, on a local app with --features v2:
Checklist