Skip to content

feature:Implement analytics metrics retention policy and purge cron#516

Open
Emmanuelluxury wants to merge 1 commit intoStellerCraft:mainfrom
Emmanuelluxury:craft497
Open

feature:Implement analytics metrics retention policy and purge cron#516
Emmanuelluxury wants to merge 1 commit intoStellerCraft:mainfrom
Emmanuelluxury:craft497

Conversation

@Emmanuelluxury
Copy link
Copy Markdown

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

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 29, 2026

@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! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement analytics metrics retention policy and purge cron

1 participant