Repository navigation
feat(reaper): report when spored has stopped checking in (#682) - #729
Merged
Merged
Conversation
A running instance whose agent has died enforces none of its own limits — TTL, idle-stop and cost all live IN the instance — so the reaper's deadline scan becomes the only thing that will ever stop it. That condition was invisible: "spored is dead" looked exactly like "the job is still running". No new producer and no new storage: spored has written spawn:last-heartbeat every tick since #497, described there as "an always-on liveness signal a caller can poll", and a search of the tree found ZERO consumers. The gap was a reader, so this adds one. - classifyHeartbeat: fresh / stale / unknown. A missing tag is UNKNOWN, not stale — pre-first-tick, or an instance with no agent at all such as a detached sweep row (#725). An unparseable stamp is also unknown: that is evidence of a format change, and calling it a death would cry wolf every cycle until someone found the real cause. - noteHeartbeat: counts all three states into the run Summary; a stale one logs the SPORED NOT CHECKING IN sentinel with instance, account, region and lapse. Only RUNNING spawn-managed instances are considered. - template.yaml: metric filter + alarm, 3 consecutive hourly runs so one lost tag write pages nobody. Deliberately NOT a reap trigger. A stale heartbeat is a diagnosis, not a deadline; spawn:ttl-deadline and the max-age ceiling stay the only authorities. Terminating on a missed tick would destroy the work of a box whose agent is merely wedged. Also makes the sentinel/template contract real: a test now requires every sentinel to have a matching FilterPattern. A sentinel wired to nothing is indistinguishable from no sentinel — the same defect as the tag itself. Gates confirmed to fail on revert: missing-tag-as-stale, the running-state guard, the clock-skew age guard, and the metric-filter contract. cfn-lint caught the AlarmDescription exceeding CloudFormation's 1024-char limit.
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.
Addresses the remaining half of #682 — but not the way we agreed, and the
reason matters more than the code.
The premise changed
The plan was to have spored write a heartbeat into DynamoDB. While implementing
the producer I found there already is one: spored has written the
spawn:last-heartbeatEC2 tag unconditionally on every tick since #497(
pkg/agent/agent.go:434), described in that issue as "an always-on livenesssignal a caller can poll". A search of the whole suite for consumers found
zero — the only other hit was an unrelated
LastHeartbeatdynamodbav fieldin
pkg/autoscaler/drain.go.So #682's gap is a reader, not a writer. A table would have added IAM grants
on every launch role and a per-instance write cost to carry data a free tag
already carries. Neither of us knew that when DynamoDB was chosen.
What a table would have bought is history — "when did it stop", trend across
runs, and a record that survives termination. The tag only answers "is it
ticking now", and dies with the box. Put to the maintainer with that trade-off
stated; the call was no table, the tag is enough, so this closes #682 and the
DynamoDB plan is dropped rather than deferred.
Closes #682.
What this does
A running instance whose agent has died enforces none of its own limits —
TTL, idle-stop and cost are all applied in the instance — so the reaper's
deadline scan becomes the only thing that will ever stop it. That condition was
invisible: "spored is dead" looked exactly like "the job is still running". The
reported case was a 0.5 GiB instance wedged during a package install, still
billing at twice its 6-minute TTL with no completion record and no signal of
any kind, until a human noticed.
classifyHeartbeat— fresh / stale / unknown, 10 minutes (ten missedrefreshes at the throttled 1/min rate).
noteHeartbeat— counts all three into the runSummary; a stale one logsthe
SPORED NOT CHECKING INsentinel with instance, account, region andlapse. Only RUNNING
spawn:managedinstances are considered.template.yaml— metric filter + alarm, three consecutive hourly runs, soone lost tag write or a throttled
TagResourcespages nobody.Three judgement calls
A missing tag is
unknown, notstale. Either spored has not finished itsfirst tick, or the instance was launched by something that installs no agent at
all — a detached sweep row (#725) is exactly that. A missing signal and a lapsed
one mean different things and only one is a symptom.
An unparseable stamp is also
unknown. That is evidence of a format change,not a dead agent; reporting it as a death would cry wolf every cycle until
someone found the real cause.
It is deliberately NOT a reap trigger. A stale heartbeat is a diagnosis, not
a deadline.
spawn:ttl-deadlineand the max-age ceiling stay the onlyauthorities — an agent wedged while its workload runs fine would otherwise have
its work destroyed to tidy a symptom. v0.121.0's memory-floor warning is the
preventive half of #682; this is the part that makes it observable when the
instance gets starved anyway.
The same defect, one level up
TestSentinelSpellingsAreStablepinned the sentinel strings but never checkedthe template actually matched them. A sentinel wired to nothing is
indistinguishable from no sentinel — which is precisely the heartbeat tag's
own defect.
TestEverySentinelHasAMetricFilternow readstemplate.yamlandrequires a literal
FilterPatternfor each of the four, matching the quotedCloudWatch form so a mention in a comment or an
AlarmDescriptioncannotsatisfy it.
Verification
Four gates, each confirmed to fail when reverted:
staleTestClassifyHeartbeat(2 cases) +TestNoteHeartbeatCountsHeartbeatStale = 2, want 1— a stopped box would read as a dead agentage = -5m0s, want >= 0FilterPatternTestEverySentinelHasAMetricFilterThe skew guard initially passed on revert — the returned state was unaffected,
so only the negative duration was observable. The test now asserts the age, so
the guard is actually covered rather than nominally.
cfn-lintcaught theAlarmDescriptionexceeding CloudFormation's 1024-charlimit;
sam validatealone did not.Gates:
gofmt,go vet,go test ./...(reaper + root),go test -short ./...,make check-docs,cfn-lint template.yaml,semgrep scan --config=auto --error(0 findings — re-run after staging, since semgrep only scans git-tracked files).
No deploy yet. The alarm needs a reaper redeploy to exist, which is the same
redeploy #685 needs.
Opened against #727's branch and auto-closed when that merged and the branch was
deleted; this is the same commit, rebased onto
main. Supersedes #728.