Repository navigation
feat(deletes): deployment retention policy as a worker resource - #14685
Conversation
|
Review complete. 🟡 2 medium 💬 Inline comments (2)
🧹 Nitpicks (1) — 🟢 1 low
This PR introduces deployment retention: a new
Reviewed commit: ec6dd0d |
🟢 Tier S · Ready to mergeAdds a worker-scoped deployment retention policy that combines resource-requested age retention with policy defaults, maximum ages, and a finished-deployment count cap, while preserving active and manually kept deployments. It routes each disjoint retention pass through the delete worker seam, documents the updated meaning of a zero request, and adds library and maintenance coverage for retention behavior. Latest changes: The newest commits extract the count-lookup-failure database into its own test file and trim the retention unit suite to selected edge cases, removing the resolver matrix and several baseline pass tests.
📂 Walkthrough · 13
Reviewed the commits since |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
There was a problem hiding this comment.
Adds a deployment-retention subsystem with an enum of retention reasons and a scheduled Deletes worker pass that enqueues retention-based deployment deletions, plus unit tests.
Key findings
- 🟡 Overlapping retention passes double-enqueue deployments — Deletes.php:637
- 🟡
deploymentRetentionis never populated from configuration — message.php:211
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
ec6dd0d to
39f0cac
Compare
Deployment cleanup only honoured the per-resource deploymentRetention setting, so an operator had no way to set a default age, cap how long deployments are kept, or bound how many are kept per function or site. The policy is a Retention resource injected into the Deletes worker (default days, max days, max count; negative values are refused). The worker container registers all zeros, so self-hosted behaviour is unchanged: resources with no retention still return before the rules lookup, and a requested retention runs the same query as before. An integration that registers non-zero values gets the age default, the age cap and a count cap, and can override the protected retireDeployments seam per Reason. A clamped request runs as two passes so an override can tell the request apart from the policy, and the count pass skips rows past the age cutoff so no deployment is handed over for two reasons. The count cap finds the deployment at offset maxCount and retires that one and everything older by ($createdAt, $sequence), so the delete query never paginates with an offset. The cap counts finished deployments only, so queued builds cannot crowd out rollback targets, and a build in progress is never retired. A failed cutoff lookup is logged for that resource instead of aborting maintenance. The active deployment and deployments targeted by manual rules are always kept. The deploymentRetention param docs no longer promise that 0 keeps everything, since the server may apply a default.
Retention is decided by three passes (requested days, policy days, newest count) layered over the active and pinned deployments, and a wrong pass silently deletes builds a domain still serves. These tests drive the real maintenance message through the worker against in-memory platform and project databases, and assert both which deployment rows remain and which deployments were queued for storage cleanup, so a pass that deletes rows without queueing them, or queues without deleting, fails. A recording subclass of the worker stands in for an override that only logs the policy reason, and proves each deployment reaches the seam for one reason. Further cases pin that a function and a site sharing a sequence are retained apart, that builds in progress neither take a cap slot nor get retired, and that a failed cutoff lookup leaves other resources capped. The suite sets the encryption key the scheduler needs, so it runs without deprecations. The zero-policy cases stay green without the worker change, pinning that self-hosted behaviour is unchanged; the policy and count cases are red without it. The tie case fails if the count pass breaks a $createdAt tie in the wrong order.
39f0cac to
66c4ec2
Compare
When a resource requests more days than the policy maximum, the policy pass also selected every deployment the requested pass had, so an override that records reasons without deleting saw them twice. The policy pass is now bounded at the request cutoff. The pass queries move into Appwrite\Deployment\Retention so they are unit-tested as a library, as the test guidelines ask, instead of through Deletes::action(). The sites maintenance E2E now checks which deployments survive, not only how many.
Maintenance now applies whatever Retention::passes() yields, so the requested, policy and count passes share the worker call the sites maintenance E2E already exercises. A wiring regression for any pass breaks that loop, and the library tests cover what each pass selects, including the passes applied with deletions in between, as maintenance applies them. The count cutoff is looked up lazily after the age passes, as before, and a failed lookup or retire is logged per resource instead of aborting the remaining resources.
Default, clamp, count cap and kept deployments are covered by Cloud's retention e2e; the remaining cases need tied timestamps, builds in progress or a failing lookup.
Builds on #14663. Tracking appwrite-labs/cloud#6628 (section 2). Deployment cleanup takes a policy resource on top of each resource's
deploymentRetention. Self-hosted registers an all-zero policy, so its behaviour is unchanged; Cloud binds a plan-driven one (appwrite-labs/cloud#6680).A subclass can handle each
Reasondifferently (Cloud's shadow mode measures policy and count passes instead of retiring them). Because the passes are disjoint by construction, no deployment reaches the seam for two reasons. Builds in progress neither take a count slot nor get retired, so queued builds cannot crowd out rollback targets. A failure for one resource (e.g. the count cutoff lookup) is logged and maintenance carries on with the next resource.The
deploymentRetentionparam docs now say 0 keeps everything unless the server applies a default retention.Self-hosted impact
None in behaviour: with the all-zero policy only the requested pass runs, with the same query as before. Two operational differences: a failure while retiring one resource's deployments is logged instead of failing the maintenance job, and each retiring resource logs
Retiring deployments of {collection} {id} by requested retention.Tests
tests/unit/Deployment/RetentionTest.phpkeeps only the library edge cases no E2E can reach (workers are not unit-tested per AGENTS.md); default, clamp, count cap and kept deployments are covered by Cloud's retention E2E. On the Memory adapter:$createdAttie by insertion ordertests/unit/Platform/Workers/DeletesTest.phponly passes the newdeploymentRetentionargument.E2E:
SitesConsoleClientTest::testSiteDeploymentRetentionWithMaintenancenow asserts which deployments survive maintenance (the active one and the one inside the requested retention), not only the total. No E2E covers a non-zero policy: CE registers all zeros; Cloud's E2E (appwrite-labs/cloud#6680) exercises policy and count through this seam. The queries (or/andon$createdAt+$sequence,offset,equal('status'),greaterThanEqual('$createdAt')) are standard filters every adapter supports.