Repository navigation
Conversation
This was referenced Oct 15, 2026
Merged
Make the stranded Spot replacement alarm actionable; record why the reaper cannot end it (#984)
#996
Merged
…#950) A persistent Spot request whose instance was terminated outside spawn reopens and makes EC2 launch an untagged replacement, invisible to spawn list and the reaper, and nothing cancelled it. TTL reaper: a new staged sweep (REAPER_SPOT_REQUESTS / SpotRequests, default report) describes spawn-tagged persistent requests and cancels those whose instance is gone, replaced (spawn:original-instance-id mismatch, or missing spawn:managed) or past its own deadline/max-age, then terminates a replacement after the cancel. It never cancels a live original's request on the request's stale ttl-deadline (spawn extend updates only the instance). An untagged replacement is outside the tag-scoped terminate grant, so it raises the alarmed SPOT REPLACEMENT NOT TERMINATED sentinel every run. A role lacking ec2:DescribeSpotInstanceRequests raises REAPER SPOT REQUESTS UNREACHABLE. That read-only grant is added to the scan-self policy, the SAM template and the cross-account role. Launch: persistent requests get ValidUntil = the TTL deadline (or launch + the 7-day ceiling) and spawn:spot-valid-until, and are tagged with spawn:original-instance-id after RunInstances. spawn extend warns past ValidUntil, and spawn start names an expired request as the likely cause. Also gates that every template parameter is referenced. (#950)
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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 #950
Stacked on #961 (base
fix/949), which is stacked on #951 (fix/922). Merge in that order.Do replacements inherit tags? (the issue's open question)
Not verified live, because the cost rules forbid launching anything. The evidence points to no.
RunInstances' instanceTagSpecificationsare applied when RunInstances runs. A Spot request'sLaunchSpecification, which is what EC2 relaunches from, has no tag field at all (checked in the SDK'stypes.LaunchSpecification). EC2's docs say a request's own tags are not copied to the instances it launches. So the sweep handles both cases:spawn:managed=true;spawn:original-instance-idtag, written right after RunInstances, names a different instance.What changes
TTL reaper sweep (
lambda/ttl-reaper/spotrequests.go). Per account and region, after the instance reaps, the sweep runsDescribeSpotInstanceRequestswith filterstag:spawn:managed=true,type=persistent,state=open|active|disabled|cancelled. It then runs a singleDescribeInstancesfiltered oninstance-id. It uses a filter, notInstanceIds, because one unknown ID fails the wholeInstanceIdscall.evaluate) → cancel (the instance scan terminates it)spawn:ttl-deadlineis past. That tag goes stale afterspawn extend, and cancelling would strand the instance at its next stop. This is a deliberate deviation from the issue's literal "cancel when the request's ttl-deadline is past", and there is a test for it.IAM, tag-scoped as asked. The only new grant is the read-only
ec2:DescribeSpotInstanceRequests, which has no resource-level ARN. Cancelling uses the #922 tag-conditionedec2:CancelSpotInstanceRequests, and terminating uses the existing tag-conditionedec2:TerminateInstances. As a result an untagged replacement cannot be terminated by the reaper. The sweep cancels its request so nothing more launches. Then it logs the alarmed sentinelSPOT REPLACEMENT NOT TERMINATEDwith the exactaws ec2 terminate-instancescommand, every run, until a person ends the instance (follow-up: #984). A role without the describe grant is reported once per account asREAPER SPOT REQUESTS UNREACHABLE(alarmed) and is not counted inErrors(#469). Both new sentinels have metric filters and alarms.Staged like
NetResources. The new parameter isSpotRequests/REAPER_SPOT_REQUESTS:report(default) logs and notifies what it would do,reapacts, andoffskips the sweep.DryRunalways wins. The parameter is added to the MakefilePARAM_MAP, the deploy echo, and the "plain deploy emits no mode parameter" gate.ValidUntil. A persistent request now gets
ValidUntilset to the TTL deadline (the same instant asspawn:ttl-deadline). With no TTL it is launch + 7 days, the reaper's default ceiling, kept in step withpkg/ttlby a test. The instance and the request carryspawn:spot-valid-until.spawn extend: EC2 has no API to move a request's end date. So extending past it prints a warning that once the request expires, a stop (the idle timeout,spawn stop, a Spot interruption) may not be restartable.spawn start: if EC2 refuses to start the instance after that point, the error names the expired request as the likely cause.New gate:
TestEveryTemplateParameterIsReferenced. Removing theREAPER_SPOT_REQUESTSenvironment line passed every existing test, because the parameter was still declared and mapped but never reached the function.Tests (each seen to fail against a revert that compiles)
spotrequests_test.gocovers 10 decision cases plus grace, filters, the instance-id filter vsInstanceIds, report/dry-run inertness, off, a failed cancel blocking the terminate, a stranded replacement reported on two consecutive runs, a failed lookup acting on nothing, and throughrun()the denied sentinel once per account and the sweep wiring.continue,recordSpot, therun()call, the lookup-failure guard, the expired-original branch,InstanceIdsinstead of the filter, and the stranded branch.pkg/reaperiamdrift gates fail when the grant is dropped from either the scan-self policy or the cross-account role.TestEverySentinelHasAMetricFilterfails when a filter is renamed.pkg/aws: ValidUntil equals the TTL deadline; without a TTL it is the 7-day ceiling; one-time requests send none; the persistent request is tagged withspawn:original-instance-id. Each fails against a revert.pkg/spotrequest:ExtendWarningandStartFailureNote.cmd:startFailedError.Commands, all run with AWS credentials stripped (see spawn#968):
make checkpasses except the known Docker-onlyTestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker.make check-nestedreports all 9 modules clean.lambda/ttl-reaperandlambda/dashboard-apigo test ./...pass.Deploy steps (NOT done)
spawn-ttl-reaper-ec2stack fromdeployment/cloudformation/ttl-reaper-cross-account-role.yaml. It addsec2:DescribeSpotInstanceRequests, and also carries Launch stoppable --spot as persistent Spot; cancel the request on every terminate (#922) #951'sec2:CancelSpotInstanceRequestsif that hasn't been applied yet. Done the other way round, the new Lambda raisesREAPER SPOT REQUESTS UNREACHABLEuntil the role catches up, which is harmless but noisy.cd lambda/ttl-reaper && make deploy ENV=productionwith no new variables.SpotRequestsarrives asreport, and every other parameter keeps its live value (lambda/ttl-reaper: 'make deploy' defaults would DISARM the live production reaper and silently drop its DNS/alarm config #650). Check the echoedSpotRequests reportandDryRun falselines.WOULD cancel orphaned spot requestlines andspot_requests_*in the run summary in/aws/lambda/spawn-ttl-reaper-productionacross a few runs (10-minute schedule). Confirm both new alarms exist:spawn-ttl-reaper-production-spot-requests-unreachableand-spot-replacement-stranded.make deploy ENV=production SPOT_REQUESTS=reap.spawn reaper deploy): re-run it to pick up the scan-self policy change. These reapers don't setREAPER_SPOT_REQUESTS, so they run the sweep inreport.ec2:CreateTags, and the request carriesspawn:managed=true.Caveats
ValidUntilstops relaunching but leaves a running instance alone; that a stopped Spot instance can't be started without an active request; that a cancelled request stays describable while its instance runs (needed to keep re-reporting a stranded replacement).spawn extendcall site of the new warning isn't covered by a test, becauserunExtendneeds AWS. Only the warning function is gated.spawn:original-instance-id. For those, a replacement that inherited tags would only be caught at its inherited deadline.spawn extend --job-array-*doesn't movespawn:ttl-deadlineat all (spawn extend --job-array-* writes only spawn:ttl, so it never moves the deadline spored and the reaper enforce #983), so it gets no ValidUntil warning.