Use HTTP error bodies in HttpExporter warnings#8428
Conversation
psx95
left a comment
There was a problem hiding this comment.
This PR improves the default parsing experience of gRPC errors in HttpExporters by converting the raw bytes to a UTF-8 string as a fallback.
Looking at the original issue #7704 - the original ask was for a way to suppress the noisy logs - this PR makes the logs helpful, but does not suppress it - which IMO is ok (IIUC, a decision was not taken on it), but I'll defer to the maintainers here.
| @@ -32,6 +34,7 @@ | |||
| */ | |||
| @SuppressWarnings("checkstyle:JavadocMethod") | |||
| public final class HttpExporter { | |||
| private static final int MAX_RESPONSE_BODY_LOG_LENGTH = 1024; | |||
There was a problem hiding this comment.
QQ: Why was this number chosen?
There was a problem hiding this comment.
Chose 1024 as a conservative cap so failed exports can still show the server response without letting a large payload flood the warning log. Happy to adjust the bound if you would prefer a different limit.
| return "Response body missing, HTTP status message: " + statusMessage; | ||
| } | ||
| if (responseBody.length == 0) { | ||
| return "HTTP status message: " + statusMessage; |
There was a problem hiding this comment.
nit: could add a better message indicating this is a length = 0 case.
Something like "Response body has 0 length, HTTP status message: "
There was a problem hiding this comment.
Addressed in the latest version: zero-length bodies now produce a specific message instead of the generic fallback.
| } | ||
|
|
||
| private static String extractResponseBodyMessage(byte[] responseBody, String statusMessage) { | ||
| String responseBodyText = new String(responseBody, StandardCharsets.UTF_8).trim(); |
There was a problem hiding this comment.
nit: Minor improvement:
int lengthToRead = Math.min(responseBody.length, MAX_RESPONSE_BODY_LOG_LENGTH);
String responseBodyText = new String(responseBody, 0, lengthToRead, StandardCharsets.UTF_8).trim();
There was a problem hiding this comment.
Addressed in the latest version: decoding is now bounded to the configured max length before converting to UTF-8.
a12e8d8 to
fff6013
Compare
|
@psx95 Addressed the nits — bounded decoding, zero-length message, 1024 comment, and rebased onto latest |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8428 +/- ##
============================================
+ Coverage 90.96% 91.03% +0.06%
- Complexity 7809 7824 +15
============================================
Files 892 893 +1
Lines 23702 23729 +27
Branches 2361 2366 +5
============================================
+ Hits 21561 21602 +41
+ Misses 1420 1408 -12
+ Partials 721 719 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Quick clarification on scope: this PR does not suppress the warning itself. It keeps the existing warning behavior, but makes the warning actionable for non-gRPC HTTP error responses by surfacing the returned body text when gRPC status parsing fails. For empty or missing bodies it still falls back to the HTTP status message.\n\nI also pushed a small cleanup commit to reuse for the null-body test case raised in review. |
|
This PR has review comments. Review suggestions, whether from maintainers or automated reviewers, aren't always correct or required. Please evaluate each comment on its merits, then make sure each thread has a clear outcome. For example, link to the commit if you applied a suggestion, explain why it wasn't applied, or ask a follow-up question. Automation flags a PR for human review once every review thread has a reply or is marked as resolved. Status across open PRs is visible on the pull request dashboard. |
1 similar comment
|
This PR has review comments. Review suggestions, whether from maintainers or automated reviewers, aren't always correct or required. Please evaluate each comment on its merits, then make sure each thread has a clear outcome. For example, link to the commit if you applied a suggestion, explain why it wasn't applied, or ask a follow-up question. Automation flags a PR for human review once every review thread has a reply or is marked as resolved. Status across open PRs is visible on the pull request dashboard. |
14c22f0 to
be4b328
Compare
|
@ADITYA-CODE-SOURCE could you fix the failing CI on this PR to ensure that the new changes are good?
Also, could you update the description to remove "Fixes" from before the issue reference - otherwise merging this would close the issue and this comment clearly indicates that the PR does not address the mentioned issue. |
Fixes #7704.
Why
HttpExportercurrently tries to parse every non-success HTTP response body as a serialized gRPC status.Unable to parse response body, which is noisy and hides the actual server response.What
Testing
./gradlew --no-daemon --max-workers=1 -Dorg.gradle.jvmargs="-Xmx768m -XX:MaxMetaspaceSize=256m" :exporters:common:test --tests io.opentelemetry.exporter.internal.http.HttpExporterTest./gradlew --no-daemon --max-workers=1 -Dorg.gradle.jvmargs="-Xmx512m -XX:MaxMetaspaceSize=192m" :exporters:common:spotlessCheck