Skip to content

Commit 79fb916

Browse files
authored
Fix misleading WARN when polling connector status after KafkaConnector delete (#12710)
Signed-off-by: Parameshwaran Krishnasamy <Parameshwaran.K@ibm.com>
1 parent 502f69e commit 79fb916

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

cluster-operator/src/main/java/io/strimzi/operator/cluster/operator/assembly/KafkaConnectApiImpl.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,16 @@ private <T> CompletableFuture<T> doGet(Reconciliation reconciliation, String hos
131131
LOGGER.debugCr(reconciliation, "Got {} response to GET request to {}: {}", statusCode, path, json.asText());
132132
return CompletableFuture.completedFuture(OBJECT_MAPPER.convertValue(json, type));
133133
} else {
134-
LOGGER.debugCr(reconciliation, "Got {} response to GET request to {}", statusCode, path);
135-
return CompletableFuture.failedFuture(new ConnectRestException(response, tryToExtractErrorMessage(reconciliation, response.body())));
134+
LOGGER.debugCr(reconciliation, "Got unexpected {} response to GET request to {}. Ok status codes: {}",
135+
statusCode, path, okStatusCodes);
136+
String message;
137+
if (statusCode >= 200 && statusCode < 300) {
138+
// Unlisted 2xx: poll may get 200 before 404 after delete.
139+
message = "Unexpected HTTP status code " + statusCode;
140+
} else {
141+
message = tryToExtractErrorMessage(reconciliation, response.body());
142+
}
143+
return CompletableFuture.failedFuture(new ConnectRestException(response, message));
136144
}
137145
});
138146
}

cluster-operator/src/test/java/io/strimzi/operator/cluster/operator/assembly/KafkaConnectApiImplTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
import org.junit.jupiter.api.BeforeEach;
1616
import org.junit.jupiter.api.Test;
1717

18+
import java.util.Collections;
1819
import java.util.Map;
20+
import java.util.concurrent.ExecutionException;
1921

2022
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
2123
import static com.github.tomakehurst.wiremock.client.WireMock.get;
@@ -26,6 +28,7 @@
2628
import static org.hamcrest.Matchers.allOf;
2729
import static org.hamcrest.Matchers.containsString;
2830
import static org.hamcrest.Matchers.hasEntry;
31+
import static org.hamcrest.Matchers.instanceOf;
2932
import static org.hamcrest.Matchers.is;
3033
import static org.junit.jupiter.api.Assertions.assertThrows;
3134

@@ -86,6 +89,45 @@ public void testFeatureCompletionWithWellFormattedError() {
8689
.whenComplete((res, ex) -> assertThat(ex.getMessage(), containsString("This is the error")))::join);
8790
}
8891

92+
@Test
93+
public void testStatusDoesNotTreatOkBodyAsErrorMessage() throws Exception {
94+
// Poll /status for 404 only; 200 with connector status is normal until removal.
95+
String statusBody = "{\"name\":\"my-connector\",\"connector\":{\"state\":\"RUNNING\"},"
96+
+ "\"tasks\":[]}";
97+
server.stubFor(get(urlPathMatching(".*/connectors/my-connector/status"))
98+
.willReturn(aResponse()
99+
.withStatus(200)
100+
.withBody(statusBody)));
101+
102+
KafkaConnectApi api = new KafkaConnectApiImpl();
103+
104+
ExecutionException ex = assertThrows(ExecutionException.class,
105+
() -> api.status(
106+
Reconciliation.DUMMY_RECONCILIATION, "127.0.0.1", server.port(),
107+
"my-connector", Collections.singleton(404))
108+
.get());
109+
assertThat(ex.getCause(), instanceOf(ConnectRestException.class));
110+
assertThat(ex.getCause().getMessage(), containsString("Unexpected HTTP status code 200"));
111+
}
112+
113+
@Test
114+
public void testStatusWithValidErrorBody() throws Exception {
115+
server.stubFor(get(urlPathMatching(".*/connectors/c/status"))
116+
.willReturn(aResponse()
117+
.withStatus(500)
118+
.withBody("{\"message\": \"Connect cluster error\"}")));
119+
120+
KafkaConnectApi api = new KafkaConnectApiImpl();
121+
122+
ExecutionException ex = assertThrows(ExecutionException.class,
123+
() -> api.status(
124+
Reconciliation.DUMMY_RECONCILIATION, "127.0.0.1", server.port(),
125+
"c", Collections.singleton(200))
126+
.get());
127+
assertThat(ex.getCause(), instanceOf(ConnectRestException.class));
128+
assertThat(ex.getCause().getMessage(), containsString("Connect cluster error"));
129+
}
130+
89131
@Test
90132
public void testListConnectLoggersWithLevel() throws Exception {
91133
server.stubFor(get(urlPathMatching(".*"))

0 commit comments

Comments
 (0)