-
Notifications
You must be signed in to change notification settings - Fork 20
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
fix: Disable retries on successful requests #11
base: master
Are you sure you want to change the base?
Conversation
By HTTP standards, it makes no sense. Might want to make it configurable if an API is expected to request retry on successful HTTP status code.
if(Response.Status.Family.familyOf(statusCode) != Response.Status.Family.SUCCESSFUL){ | ||
RetryIndicator retryIndicator = getResponseIndicator(); | ||
log.info("Retry Indicator: {}", retryIndicator); | ||
if(retryIndicator == RetryIndicator.UNKNOWN | ||
&& CALLBACK_API_DOWN_HTTP_STATUS_CODE.contains(statusCode)){ | ||
throw new ApiRequestErrorException("Unable to connect to callback API: " | ||
+ " received status: " + statusCode, kafkaRecord); | ||
} else if (retryIndicator.shouldRetry) { | ||
throw new ApiResponseErrorException("Received response retry=true", kafkaRecord); | ||
} |
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.
I prefer early returns 😄
if(Response.Status.Family.familyOf(statusCode) != Response.Status.Family.SUCCESSFUL){ | |
RetryIndicator retryIndicator = getResponseIndicator(); | |
log.info("Retry Indicator: {}", retryIndicator); | |
if(retryIndicator == RetryIndicator.UNKNOWN | |
&& CALLBACK_API_DOWN_HTTP_STATUS_CODE.contains(statusCode)){ | |
throw new ApiRequestErrorException("Unable to connect to callback API: " | |
+ " received status: " + statusCode, kafkaRecord); | |
} else if (retryIndicator.shouldRetry) { | |
throw new ApiResponseErrorException("Received response retry=true", kafkaRecord); | |
} | |
if (Response.Status.Family.familyOf(statusCode) == Response.Status.Family.SUCCESSFUL) { | |
return | |
} | |
RetryIndicator retryIndicator = getResponseIndicator(); | |
log.info("Retry Indicator: {}", retryIndicator); | |
if (retryIndicator == RetryIndicator.UNKNOWN | |
&& CALLBACK_API_DOWN_HTTP_STATUS_CODE.contains(statusCode)){ | |
throw new ApiRequestErrorException("Unable to connect to callback API: " | |
+ " received status: " + statusCode, kafkaRecord); | |
} else if (retryIndicator.shouldRetry) { | |
throw new ApiResponseErrorException("Received response retry=true", kafkaRecord); | |
} |
The connector is designed to retry based on the flag returned in the response. The Idea here was to keep the retry strategy decoupled from the HTTP Status. Hence even for HTTP Success we check the retry flag. |
I see. It is a bit confusing when later describing the default according to HTTP status code and no field always means retry=True. Neither this default nor the HTTP status code is configurable so I implemented what I expected normal given a "standard" REST API response. |
We could probably add in a configuration for completely ignoring retries when the status code is successful? @kedarkrishnan thoughts? |
@danieljimeneznz That sounds like a good idea, it would not break the existing functionality. |
By HTTP standards, it makes no sense to retry a successful query.
This is also generating extra log lines that might be confusing as you expect the minimum after a successful query.
Might want to make it configurable if an API is expected to request retry on successful HTTP status code.