Add cooldown after metrics upload failure to prevent memory spikes#1700
Open
Siddhant-K-code wants to merge 4 commits into
Open
Add cooldown after metrics upload failure to prevent memory spikes#1700Siddhant-K-code wants to merge 4 commits into
Siddhant-K-code wants to merge 4 commits into
Conversation
When metrics delivery fails (e.g., unreachable server, non-prod URL), the flush loop previously kept attempting uploads every 3s, each blocking for up to 30s on HTTP timeout while holding ~300MB of deserialized event data in memory. This adds a 5-minute cooldown after a delivery failure: - METRICS_UPLOAD_LAST_FAILURE_AT tracks the last failure timestamp - During cooldown, flush_pending_metrics and flush_metrics skip upload attempts entirely (events are still persisted to SQLite) - METRICS_UPLOAD_AVAILABLE is set to false during cooldown so the stream worker backpressure check doesn't count pending DB rows that can't be drained anyway - After cooldown expires, a single retry determines if the server is back; on success the failure state is cleared Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Collaborator
Author
|
With this^, it starts with ~300MB, and gradually slows down to ~20 MB or so in 10-15s |
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.
Summary
When metrics delivery fails (unreachable server, non-prod URL configured), the flush loop was attempting uploads every 3s — each blocking up to 30s on HTTP timeout while holding ~300MB of deserialized event data (
Vec<MetricRecord>+Vec<MetricEvent>+ serialized JSON POST body) in memory. WithMETRICS_UPLOAD_AVAILABLEstayingtrue, the stream worker's backpressure also counted undrainable pending DB rows, defeating the throttle.This adds a 5-minute cooldown (
METRICS_UPLOAD_LAST_FAILURE_AT) after delivery failure:Both
flush_metrics(buffer-driven path) andflush_pending_metrics(periodic drain path) respect the cooldown. On successful delivery after cooldown expires, the failure state is cleared. Row-level retry (mark_records_failedwith exponential backoff) still handles eventual delivery once the server is reachable again.