Disable a log destination after repeated consecutive emit failures - #21
Merged
Conversation
Emission is synchronous on the caller's request path, and a destination whose credential exchange fails after long internal retries previously charged that cost to every request forever (policyengine-uk-chat#142 outage: a WIF attribute-mapping error turned every log write into ~25s of failing STS retries). After DESTINATION_FAILURE_LIMIT consecutive failures a destination is now disabled for the process, with an internal record emitted; if no destination remains, stdout is restored so logs keep flowing. Success resets the counter. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2 tasks
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.
What
Adds a per-destination circuit breaker to
LogDestinationManager.emit: afterDESTINATION_FAILURE_LIMIT(3) consecutive emit failures, the destination is disabled for the rest of the process, with alogging.destination_disabledinternal record. A successful emit resets the counter. If the last destination is disabled, a stdout destination is restored so logs keep flowing.Why
Emission is synchronous on the caller's request path. In the PolicyEngine/policyengine-uk-chat#142 outage, a WIF attribute-mapping error (
google.subject> 127 bytes) made the Google Cloud Logging destination's credential exchange fail after ~25 seconds of internal google-auth/gRPC retries — per log write, on every request, forever, taking the service down. Creation-time failures already fall back to stdout; this closes the same hole for emit-time failures. An observability sink must never be able to degrade its host service.The breaker deliberately trips on consecutive failures only, so a transient GCL blip doesn't permanently disable the destination; a tripped destination returns naturally with the next container.
Not included (follow-up candidate)
The materialized WIF token file is written once at credential creation and never refreshed. Modal identity tokens live 48h (measured), so this only affects containers outliving that window — with this breaker the failure mode degrades to lost logs plus internal records rather than an outage. Worth a follow-up (re-materialize on refresh or a subject-token supplier).
Verification
Full suite: 126 passed (3 new circuit-breaker tests: disable-after-consecutive-failures with a healthy destination unaffected, success-resets-counter, sole-destination-falls-back-to-stdout).
🤖 Generated with Claude Code