Skip to content

Commit

Permalink
Manual cherrypick of 2a88be2 (#3820)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuraaga committed Nov 3, 2021
1 parent 33094f4 commit e84ee02
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,26 @@ public void onFailure(Call call, IOException e) {

@Override
public void onResponse(Call call, Response response) {
if (response.isSuccessful()) {
logsExportedSuccess.add(logs.size());
result.succeed();
return;
try (ResponseBody body = response.body()) {
if (response.isSuccessful()) {
logsExportedSuccess.add(logs.size());
result.succeed();
return;
}

logsExportedFailure.add(logs.size());
int code = response.code();

String status = extractErrorStatus(response, body);

logger.log(
Level.WARNING,
"Failed to export logs. Server responded with HTTP status code "
+ code
+ ". Error message: "
+ status);
result.fail();
}

logsExportedFailure.add(logs.size());
int code = response.code();

String status = extractErrorStatus(response);

logger.log(
Level.WARNING,
"Failed to export logs. Server responded with HTTP status code "
+ code
+ ". Error message: "
+ status);
result.fail();
}
});

Expand Down Expand Up @@ -163,8 +165,7 @@ public void writeTo(BufferedSink bufferedSink) throws IOException {
};
}

private static String extractErrorStatus(Response response) {
ResponseBody responseBody = response.body();
private static String extractErrorStatus(Response response, @Nullable ResponseBody responseBody) {
if (responseBody == null) {
return "Response body missing, HTTP status message: " + response.message();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,24 @@ public void onFailure(Call call, IOException e) {

@Override
public void onResponse(Call call, Response response) {
if (response.isSuccessful()) {
result.succeed();
return;
try (ResponseBody body = response.body()) {
if (response.isSuccessful()) {
result.succeed();
return;
}

int code = response.code();

String status = extractErrorStatus(response, body);

logger.log(
Level.WARNING,
"Failed to export metrics. Server responded with HTTP status code "
+ code
+ ". Error message: "
+ status);
result.fail();
}

int code = response.code();

String status = extractErrorStatus(response);

logger.log(
Level.WARNING,
"Failed to export metrics. Server responded with HTTP status code "
+ code
+ ". Error message: "
+ status);
result.fail();
}
});

Expand Down Expand Up @@ -135,8 +137,7 @@ public void writeTo(BufferedSink bufferedSink) throws IOException {
};
}

private static String extractErrorStatus(Response response) {
ResponseBody responseBody = response.body();
private static String extractErrorStatus(Response response, @Nullable ResponseBody responseBody) {
if (responseBody == null) {
return "Response body missing, HTTP status message: " + response.message();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,26 @@ public void onFailure(Call call, IOException e) {

@Override
public void onResponse(Call call, Response response) {
if (response.isSuccessful()) {
spansExportedSuccess.add(spans.size());
result.succeed();
return;
try (ResponseBody body = response.body()) {
if (response.isSuccessful()) {
spansExportedSuccess.add(spans.size());
result.succeed();
return;
}

spansExportedFailure.add(spans.size());
int code = response.code();

String status = extractErrorStatus(response, body);

logger.log(
Level.WARNING,
"Failed to export spans. Server responded with HTTP status code "
+ code
+ ". Error message: "
+ status);
result.fail();
}

spansExportedFailure.add(spans.size());
int code = response.code();

String status = extractErrorStatus(response);

logger.log(
Level.WARNING,
"Failed to export spans. Server responded with HTTP status code "
+ code
+ ". Error message: "
+ status);
result.fail();
}
});

Expand Down Expand Up @@ -163,8 +165,7 @@ public void writeTo(BufferedSink bufferedSink) throws IOException {
};
}

private static String extractErrorStatus(Response response) {
ResponseBody responseBody = response.body();
private static String extractErrorStatus(Response response, @Nullable ResponseBody responseBody) {
if (responseBody == null) {
return "Response body missing, HTTP status message: " + response.message();
}
Expand Down

0 comments on commit e84ee02

Please sign in to comment.