Repository navigation
feat(cleanup,reaper): delete undrained pools' SQS queues and staged specs (#1351) - #1361
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…pecs (#1351) pkg/poolqueue holds the one rule, shared by `spawn cleanup --pool-queues` and the TTL reaper (REAPER_POOL_QUEUES / PoolQueues / POOL_QUEUES / spawn reaper deploy --pool-queues; off|report|reap, default report). A spawn-pool-<run id> queue goes only when it is tagged spawn:managed=true with a matching spawn:pool-run-id, no live instance in any enabled region holds the pool's worker profile or tag, both message counts are 0, and it is at least 24h old. A run's specs under staging/pool-specs/<run id>/ in the results bucket go once its queue is gone, no instance is the pool's, and the newest is 24h old. An unreadable region means nothing is deleted. pkg/taskpool.CreateQueue now creates the queue tagged; without sqs:TagQueue it falls back to an untagged queue and pool create warns. Untagged (pre-v0.147.0) queues are kept. IAM in pkg/reaperiam, the SAM ScanSelf branch and the member role: sqs:ListQueues on *, the reads and DeleteQueue on spawn-pool-*, s3:DeleteObject on spawn-results-*/staging/pool-specs/* only. Fixes #1351
scttfrdmn
force-pushed
the
fix/1351-pool-queue-deleter
branch
from
October 27, 2026 04:47
7184eec to
0ab5d85
Compare
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.
Fixes #1351
Before this, only
spawn pool draindeleted a pool's SQS queue, and nothing deleted the specsspawn pool submitstages. This PR gives both a deleter. It follows the #1300 (pkg/instancerole) and #1301 (pkg/bucketsweep) pattern: one shared package,pkg/poolqueue, holds the rule, and bothspawn cleanup --pool-queuesand the TTL reaper (REAPER_POOL_QUEUES) use it.Tagging facts
pkg/taskpool.CreateQueuecreatedspawn-pool-<run id>with NO tags. Only the pool's role, profile and workers carriedspawn:pool-run-id.Tags: {spawn:managed=true, spawn:pool-run-id=<run id>}. Tagging on create needssqs:TagQueue. On AccessDenied, CreateQueue retries without tags,Queue.TagErr()reports why, andpool createwarns that onlypool drainwill delete that queue.spawn-pool-*queue cannot be told apart from someone else's queue with that name, so it is reported and kept.spawn pool drain --run-id <id>deletes one. Its specs are kept too, because its queue still exists.pool submitstagesstaging/pool-specs/<run id>/<task>.jsoninspawn-results-<acct>-<region>, which has no lifecycle rule, andpool drainnever removed those objects.SpecStorenow builds keys withpoolqueue.SpecKey, so the prefix written and the prefix swept come from one definition.The rule (
poolqueue.Decide)A queue is deleted only when all of these hold:
spawn-pool-<id>, is taggedspawn:managed=true, and itsspawn:pool-run-idtag equals<id>;spawn-instance-pool-<hash>, or the pre-v0.147spawn-pool-worker-<hash>) or carries itsspawn:pool-run-idtag;ApproximateNumberOfMessagesandApproximateNumberOfMessagesNotVisibleare both 0. An unreadable count counts as not zero....Delayedis also counted when SQS returns it;CreatedTimestampis at least 24 hours old.A run's specs are deleted when its queue is gone (already, or in this sweep), no instance belongs to the pool, and the newest spec is at least 24 hours old. Every S3 call names the account as
ExpectedBucketOwner. In report mode, a queue that reap would delete counts as gone, so report and reap give the same answer. If any region cannot be read, nothing is deleted.Reaper mode switch
REAPER_POOL_QUEUES/ templatePoolQueues/make deploy POOL_QUEUES=/spawn reaper deploy --pool-queuestakeoff|report|reap. The default isreport: it logs and changes nothing, asREAPER_INSTANCE_ROLESandREAPER_EMPTY_BUCKETSdo, so an upgrade deletes nothing on its own. A deploy that does not name the setting keeps the deployed value (TestPoolQueuesSurvivesAMakeDeploy,TestEveryReaperSettingSurvivesARedeploy). The setting is wired into the MakefilePARAM_MAPand awk echo list, theTestPlainDeployEmitsNoModeSettingParameterkey list, reaperconfigValidate/Settable, and the reaperdeploy settings test. The sweep runs once per account after the regional scans. Its summary counters arepool_queues_*,pool_specs_*andpool_queues_accounts_denied.IAM
The same grants are in all three copies (pkg/reaperiam
ScanSelfStatements, the SAM ScanSelf branch, and the member role):sqs:ListQueueson*(it has no resource ARN);sqs:GetQueueAttributes,sqs:ListQueueTags,sqs:DeleteQueueonarn:aws:sqs:*:<acct>:spawn-pool-*;s3:DeleteObjectonarn:aws:s3:::spawn-results-*/staging/pool-specs/*. Listing uses the existing results-buckets3:ListBucket.DeleteQueue is scoped by name and not by tag. That follows the
fsx:DeleteFileSystemprecedent: nobody has proven against a live account that SQS populatesaws:ResourceTagfor DeleteQueue, and an unproven condition fails closed without any error. The code's tag check is the guard.The CLI inventory is regenerated (
spawn cleanupgainssqs:ListQueues,sqs:ListQueueTags,sqs:GetQueueAttributes,sqs:DeleteQueueands3:DeleteObject). Its "implied permissions" note now namessqs:TagQueueforpool create.Gates (each watched failing against a revert that compiles)
Delete=falseREAPER_REGIONSfor workersbusy), FailsClosed, ModesoffreapPoolQueues:POOL_QUEUESremoved fromPARAM_MAPsqs:ListQueueTagsdropped from reaperiam*spawn-results-*/*sqs:ListQueueTagsdropped from the member roleCLI and reaper agreement:
pkg/poolqueue/poolqueuetestis one account scenario. It holds an abandoned queue, a queue whose only worker is in an enabled region outside the scanned ones, one holding a message, a young one, an untagged one, one tagged for another run, and the specs of an abandoned run and of a drained run.cmd.TestCleanupPoolQueuesand the reaper'sTestPoolQueueSweepAgreesWithTheCLIboth require it to produce exactlyWantDeletedQueues/WantDeletedSpecRuns.Substrate:
TestCreatedQueueIsSweptAgainstSubstratechecks that the tags CreateQueue writes come back through ListQueueTags, and exercises ListQueues and DeleteQueue against a real implementation. Substrate does not model theApproximateNumberOfMessages*counts at all (filed as scttfrdmn/substrate#1441). The test therefore asserts that, against Substrate as-is, nothing tagged is deleted because the counts are unread. It then supplies zero counts and asserts that the abandoned queue goes and the untagged one stays. The case "a queue holding messages is kept" is covered by the fake tests only.Checks
make checkpasses steps 1–6 (gofmt, vet, every GOOS, staticcheck, golangci-lint, hermetic short tests, nested modules, tidy). Step 7,check-build-tags, fails from/tmp, which is the known path issue on this machine, and passes when run from/private/tmp/spawn-1351.make lint: 0 issues in all 10 modules.semgrep scan --config=auto --error .is clean.make gen-docsandmake check-docsare clean.make api-snapshotadds one line,func (*Queue) TagErr() error. Nothing is removed.Live deploy steps (not done; no AWS calls were made)
deployment/cloudformation/ttl-reaper-cross-account-role.yamlin every account the reaper assumes into (spore-host-dev 435415984226 and any other entry inREAPER_ROLE_ARNS). Snapshot the stack parameters before the deploy and diff them after, expecting no drift. Until a role is redeployed, the account is counted inpool_queues_accounts_denied.spawn-ttl-reaper-productionwithmake deployfromlambda/ttl-reaper, without namingPOOL_QUEUES, so the stack picks up the template defaultreport. Snapshot the parameters first and confirm afterwards that every other parameter is unchanged. A self-hosted reaper picks this up withspawn reaper deploy, and the scan-self policy comes from reaperiam.iam simulate-principal-policy, both allow and deny:sqs:DeleteQueueonspawn-pool-xallowed and onother-queuedenied;s3:DeleteObjectonspawn-results-<acct>-<region>/staging/pool-specs/r/t.jsonallowed and on.../tasks/xdenied.WOULD delete pool queuelines from a report run. Arm withmake deploy POOL_QUEUES=reaponly after that.CreateQueuenames an existing queue, i.e. a reused run id, and theAccessDeniedcode SQS returns for a missingsqs:TagQueue.