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

Add new retry policy adjustment method #1824

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,8 @@ protected boolean isRetryable(final ErrorType err) {
if ((err == OutboundErrorType.RESET_CONNECTION)
|| (err == OutboundErrorType.CONNECT_ERROR)
|| (err == OutboundErrorType.READ_TIMEOUT
&& IDEMPOTENT_HTTP_METHODS.contains(
zuulRequest.getMethod().toUpperCase()))) {
&& IDEMPOTENT_HTTP_METHODS.contains(
zuulRequest.getMethod().toUpperCase()))) {
return isRequestReplayable();
}
return false;
Expand Down Expand Up @@ -908,7 +908,7 @@ protected void handleOriginNonSuccessResponse(final HttpResponse originResponse,

boolean retryable5xxResponse = isRetryable5xxResponse(zuulRequest, originResponse);
if (retryable5xxResponse) {
origin.adjustRetryPolicyIfNeeded(zuulRequest);
origin.adjustRetryPolicyIfNeeded(zuulRequest, originResponse);
}

if (retryable5xxResponse && isBelowRetryLimit()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
import com.netflix.zuul.niws.RequestAttempt;
import com.netflix.zuul.passport.CurrentPassport;
import io.netty.channel.EventLoop;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.util.concurrent.Promise;

import javax.annotation.Nullable;
import java.net.InetAddress;
import java.util.concurrent.atomic.AtomicReference;

Expand Down Expand Up @@ -77,4 +80,8 @@ RequestAttempt newRequestAttempt(
IClientConfig getClientConfig();

Registry getSpectatorRegistry();

default void adjustRetryPolicyIfNeeded(HttpRequestMessage zuulRequest, @Nullable HttpResponse response) {
adjustRetryPolicyIfNeeded(zuulRequest);
Copy link
Collaborator

@argha-c argha-c Sep 17, 2024

Choose a reason for hiding this comment

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

Can we avoid this overload by using an || on the original method and a new one derived from the response?
That feels cleaner imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a new (awkwardly named) method originRetryPolicyAdjustmentIfNeeded

Copy link
Collaborator

Choose a reason for hiding this comment

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

Naming is hard. It just needs to convey that the adjustment is inferred by the origin response.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
Expand Down Expand Up @@ -61,6 +62,7 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.mockito.stubbing.Answer;

@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
Expand Down Expand Up @@ -156,7 +158,7 @@ void retryWhenNoAdjustment() {
createResponse(HttpResponseStatus.SERVICE_UNAVAILABLE);

proxyEndpoint.handleOriginNonSuccessResponse(response, createDiscoveryResult());
verify(nettyOrigin).adjustRetryPolicyIfNeeded(request);
verify(nettyOrigin).adjustRetryPolicyIfNeeded(eq(request), any(HttpResponse.class));
verify(nettyOrigin).connectToOrigin(any(), any(), anyInt(), any(), any(), any());
}

Expand Down Expand Up @@ -215,12 +217,12 @@ private void validateNoRetry() {
}

private void disableRetriesOnAdjustment() {
doAnswer(invocation -> {
doReturn(-1).when(nettyOrigin).getMaxRetriesForRequest(context);
return null;
})
.when(nettyOrigin)
.adjustRetryPolicyIfNeeded(request);
Answer<?> answer = invocation -> {
doReturn(-1).when(nettyOrigin).getMaxRetriesForRequest(context);
return null;
};
doAnswer(answer).when(nettyOrigin).adjustRetryPolicyIfNeeded(request);
doAnswer(answer).when(nettyOrigin).adjustRetryPolicyIfNeeded(request, any(HttpResponse.class));
}

private static DiscoveryResult createDiscoveryResult() {
Expand Down
Loading