Repository navigation
feat(audit): retry, dead letters, and a file sink - #34
Merged
Merged
Conversation
Roadmap Horizon 1 item 4, less the otlp-logs sink, which brings a new
dependency and gets its own change.
Audit is fold's single exit door — one event per terminal response, denials
included — and it shipped as stdout or a webhook that tried once and gave up.
A receiver restarting for thirty seconds therefore cost every event in that
window, silently, which is the opposite of what an audit trail is for.
Delivery now retries with exponential backoff and equal jitter: four attempts
from 500ms to 30s by default, and on by default rather than opt-in, because
the previous behaviour was the defect and not a policy anyone had chosen. The
jitter matters at fleet scale — every instance watches the same receiver and
fails at the same instant, so unjittered retries turn a stumble into a
synchronised stampede against it as it recovers. Equal jitter rather than
full: full jitter around the delay overshoots the cap by half, which is a cap
that does not cap, and the test that asserts the bound is what caught it.
A 4xx other than 429 is permanent and not retried. A receiver that rejects the
payload will reject it identically four times; retrying only delays the dead
letter.
What delivery finally gives up on goes to deadLetterPath, one JSON event per
line, for replay. Without one, exhausted events are counted and gone — visible
rather than silent, which is the least the trail owes an operator.
The file sink lands as a destination in its own right and as the dead letter's
machinery: JSON lines, size-based rotation, renaming in place so a tail or a
log shipper watching the live name survives it, bounded at 100MB x 5 because
an audit sink that fills the disk turns a recording problem into an outage.
Hand-rolled rather than depended on: the requirement is "append lines, do not
fill the disk", and a library whose feature set is compression and cleanup
schedules is a larger surface than the problem. Directory 0o750, file 0o600 —
these records name principals and the tools they invoked.
fold_audit_events_total{sink,outcome} counts delivered, retried,
dead_lettered, and dropped, with the FoldAuditEventsLost alert on the latter
two, because the audit trail is the one system that cannot report its own
gaps. The observability pack's lockstep test refused the new metric until it
had a panel and an alert, which is exactly what it was built to do.
A sink that will not construct is logged and skipped rather than fatal: losing
one destination should not take the gateway down, and StartupErrors gives the
caller the words to say so.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
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.
Roadmap Horizon 1 item 4, less the
otlp-logssink — that brings a new dependency (the OTel logs SDK) and gets its own change, so this one stays reviewable.The problem
Audit is fold's single exit door — one event per terminal response, denials included — and it shipped as stdout or a webhook that tried once and gave up. A receiver restarting for thirty seconds cost every event in that window, silently. That is the opposite of what an audit trail is for.
Delivery
4xxother than429is permanent and not retried: a receiver that rejects the payload rejects it identically four times.Dead letters and the file sink
What delivery finally abandons goes to
deadLetterPath, one JSON event per line, for replay. Without one, exhausted events are counted and gone — visible rather than silent.The
filesink is both a destination and the dead letter's machinery: JSON lines, size-based rotation that renames in place so atail -For log shipper watching the live name survives it, bounded at 100 MB × 5 (an audit sink that fills the disk turns a recording problem into an outage). Hand-rolled rather than depended on — the requirement is "append lines, don't fill the disk", and a library whose feature set is compression and cleanup schedules is a bigger surface than the problem. Directory0o750, file0o600: these records name principals and the tools they invoked.Visibility
fold_audit_events_total{sink,outcome}countsdelivered/retried/dead_lettered/dropped, with aFoldAuditEventsLostalert on the last two — the audit trail is the one system that cannot report its own gaps.Notably, the observability pack's lockstep test refused the new metric until it had a panel and an alert. That is precisely what it was built to do, and it's the second time this session it's paid for itself.
A sink that won't construct is logged and skipped rather than fatal;
StartupErrors()gives the caller the words to say so.Verification
make checkgreen (lint 0 issues),make helm-checkgreen. Nine new tests covering recovery-after-failure, permanent-rejection, dead-letter contents, counted drops with no dead letter, file writing, rotation bounds and live-name preservation, unopenable sinks, and the backoff bound/jitter properties.Two gosec findings handled deliberately rather than uniformly:
G301tightened the directory to0o750(a fair catch),G404annotated with a reason (jitter spreads retries in time; it isn't generating a secret).🤖 Generated with Claude Code