-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Bound HTTP timeouts in KafkaAgentClient to keep KafkaRoller responsive #12675
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -7,6 +7,11 @@ | |
| import io.strimzi.operator.common.Reconciliation; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.http.HttpClient; | ||
| import java.net.http.HttpRequest; | ||
| import java.time.Duration; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
|
|
@@ -60,4 +65,30 @@ public void testErrorResponse() { | |
| assertEquals(0, actual.remainingLogsToRecover()); | ||
| assertEquals(0, actual.remainingSegmentsToRecover()); | ||
| } | ||
|
|
||
| /** | ||
| * Regression guard: a previous version of KafkaAgentClient configured no timeout on the per-request side, | ||
| * which let a broker stuck on IO block the KafkaRoller's single-threaded executor indefinitely. Verify that | ||
| * requests built via the package-private helper carry the configured timeout. | ||
| */ | ||
| @Test | ||
| public void testBuildRequestAppliesHttpRequestTimeout() { | ||
|
Contributor
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. Similar to my other comment, I'm not sure if these tests are really that helpful. We set the timeout on the client and request, then testing if these timeouts are set here. If we want to make sure, we are not indefinitely waiting for a response, maybe simulating a slow response that exceeds the timeout and check for timeout error to really test the behaviour. But even that might be overkill?
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 think testing it like this might be tricky and questionable. What is it we want to test?
For the first one I would argue it is probably not our concern. For the second one, it might be hard to actually make sure the test hangs in the right way how it would in production. So I wonder how reliably can we replicate the same situation.
Contributor
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 these new tests add much value and we set timeouts in many places for requests and we don't test them like that. So I was trying to suggest alternative that is more for your second point but wasn't anyway sure if that is the right thing to do either.
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. Yeah, that is a fair point that the current test is probably not much useful. I'm just not sure how easy it is to make it useful.
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 agree that this test is not really useful, I left a similar comment for the other one. |
||
| HttpRequest request = KafkaAgentClient.buildRequest(URI.create("https://example.invalid/v1/broker-state/")); | ||
| Duration timeout = request.timeout().orElseThrow(() -> new AssertionError("HTTP request timeout was not configured")); | ||
| assertEquals(KafkaAgentClient.HTTP_REQUEST_TIMEOUT, timeout, "Request timeout must equal HTTP_REQUEST_TIMEOUT"); | ||
| assertTrue(timeout.toMillis() > 0, "HTTP request timeout must be positive but was " + timeout); | ||
| } | ||
|
|
||
| /** | ||
| * Regression guard: a previous version of KafkaAgentClient configured no connect timeout, which let an | ||
| * unresponsive broker block the KafkaRoller's single-threaded executor indefinitely. Verify that clients | ||
| * built via the package-private helper carry the configured connect timeout. | ||
| */ | ||
| @Test | ||
| public void testHttpClientBuilderAppliesConnectTimeout() { | ||
| HttpClient client = KafkaAgentClient.httpClientBuilder().build(); | ||
|
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. In the end the |
||
| Duration connectTimeout = client.connectTimeout().orElseThrow(() -> new AssertionError("HTTP connect timeout was not configured")); | ||
| assertEquals(KafkaAgentClient.HTTP_REQUEST_TIMEOUT, connectTimeout, "Connect timeout must equal HTTP_REQUEST_TIMEOUT"); | ||
| assertTrue(connectTimeout.toMillis() > 0, "HTTP connect timeout must be positive but was " + connectTimeout); | ||
| } | ||
| } | ||
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.
Sorry, I did not realize it before. But why not add the SSL context as a parameter and have it return the HTTP client instead of the half-finished builder?
Uh oh!
There was an error while loading. Please reload this page.
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 understand these new methods make it easier to test but are they really necessary? It seems to me it is quite straight forward to set the timeout without additional methods that are called only once. Otherwise I agree with Jakub that it makes more sense that the method returns complete HTTP client, rather than finish building here.
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.
Taking into account that this method was written for adding tests which seem to be not that useful, I agree that we should just remove the method and configure timeout and SSLContext here.
Uh oh!
There was an error while loading. Please reload this page.
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.
@chon3806 Are you happy with the suggestions in above comments? So you could set the timeout directly here instead of a separate method, for example: