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 extra logging for the failure case of the HTTP request. #1736

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<hbase.client.version>2.5.3-hadoop3</hbase.client.version>
<mockito.version>4.11.0</mockito.version>
<log4j-2.version>2.17.2</log4j-2.version>
<jackson.version>2.14.1</jackson.version>
<jackson.version>2.15.4</jackson.version>
<jettison.version>1.5.4</jettison.version>
<json.version>20231013</json.version>
<junit.version>4.13.2</junit.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.apache.beam.sdk.values.PDone;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.annotations.VisibleForTesting;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Strings;
import org.apache.commons.io.IOUtils;
import org.apache.http.ConnectionClosedException;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
Expand Down Expand Up @@ -1658,7 +1659,14 @@
try (RestClient restClient = connectionConfiguration.createClient()) {
Request request = new Request("GET", "");
Response response = restClient.performRequest(request);
JsonNode jsonNode = parseResponse(response.getEntity());
JsonNode jsonNode;
try {
jsonNode = parseResponse(response.getEntity());
} catch (IOException jsonException) {
throw new IOException(

Check warning on line 1666 in v2/elasticsearch-common/src/main/java/com/google/cloud/teleport/v2/elasticsearch/utils/ElasticsearchIO.java

View check run for this annotation

Codecov / codecov/patch

v2/elasticsearch-common/src/main/java/com/google/cloud/teleport/v2/elasticsearch/utils/ElasticsearchIO.java#L1664-L1666

Added lines #L1664 - L1666 were not covered by tests
"The response is not a valid JSON: "
+ IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8));
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a unit test for this? Make sure an exception is thrown with the HTTP response body in the message?

}

Check warning on line 1669 in v2/elasticsearch-common/src/main/java/com/google/cloud/teleport/v2/elasticsearch/utils/ElasticsearchIO.java

View check run for this annotation

Codecov / codecov/patch

v2/elasticsearch-common/src/main/java/com/google/cloud/teleport/v2/elasticsearch/utils/ElasticsearchIO.java#L1668-L1669

Added lines #L1668 - L1669 were not covered by tests
int backendVersion =
Integer.parseInt(jsonNode.path("version").path("number").asText().substring(0, 1));
checkArgument(
Expand Down
Loading