Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

EvaSDK
Copy link

@EvaSDK EvaSDK commented Sep 26, 2022

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.

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.
Comment on lines +114 to +123
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer early returns 😄

Suggested change
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);
}

@danieljimeneznz danieljimeneznz changed the title Do not retry on successful requests fix: Disable retries on successful requests Sep 26, 2022
@kedarkrishnan
Copy link
Member

The connector is designed to retry based on the flag returned in the response.
Check README - Exception strategies
"The exception strategy is triggered if the response send back by the callback url had a retry flag set to true."

The Idea here was to keep the retry strategy decoupled from the HTTP Status. Hence even for HTTP Success we check the retry flag.
This change breaks that.

@EvaSDK
Copy link
Author

EvaSDK commented Sep 29, 2022

The Idea here was to keep the retry strategy decoupled from the HTTP Status. Hence even for HTTP Success we check the retry flag. This change breaks that.

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.

@danieljimeneznz
Copy link
Contributor

The Idea here was to keep the retry strategy decoupled from the HTTP Status. Hence even for HTTP Success we check the retry flag. This change breaks that.

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?

@kedarkrishnan
Copy link
Member

The Idea here was to keep the retry strategy decoupled from the HTTP Status. Hence even for HTTP Success we check the retry flag. This change breaks that.

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.

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