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: 404 for /topics connect endpoint logs a warn instead of showing up in CLI #8462

Merged
merged 1 commit into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -35,12 +35,17 @@
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.kafka.connect.runtime.ConnectorConfig;
import org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo;
import org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class DescribeConnectorExecutor {

private static final Logger LOG = LoggerFactory.getLogger(DescribeConnectorExecutor.class);

@VisibleForTesting
static final String TOPICS_KEY = "topics";

Expand Down Expand Up @@ -99,7 +104,15 @@ public StatementExecutorResponse execute(
final ConnectResponse<Map<String, Map<String, List<String>>>> topicsResponse = serviceContext
.getConnectClient()
.topics(connectorName);
if (topicsResponse.error().isPresent()) {
// topics endpoint is relatively new (KAFKA-9422), so 404 here is expected behavior for older
// Connect versions. Rather than showing a scary warning to the user, we just log it to the
// server logs.
if (topicsResponse.error().isPresent()
&& topicsResponse.httpCode() == HttpStatus.SC_NOT_FOUND) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a quick comment in the code about why we handle the 404 case differently? I can imagine future readers seeing this and being confused.

Copy link
Contributor Author

@Gerrrr Gerrrr Dec 8, 2021

Choose a reason for hiding this comment

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

Done in 9eda284.

topics = ImmutableList.of();
warnings = ImmutableList.of();
LOG.warn("Could not list related topics due to error: " + topicsResponse.error().get());
} else if (topicsResponse.error().isPresent()) {
topics = ImmutableList.of();
warnings = ImmutableList.of(
new KsqlWarning("Could not list related topics due to error: "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,31 @@ public void shouldErrorIfConnectClientFailsDescribe() {
assertThat(((ErrorEntity) entity.get()).getErrorMessage(), is("error"));
}

@Test
public void shouldNotWarnClientOnMissingTopicsEndpoint() {
// Given:
when(connectClient.topics(any())).thenReturn(ConnectResponse.failure("not found",
HttpStatus.SC_NOT_FOUND));

// When:
final Optional<KsqlEntity> entity = executor
.execute(describeStatement, mock(SessionProperties.class), engine, serviceContext)
.getEntity();

// Then:
verify(engine).getMetaStore();
verify(metaStore).getAllDataSources();
verify(connectClient).status("connector");
verify(connectClient).describe("connector");
verify(connectClient).topics("connector");
assertThat("Expected a response", entity.isPresent());
assertThat(entity.get(), instanceOf(ConnectorDescription.class));

final ConnectorDescription description = (ConnectorDescription) entity.get();
assertThat(description.getTopics(), empty());
assertThat(description.getWarnings(), empty());
}

@Test
public void shouldWorkIfUnknownConnector() {
// Given:
Expand Down