-
Notifications
You must be signed in to change notification settings - Fork 45
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
HTTP lookup source max retries #90
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 |
---|---|---|
|
@@ -27,6 +27,10 @@ | |
@Slf4j | ||
public class JavaNetHttpPollingClient implements PollingClient<RowData> { | ||
|
||
public static final String DEFAULT_REQUEST_MAX_RETRIES = "3"; | ||
|
||
public static final String DEFAULT_REQUEST_RETRY_TIMEOUT_MS = "1000"; | ||
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 suggest calling this DEFAULT_REQUEST_RETRY_INTERVAL_MS as it is not a timeout. Also this name should mention lookup or polling client - so that it is obvious it does not apply to the sink client. Same naming consideration for max retries. I assume we will add something similar for the sink client 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. @Raz0r could you apply proposed changes? |
||
|
||
private final HttpClient httpClient; | ||
|
||
private final HttpStatusCodeChecker statusCodeChecker; | ||
|
@@ -37,6 +41,10 @@ public class JavaNetHttpPollingClient implements PollingClient<RowData> { | |
|
||
private final HttpPostRequestCallback<HttpLookupSourceRequestEntry> httpPostRequestCallback; | ||
|
||
protected final int httpRequestMaxRetries; | ||
|
||
protected final int httpRequestRetryTimeoutMs; | ||
|
||
public JavaNetHttpPollingClient( | ||
HttpClient httpClient, | ||
DeserializationSchema<RowData> responseBodyDecoder, | ||
|
@@ -62,6 +70,20 @@ public JavaNetHttpPollingClient( | |
.build(); | ||
|
||
this.statusCodeChecker = new ComposeHttpStatusCodeChecker(checkerConfig); | ||
|
||
this.httpRequestMaxRetries = Integer.parseInt( | ||
options.getProperties().getProperty( | ||
HttpConnectorConfigConstants.LOOKUP_HTTP_MAX_RETRIES, | ||
DEFAULT_REQUEST_MAX_RETRIES | ||
) | ||
); | ||
|
||
this.httpRequestRetryTimeoutMs = Integer.parseInt( | ||
options.getProperties().getProperty( | ||
HttpConnectorConfigConstants.LOOKUP_HTTP_RETRY_TIMEOUT_MS, | ||
DEFAULT_REQUEST_RETRY_TIMEOUT_MS | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
|
@@ -74,15 +96,43 @@ public Optional<RowData> pull(RowData lookupRow) { | |
} | ||
} | ||
|
||
// TODO Add Retry Policy And configure TimeOut from properties | ||
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 the intent of this comment is to make use of the Flink Retry strategies, which includes async. 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 thing is that AsyncSink uses totally different, dedicated mechanism for retries => Flink native support. What kind of Flink retry strategies you were here @davidradl ? |
||
private Optional<RowData> queryAndProcess(RowData lookupData) throws Exception { | ||
|
||
private Optional<RowData> queryAndProcess(RowData lookupData) { | ||
HttpLookupSourceRequestEntry request = requestFactory.buildLookupRequest(lookupData); | ||
HttpResponse<String> response = httpClient.send( | ||
request.getHttpRequest(), | ||
BodyHandlers.ofString() | ||
); | ||
return processHttpResponse(response, request); | ||
HttpResponse<String> response = null; | ||
|
||
int retryCount = 0; | ||
|
||
while (retryCount < this.httpRequestMaxRetries) { | ||
try { | ||
response = httpClient.send( | ||
request.getHttpRequest(), | ||
BodyHandlers.ofString() | ||
); | ||
break; | ||
} catch (IOException e) { | ||
log.error("IOException during HTTP request. Retrying...", e); | ||
retryCount++; | ||
if (retryCount == this.httpRequestMaxRetries) { | ||
log.error("Maximum retries reached. Aborting..."); | ||
return Optional.empty(); | ||
} | ||
try { | ||
Thread.sleep(this.httpRequestRetryTimeoutMs); | ||
} catch (InterruptedException ie) { | ||
Thread.currentThread().interrupt(); | ||
} | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
log.error("HTTP request interrupted. Aborting...", e); | ||
return Optional.empty(); | ||
} | ||
} | ||
try { | ||
return processHttpResponse(response, request); | ||
} catch (IOException e) { | ||
log.error("IOException during HTTP response processing.", e); | ||
return Optional.empty(); | ||
} | ||
} | ||
|
||
private Optional<RowData> processHttpResponse( | ||
|
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.
should this not be an int?
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.
We tend keep all properties as Strings, becase they are passed as Properties<String,String> from Table factories.
Later we use them like this: