feature:Implement analytics metrics retention policy and purge cron#516
Open
Emmanuelluxury wants to merge 1 commit intoStellerCraft:mainfrom
Open
feature:Implement analytics metrics retention policy and purge cron#516Emmanuelluxury wants to merge 1 commit intoStellerCraft:mainfrom
Emmanuelluxury wants to merge 1 commit intoStellerCraft:mainfrom
Conversation
|
@Emmanuelluxury Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
closes #497
Description
MetricsCollectionService.applyRetentionPolicy is tested in apps/backend/tests/metrics/collection.test.ts but no cron job calls it. The deployment_analytics table will grow unbounded in production, degrading query performance over time.
Requirements and context
Must be secure, tested, and documented where applicable
Should stay reviewable and fit the current monorepo structure
Relevant files: apps/backend/tests/metrics/collection.test.ts, apps/backend/src/services/analytics.service.ts, apps/backend/src/app/api/cron/
Suggested execution
Create branch: issue-023-analytics-retention-policy-cron
Keep changes scoped to the issue and reference the task IDs in the PR
Implement changes
Add applyRetentionPolicy(retentionDays) to AnalyticsService that deletes records older than the threshold
Create apps/backend/src/app/api/cron/purge-analytics/route.ts calling the service
Default retention: 90 days; configurable via ANALYTICS_RETENTION_DAYS env var
Register in vercel.json crons (daily schedule)
Test and commit
Add cron route tests: records within retention kept, records outside deleted, env var override respected
Verify the cron returns { deleted: N } in the response body
Edge case: retention days set to 0 — treat as disabled, delete nothing
Example commit message
feat(cron): add daily analytics retention purge job
Guidelines
Prefer small, reviewable PRs
Keep naming and data contracts consistent with the spec docs