Repository navigation
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…er tag spawn:ttl without a deadline (#990) `spawn launch --ttl 1d` tagged spawn:ttl=1d with no spawn:ttl-deadline: buildTags wrote the deadline only when time.ParseDuration (no day unit) accepted the value, and spored parsed the tag the same way, so only the reaper's 7-day max-age ceiling bounded the instance. - pkg/ttl.ParseDuration is the one parser: Go durations plus days ("1d", "2d12h", "1.5d"), no signs, overflow checked. ParseTTL requires a positive value; TagValue stores day forms in Go form so older readers agree. pkg/config.ParseDurationE delegates to it. - buildTags returns an error instead of writing spawn:ttl without a deadline, and refuses unparseable idle/pre-stop/completion/webhook durations. LaunchConfig.ValidateDurations (new, public) runs first in Client.Launch and launcher.Provision, and before any AWS call in launch (flags and assembled config, wizard included), app, service, pool, extend, spored config set, defaults set, sweeps (CLI and the detached-sweep Lambda), task specs, batch queues and pipelines. - Readers use the same parser: spored's tag reader (pkg/provider), the TTL reaper (REAPER_MAX_AGE, pre-stop-timeout), status and estimates. - The reaper now enforces launch-time + spawn:ttl when there is no usable deadline tag, the deadline spored already synthesizes, so instances launched with a day-unit TTL before this fix are reaped on time even when stopped. spawn:ttl=0 (disabled) stays exempt. - The #983 writer gate now requires the deadline write on the same path (same block or an enclosing one) as each spawn:ttl write, and a pkg/aws test asserts every accepted TTL spelling (enumerated from ttl.Units()) yields a deadline. Both fail against the old conditional write. (#990)
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 #990. Stacked on #993. Merge #993 first; this PR's base is
fix/983.The bug
spawn launch --ttl 1dtaggedspawn:ttl=1dand nospawn:ttl-deadline.buildTagswrote the deadline only whentime.ParseDurationaccepted the value, and that parser has no day unit. spored readspawn:ttlthe same way, so the launch went ahead with nothing enforcing the TTL. Only the reaper's 7-day max-age ceiling bounded the instance.Decision: accept day units
Users type them, and
--fsx-ttl,extend's old regex andpkg/configalready accepted them. So every input and every reader now uses one parser.pkg/ttl.ParseDuration: Go durations plusd(1d,2d12h,1.5d,12h1d). It rejects signs, spaces, unknown units, empty input and overflow.ParseTTL: the same, but the value must be positive. A zero TTL puts the deadline at the launch instant, and a zero idle timeout means no idle timeout.TagValue: stores a day-unit value in Go form (1dbecomes24h0m0s). A reader still ontime.ParseDuration(an older spored,lambda/dashboard-api, another repo) then gets the same duration.Inputs (each rejected before any AWS call):
spawn launch:--ttl,--idle-timeout,--pre-stop-timeout,--completion-delay,--webhook-timeout,--fsx-ttl.runLaunchchecks them first, before its STS identity call and before the sweep/batch/wizard branches. The assembled config is checked again, which also covers~/.spawndefaults and the wizard, which now re-prompts.spawn extend(single instance and job array)spored config set ttl/idle-timeout/completion-delay, validated before the provider/IMDS callspawn defaults set idle-timeoutttl/idle_timeout, in the CLI and in the detached-sweep Lambda.ttl: 3600(a YAML int) is now an error instead of being silently dropped.spawn tasklifecycle.ttlspawn app/service/pool --ttlClient.Launchandlauncher.Provisioncall the new publicLaunchConfig.ValidateDurationsfirst. That is an addition to the API snapshot.Readers:
pkg/provider, nowconfigFromTagsso it is testable): ttl, idle, pre-stop, webhook and completion-delay tagsREAPER_MAX_AGE,REAPER_GRACEFUL_MAX_WAIT,pre-stop-timeoutspawn status, the launch, task and service cost estimates, the wizard estimateReaper agreement: when an instance has no usable
spawn:ttl-deadlinebut does have a positivespawn:ttl, the reaper now uses launch-time +spawn:ttlas the deadline. That is the deadline spored already synthesizes in that case (agent.NewAgent). Instances launched with--ttl 1dbefore this fix are therefore reaped on time, including stopped ones, which run no spored.spawn:ttl=0(config set ttl 0) stays exempt, and a valid deadline tag still wins.Refusal and the strengthened gate
buildTagsreturns([]Tag, error). It refuses an unparseable or zero TTL rather than writingspawn:ttlwithout a deadline, and it refuses unparseable idle, pre-stop, completion and webhook durations.TestEveryTTLTagWriterAlsoWritesTheDeadline(spawn extend --job-array-* writes only spawn:ttl, so it never moves the deadline spored and the reaper enforce #983) only checked that both keys appeared somewhere in the function. Now everyspawn:ttlwrite needs a deadline write in the same block or an enclosing one. The detector-shape test gains the spawn launch --ttl 1d writes spawn:ttl=1d with no spawn:ttl-deadline, so neither spored nor the reaper enforces the TTL #990 shape (deadline insideif err == nil), a sibling branch, a switch case, and the case where several writes are only partly covered.TestBuildTags_EveryAcceptedTTLFormYieldsADeadlinetakes every unit fromttl.Units()in integer and fractional form, plus the mixed forms. For each it asserts that a deadline equal to launch + the TTL exists, and thatspawn:ttlround-trips throughtime.ParseDuration.Test evidence (each new test watched failing against a revert that compiles)
buildTags: the AST gate fails onpkg/aws/tags.go buildTags.EveryAcceptedTTLFormYieldsADeadlinefails for3d,1.5d,2d12h,1d30m,12h1dand1d2h30m15s.RefusesATTLItCannotEnforcefails.Launch:TestLaunchRejectsAnUnparseableTTLBeforeAnyAWSCallfails because the call reaches STS.time.ParseDuration: the reaper tests fail both times, andTestParseMaxAgeAcceptsDaysfails on the second revert.extend, sweep and launch-config validation,configSetTag, the wizard,defaults set,taskprotoandqueuechanges one at a time: each one's test fails.make check: green apart from the known Docker-onlyTestGenerateWrapper_ChownFixesCrossUIDStickyUnlink_Docker.make check-nested: all 9 nested modules clean, ttl-reaper and sweep-orchestrator included.check-tidyis clean,golangci-lint --new-from-rev=HEADreports 0 issues, andsemgrep --config=autoon the changed files reports 0 findings.docs-genandapi/public-surface.txtare regenerated.Caveats
lambda/dashboard-api(a separate module with no spawn dependency) still readsspawn:ttlwithtime.ParseDuration. That is display only, and new tags are written in Go form.--launch-delay,--wait-timeout, plugin health interval, queue retry delays,pool --idle-timeout, which is aDurationVar) keep Go syntax. They are not lifecycle bounds.--ttl/--idle-timeoutat launch is now an error. Use--no-timeout.