-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Http Event Listener retry for codes not in [200, 300) and expections, rertry delay calculation fix, better logging #10566
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
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 |
|---|---|---|
|
|
@@ -82,27 +82,27 @@ public HttpEventListener(HttpEventListenerConfig config, @ForHttpEventListener H | |
| public void queryCreated(QueryCreatedEvent queryCreatedEvent) | ||
| { | ||
| if (config.getLogCreated()) { | ||
| sendLog(queryCreatedEvent); | ||
| sendLog(queryCreatedEvent, queryCreatedEvent.getMetadata().getQueryId()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void queryCompleted(QueryCompletedEvent queryCompletedEvent) | ||
| { | ||
| if (config.getLogCompleted()) { | ||
| sendLog(queryCompletedEvent); | ||
| sendLog(queryCompletedEvent, queryCompletedEvent.getMetadata().getQueryId()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void splitCompleted(SplitCompletedEvent splitCompletedEvent) | ||
| { | ||
| if (config.getLogSplit()) { | ||
| sendLog(splitCompletedEvent); | ||
| sendLog(splitCompletedEvent, splitCompletedEvent.getQueryId()); | ||
| } | ||
| } | ||
|
|
||
| private <T> void sendLog(T event) | ||
| private <T> void sendLog(T event, String queryId) | ||
| { | ||
| Request request = preparePost() | ||
| .addHeaders(Multimaps.forMap(config.getHttpHeaders())) | ||
|
|
@@ -111,10 +111,10 @@ private <T> void sendLog(T event) | |
| .setBodyGenerator(out -> objectWriter.writeValue(out, event)) | ||
| .build(); | ||
|
|
||
| attemptToSend(request, 0, Duration.valueOf("0s")); | ||
| attemptToSend(request, 0, Duration.valueOf("0s"), queryId); | ||
| } | ||
|
|
||
| private void attemptToSend(Request request, int attempt, Duration delay) | ||
| private void attemptToSend(Request request, int attempt, Duration delay, String queryId) | ||
| { | ||
| this.executor.schedule( | ||
| () -> Futures.addCallback(client.executeAsync(request, createStatusResponseHandler()), | ||
|
|
@@ -124,27 +124,50 @@ public void onSuccess(StatusResponse result) | |
| { | ||
| verify(result != null); | ||
|
|
||
| if (result.getStatusCode() >= 500 && attempt < config.getRetryCount()) { | ||
| attemptToSend(request, attempt + 1, nextDelay(delay)); | ||
| if (!(result.getStatusCode() >= 200 && result.getStatusCode() < 300) && attempt < config.getRetryCount()) { | ||
|
Member
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'm not sure how would retrying any 4xx error ever succeed? Wouldn't we end up retrying until retry attempts are exhausted?
Contributor
Author
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. Yes, we would retry until attempts are exhausted.
Member
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. Seems wasteful - specially since the event listener is synchronous and retrying a 4xx error seems guaranteed to fail unless for maybe HTTP 429. Thanks for clarifying. I believe the intent is to use this mechanism to identify the scenarios we don't handle well currently and then fix them.
Contributor
Author
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 think it has its use-cases (which admittedly are edge-cases) and it's better to be safe than drop data. This doesn't run on the query execution threads so no direct slowdown. |
||
| Duration nextDelay = nextDelay(delay); | ||
| int nextAttempt = attempt + 1; | ||
|
|
||
| log.warn("QueryId = \"%s\", attempt = %d/%d, URL = %s | Ingest server responded with code %d, will retry after approximately %d seconds", | ||
| queryId, attempt + 1, config.getRetryCount() + 1, request.getUri().toString(), | ||
| result.getStatusCode(), nextDelay.roundTo(TimeUnit.SECONDS)); | ||
|
|
||
| attemptToSend(request, nextAttempt, nextDelay, queryId); | ||
| return; | ||
| } | ||
|
|
||
| if (!(result.getStatusCode() >= 200 && result.getStatusCode() < 300)) { | ||
| log.error("Received status code %d from ingest server URI %s; expecting status 200", result.getStatusCode(), request.getUri()); | ||
| } | ||
| log.debug("QueryId = \"%s\", attempt = %d/%d, URL = %s | Query event delivered successfully", | ||
| queryId, attempt + 1, config.getRetryCount() + 1, request.getUri().toString()); | ||
| } | ||
|
|
||
| @Override | ||
| public void onFailure(Throwable t) | ||
| { | ||
| log.error("Error sending HTTP request to ingest server with URL %s: %s", request.getUri(), t); | ||
| if (attempt < config.getRetryCount()) { | ||
| Duration nextDelay = nextDelay(delay); | ||
| int nextAttempt = attempt + 1; | ||
|
|
||
| log.warn(t, "QueryId = \"%s\", attempt = %d/%d, URL = %s | Sending event caused an exception, will retry after %d seconds", | ||
| queryId, attempt + 1, config.getRetryCount() + 1, request.getUri().toString(), | ||
| nextDelay.roundTo(TimeUnit.SECONDS)); | ||
|
|
||
| attemptToSend(request, nextAttempt, nextDelay, queryId); | ||
| return; | ||
| } | ||
|
|
||
| log.error(t, "QueryId = \"%s\", attempt = %d/%d, URL = %s | Error sending HTTP request", | ||
| queryId, attempt + 1, config.getRetryCount() + 1, request.getUri().toString()); | ||
| } | ||
| }, executor), | ||
| (long) delay.getValue(), delay.getUnit()); | ||
| } | ||
|
|
||
| private Duration nextDelay(Duration delay) | ||
| { | ||
| if (delay.compareTo(Duration.valueOf("0s")) == 0) { | ||
| return config.getRetryDelay(); | ||
| } | ||
|
|
||
| Duration newDuration = Duration.succinctDuration(delay.getValue(TimeUnit.SECONDS) * this.config.getBackoffBase(), TimeUnit.SECONDS); | ||
| if (newDuration.compareTo(config.getMaxDelay()) > 0) { | ||
| return config.getMaxDelay(); | ||
|
|
||
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.
Commit messge
Add more logging the event listener->Add more logging in the HTTP event listener