Repository navigation
fix(spored,reaper): make the task terminal flush visible, retried and covered by the reaper (#1186) - #1294
Merged
Conversation
… covered by the reaper (#1186) spored: every flush outcome is logged in full and recorded in a spawn:flush-status tag; a failure or skip (missing hook on a task instance, refused hook, timeout, failed uploads, other non-zero exit) also goes to the serial console with the hook output and command-log tail, and is sent as a pre_stop_failed notification. The hook's output pipes are bounded with exec.Cmd.WaitDelay. Flush hook: each upload is retried (3 attempts, backoff, 25 s budget, connect/read timeouts), the aws error is printed on final failure, the record still uploads when command.log fails, and the hook exits 3 when an upload did not land. A wrapper record that exists locally but not in S3 is uploaded instead of ending the hook (an incomplete local copy is not). Reaper: REAPER_TTL_GRACE (default 10m, 0..1h) leaves a running instance with a fresh heartbeat for spored past its deadline; threaded through the template, Makefile PARAM_MAP and spawn reaper deploy --ttl-grace with deployed-value preservation. Task instances get the flush hook run over SSM (taskproto.FlushCommand, shared with spawn terminate) before the terminate. Fixes #1186
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Merged
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 #1186
The TTL-killed task in #1186 left an empty results prefix and no trace of why: the flush hook's output and status went only to spored's journal, which goes with the instance. This makes every flush outcome survive the instance, makes the hook retry, closes an interlock hole, bounds the hook's pipes, and has the reaper wait for a live spored and run the flush itself when it does terminate a task.
spored (pkg/agent)
spawn:flush-statustag:ok,failed:{hook-refused,timeout,upload-failed,exit-N,start-failed,killed}, orskipped:hook-missing(only reported on a task instance, meaningspawn:task-idis set; a plain launch stays silent).=== task flush report: … ===) with the reason and the hook's output goes to/dev/console, followed by the command-log tail (writeCommandLogToConsole). A notification is also sent. It goes out aspre_stop_failedwith detailtask flush <status> — <output tail>, not as a new event:TestSporedNotifyEventsHandledBySporeBotonly allows events spore-bot formats, and a new one would need a spore-host change first.exec.Cmd.WaitDelay(5 s) on the hook, so anawschild it leaves holding the pipe can't stall termination past the 45 s cap.Flush hook (pkg/taskproto/flush.go)
spawn_upretries each upload: 3 attempts, 1 s/2 s backoff, no new attempt after 25 s, plus--cli-connect-timeout 5 --cli-read-timeout 15. On the last failure it prints the aws error text. A stdin upload is buffered first, so a retry doesn't send an empty body.completion.jsonand.exitcodestill upload whencommand.logfails. The hook exitsFlushExitUploadFailed(3) if any upload didn't land.head-objectcan't find it in S3, the hook now uploads the wrapper's own record (plus the log and.exitcode) instead of exiting 0. It never writes its own record in that case, and it won't upload a local copy that doesn't end in}(the A task that fills /tmp uploads a 0-byte completion.json and .exitcode; status then fails 'unexpected end of JSON input' and --wait never returns #1179 full-/tmp case). Note: task roles have onlys3:PutObjecton the results bucket, sohead-objectnormally gets a 403, and the hook re-uploads the wrapper's identical bytes.writeRecordFilegains anonFailargument (the wrapper passestrue, which is unchanged) because a piped upload runs in a subshell.Reaper (lambda/ttl-reaper)
REAPER_TTL_GRACE(default 10m,0–1h,0= old behaviour): a running instance with a freshspawn:last-heartbeatisn't reaped until the grace after its deadline. This covers bothspawn:ttl-deadlineand the launch-time+ttl fallback. A stale or missing heartbeat, or a stopped instance, is reaped at the deadline, and max-age still applies. It's capped because the heartbeat tag is instance-writable.TtlGrace(default''), MakefilePARAM_MAP/ echo list (no?=default, so live values win),spawn reaper deploy --ttl-graceviareaperconfig.Settable, and the census tests.spawn:task-idinstance, the reaper runstaskproto.FlushCommand(ExitTTLExpired)over SSM, bounded at 60 s. This is the commandspawn terminatealready sent, now moved to taskproto and shared. It runs whateverREAPER_GRACEFULis set to.ssmFornow returns anssmAPIinterface so this can be tested.ssm:SendCommand(instance on thessm:resourceTag/spawn:managedrail, plusdocument/AWS-RunShellScript) andssm:GetCommandInvocationare already in the SAM template's ScanSelf branch, the cross-account role andpkg/reaperiam.Sizes
For a trivial spec, the flush hook (embedded in task user data) grows from 1,070 to 1,538 bytes gzipped. The wrapper is unchanged (1,760 to 1,762, which is just temp-path noise). The user-data budget tests in pkg/launcher and pkg/tasklaunch pass.
Gates, each watched failing against a revert that compiles
reportFlushOutcomereturning early failsTestFlushOutcomeIsVisibleAfterTermination(all 4 cases),TestFlushSuccessIsTaggedQuietlyand the Monitor test.flushUploadAttempts = 1failsTestFlushHookRetriesAFailedUpload.TestFlushHookReportsAPersistentUploadFailure. Making a failed uploadexit 3immediately fails it too (the record wasn't uploaded after the log failed).exit 0failsTestFlushHookUploadsALocalOnlyRecord. Removing the}guard failsTestFlushHookDoesNotUploadATruncatedLocalRecord._ = a.flushWaitDelay()in place ofcmd.WaitDelay = …,TestFlushHookOutputPipeIsBoundedfails. It passes when flushTaskRecord returns while the hook's child is still alive; there's no wall-clock bound on the pass path.a.flushTaskRecord(why)fromrunPreStopfailsTestMonitorTTLExpiryRunsTheFlushHookBeforeTerminate. The provider's Terminate records what the hook had done by then.TestTTLGraceOnlyForARunningInstanceWhoseSporedIsAlive.TestReaperFlushesOnlyTaskInstancesBeforeTerminating.TtlGrace:TTL_GRACEfromPARAM_MAPfailsTestEveryTemplateParameterIsInThePARAMMAPandTestTtlGraceSurvivesAMakeDeploy. A typo in the env read failsTestTemplateEnvironmentIsReadByTheReaper. Dropping it fromreaperconfig.settablefailsTestReaperDeployFlagsBecomeSettingsandTestEveryReaperSettingSurvivesARedeploy.Checks
make checkpasses every step except check-build-tags, which fails the same way on unmodified main (the /private/tmp paths). golangci-lint reports 0 issues in all 10 modules.make check-docsandsemgrep scan --config=auto --error .find nothing (0 findings).make api-snapshot: additions only (FlushCommand,FlushHookSeconds,FlushExitUploadFailed).No deploy, no AWS calls. The reaper change needs a redeploy; the SSM grants are already in place but should be IAM-simulated at deploy.