-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(aws_s3 source): add retry delay in sqs::Ingestor #22999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
use std::collections::HashMap; | ||
use std::time::Duration; | ||
use std::{future::ready, num::NonZeroUsize, panic, sync::Arc, sync::LazyLock}; | ||
|
||
use aws_sdk_s3::operation::get_object::GetObjectError; | ||
|
@@ -401,27 +402,37 @@ impl IngestorProcess { | |
async fn run(mut self) { | ||
let shutdown = self.shutdown.clone().fuse(); | ||
pin!(shutdown); | ||
let delay = Duration::from_millis(500); | ||
|
||
loop { | ||
select! { | ||
_ = &mut shutdown => break, | ||
_ = self.run_once() => {}, | ||
result = self.run_once() => { | ||
match result { | ||
Ok(()) => {} | ||
Err(_) => { | ||
trace!("run_once failed, will retry after delay"); | ||
tokio::time::sleep(delay).await; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder how this constant was chosen. Would an exponential backoff strategy work better here or it's an overkill? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was treating this code as a hotfix rather than a long-term solution, so I chose a simple constant delay to quickly address the issue. The current 0.5-second delay doesn't introduce significant latency but greatly reduces the number of retries triggered by the source, which helps stabilize things short-term. That said, I agree a constant delay may not be ideal across all use cases - different values might work better for different users. An exponential backoff could offer a more flexible and resilient solution without needing to make the delay configurable. Happy to explore that in a follow-up PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see how this improves things in your situation but we generally don't want to merge hotfixes. If you have urgent need for this commit, you can always maintain a fork with this commit and use a custom Vector build. Going back to this PR, what do you think about introducing a new opt-in config parameter here? We can probably reuse Example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. I will check it. |
||
} | ||
} | ||
}, | ||
} | ||
} | ||
} | ||
|
||
async fn run_once(&mut self) { | ||
let messages = self.receive_messages().await; | ||
let messages = messages | ||
.inspect(|messages| { | ||
async fn run_once(&mut self) -> Result<(), ()> { | ||
let messages = match self.receive_messages().await { | ||
Ok(messages) => { | ||
emit!(SqsMessageReceiveSucceeded { | ||
count: messages.len(), | ||
}); | ||
}) | ||
.inspect_err(|err| { | ||
emit!(SqsMessageReceiveError { error: err }); | ||
}) | ||
.unwrap_or_default(); | ||
messages | ||
} | ||
Err(err) => { | ||
emit!(SqsMessageReceiveError { error: &err }); | ||
return Err(()); | ||
} | ||
}; | ||
|
||
let mut delete_entries = Vec::new(); | ||
let mut deferred_entries = Vec::new(); | ||
|
@@ -517,7 +528,7 @@ impl IngestorProcess { | |
message = "Deferred queue not configured, but received deferred entries.", | ||
internal_log_rate_limit = true | ||
); | ||
return; | ||
return Ok(()); | ||
}; | ||
let cloned_entries = deferred_entries.clone(); | ||
match self | ||
|
@@ -572,6 +583,7 @@ impl IngestorProcess { | |
} | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
async fn handle_sqs_message(&mut self, message: Message) -> Result<(), ProcessingError> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This could be a constant.