Skip to content

Conversation

hoytak
Copy link
Collaborator

@hoytak hoytak commented Jun 26, 2025

This PR consolidates the retry logic for the http connections around a single utility, RetryWrapper, and integrates it more cleanly with the logging and parsing logic. The goal is to replace the retry middleware with this, which doesn't work with streaming connections.

This PR introduces this and replaces the simpler connection paths in RemoteClient with this wrapper but leaves the previous logic intact. The next step is to fully switch the remaining cases over to this wrapper to clean up the code.

@hoytak hoytak requested review from assafvayner and jgodlew June 26, 2025 00:12
@@ -34,10 +34,10 @@ use utils::singleflight::Group;
use crate::download_utils::*;
use crate::error::{CasClientError, Result};
use crate::http_client::{Api, ResponseErrorLogger, RetryConfig};
use crate::interface::*;
use crate::interface::{ShardDedupProber, *};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an odd import? is ShardDedupProber not part of "*"?

if !response.status().is_success() {
let response = RetryWrapper::new(api_tag)
.with_429_no_retry()
.log_errors_as_info()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this an override over the default log level? what is the default/is there a default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default log level is to log fatal errors as errors, i.e. the connection couldn't be completed either due to non-transient errors or running out of retries. The current logging -- prior to this PR -- is done with a log_error after the send, which isn't as consistent as it doesn't include a lot of the context, just the error.

Comment on lines +71 to +75
if self.log_errors_as_info || log_as_info {
info!("{msg}");
} else {
error!("{msg}");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead can we hold a tracing::Level, default it to tracing::Level::ERROR and emit event! here? if you want to override it by passing in log_as_info, then pass in an Option<tracing::Level>?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather have formally more control, even if we use the same settings everywhere. Fine if you really prefer to not expose that option.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the need for that extra control here? I'm wondering what scenarios would benefit from it. Currently, each of the calls does a log_error call except the global dedup query, which swallows any errors; this reflects that behavior.

Also, this logs retries as info, and the error is for fatal errors.

Comment on lines +163 to +166
ReqFn: Fn() -> ReqFut + Send + 'static,
ReqFut: std::future::Future<Output = Result<Response, reqwest_middleware::Error>> + 'static,
ProcFn: Fn(Response) -> ProcFut + Send + 'static,
ProcFut: std::future::Future<Output = Result<T, RetryableReqwestError>> + 'static,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add comments on these types, they are quite long/complex-looking, they aren't too complex, but it's a minor chore to read. similar in run_and_extract_json

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, happy to.

@hoytak hoytak requested a review from seanses June 30, 2025 19:05
Copy link
Contributor

@jgodlew jgodlew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks good!

@hoytak hoytak merged commit 642e8b7 into main Jul 1, 2025
5 checks passed
@hoytak hoytak deleted the hoytak/250612-retry-wrapper branch July 1, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants