-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add timeout and metrics on delta chunk sends. #73
base: main
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 |
---|---|---|
|
@@ -12,22 +12,28 @@ | |
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Function; | ||
import java.util.function.BiFunction; | ||
|
||
public class RetryingWebClient { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(RetryingWebClient.class); | ||
private final URI uri; | ||
private final HttpMethod method; | ||
private final long resultTimeoutMs; | ||
private final int retryCount; | ||
private final int retryBackoffMs; | ||
private final HttpClient httpClient; | ||
private Vertx vertx; | ||
|
||
public RetryingWebClient(Vertx vertx, String uri, HttpMethod method, int retryCount, int retryBackoffMs) { | ||
this(vertx, uri, method, retryCount, retryBackoffMs, 5*60*1000); | ||
} | ||
public RetryingWebClient(Vertx vertx, String uri, HttpMethod method, int retryCount, int retryBackoffMs, long resultTimeoutMs) { | ||
this.vertx = vertx; | ||
this.uri = URI.create(uri); | ||
this.method = method; | ||
this.resultTimeoutMs = resultTimeoutMs; | ||
this.httpClient = HttpClient.newHttpClient(); | ||
|
||
this.retryCount = retryCount; | ||
|
@@ -42,7 +48,8 @@ public Future<Void> send(BiFunction<URI, HttpMethod, HttpRequest> requestCreator | |
Promise<Void> promise = Promise.promise(); | ||
|
||
HttpRequest request = requestCreator.apply(this.uri, this.method); | ||
CompletableFuture<HttpResponse<String>> asyncResponse = this.httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString()); | ||
CompletableFuture<HttpResponse<String>> asyncResponse = this.httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString()) | ||
.orTimeout(this.resultTimeoutMs, TimeUnit.MILLISECONDS); | ||
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. The timeout. This won't hit the retry logic - the retries only kick in if the overall network request succeeds and the server returns a failure (i.e. the future succeeds with a response indicating failure). This is consistent with that behavior, but maybe we want to think about whether exceptions should also trigger the retry logic. |
||
|
||
asyncResponse.thenAccept(response -> { | ||
try { | ||
|
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.
Currently only recording successful sends - failures could happen for a range of reasons that might affect the time they take, so having a timer on "any failed request" probably isn't useful.