-
Notifications
You must be signed in to change notification settings - Fork 982
Use HTTP error bodies in HttpExporter warnings #8428
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
Open
ADITYA-CODE-SOURCE
wants to merge
4
commits into
open-telemetry:main
Choose a base branch
from
ADITYA-CODE-SOURCE:issue-7704-http-exporter-warning
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+140
−2
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fff6013
Use HTTP error body in HttpExporter warnings
ADITYA-CODE-SOURCE 47159e2
Fix GrpcExporterUtil import after rebase
ADITYA-CODE-SOURCE 323e2b4
Fix OTLP HttpExporter test suite split
ADITYA-CODE-SOURCE 29c06ac
Cover HttpExporter fallback branches
ADITYA-CODE-SOURCE File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,9 @@ | |
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.doAnswer; | ||
|
|
||
| import io.github.netmikey.logunit.api.LogCapturer; | ||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.api.metrics.MeterProvider; | ||
| import io.opentelemetry.exporter.internal.marshal.Marshaler; | ||
| import io.opentelemetry.internal.testing.slf4j.SuppressLogger; | ||
| import io.opentelemetry.sdk.common.InternalTelemetryVersion; | ||
|
|
@@ -22,13 +24,19 @@ | |
| import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; | ||
| import java.io.IOException; | ||
| import java.net.URI; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Consumer; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.RegisterExtension; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.EnumSource; | ||
| import org.mockito.Mockito; | ||
|
|
||
| class HttpExporterTest { | ||
|
|
||
| @RegisterExtension LogCapturer logs = LogCapturer.create().captureForType(HttpExporter.class); | ||
|
|
||
| @ParameterizedTest | ||
| @EnumSource | ||
| @SuppressLogger(HttpExporter.class) | ||
|
|
@@ -197,14 +205,128 @@ void testInternalTelemetry(StandardComponentId.ExporterType exporterType) { | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| @SuppressLogger(HttpExporter.class) | ||
| void export_httpJsonErrorBodyUsesBodyTextWithoutGrpcParseWarning() { | ||
| HttpSender mockSender = Mockito.mock(HttpSender.class); | ||
| Marshaler mockMarshaller = Mockito.mock(Marshaler.class); | ||
| HttpExporter exporter = | ||
| new HttpExporter( | ||
| ComponentId.generateLazy(StandardComponentId.ExporterType.OTLP_HTTP_SPAN_EXPORTER), | ||
| mockSender, | ||
| MeterProvider::noop, | ||
| InternalTelemetryVersion.LATEST, | ||
| URI.create("http://testing:1234"), | ||
| false); | ||
|
|
||
| doAnswer( | ||
| invoc -> { | ||
| Consumer<HttpResponse> onResponse = invoc.getArgument(1); | ||
| onResponse.accept( | ||
| new FakeHttpResponse( | ||
| 500, | ||
| "Internal Server Error", | ||
| "{\"error\":\"grpc not supported\"}".getBytes(StandardCharsets.UTF_8))); | ||
| return null; | ||
| }) | ||
| .when(mockSender) | ||
| .send(any(), any(), any()); | ||
|
|
||
| assertThat(exporter.export(mockMarshaller, 1).join(10, TimeUnit.SECONDS).isSuccess()).isFalse(); | ||
|
|
||
| logs.assertContains("Response body: {\"error\":\"grpc not supported\"}"); | ||
| logs.assertDoesNotContain("Unable to parse response body"); | ||
| } | ||
|
|
||
| @Test | ||
| @SuppressLogger(HttpExporter.class) | ||
| void export_nullErrorBodyUsesMissingBodyMessage() { | ||
| HttpSender mockSender = Mockito.mock(HttpSender.class); | ||
| Marshaler mockMarshaller = Mockito.mock(Marshaler.class); | ||
| HttpExporter exporter = | ||
| new HttpExporter( | ||
| ComponentId.generateLazy(StandardComponentId.ExporterType.OTLP_HTTP_SPAN_EXPORTER), | ||
| mockSender, | ||
| MeterProvider::noop, | ||
| InternalTelemetryVersion.LATEST, | ||
| URI.create("http://testing:1234"), | ||
| false); | ||
|
|
||
| doAnswer( | ||
| invoc -> { | ||
| Consumer<HttpResponse> onResponse = invoc.getArgument(1); | ||
| onResponse.accept( | ||
| new HttpResponse() { | ||
| @Override | ||
| public int getStatusCode() { | ||
| return 500; | ||
| } | ||
|
|
||
| @Override | ||
| public String getStatusMessage() { | ||
| return "Internal Server Error"; | ||
| } | ||
|
|
||
| @Override | ||
| public byte[] getResponseBody() { | ||
| return null; | ||
| } | ||
| }); | ||
| return null; | ||
| }) | ||
|
Comment on lines
+258
to
+276
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't this be replaced by: new FakeHttpResponse(500, "Internal Server Error", null);or am I missing something? |
||
| .when(mockSender) | ||
| .send(any(), any(), any()); | ||
|
|
||
| assertThat(exporter.export(mockMarshaller, 1).join(10, TimeUnit.SECONDS).isSuccess()).isFalse(); | ||
|
|
||
| logs.assertContains("Response body missing, HTTP status message: Internal Server Error"); | ||
| } | ||
|
|
||
| @Test | ||
| @SuppressLogger(HttpExporter.class) | ||
| void export_whitespaceErrorBodyFallsBackToStatusMessage() { | ||
| HttpSender mockSender = Mockito.mock(HttpSender.class); | ||
| Marshaler mockMarshaller = Mockito.mock(Marshaler.class); | ||
| HttpExporter exporter = | ||
| new HttpExporter( | ||
| ComponentId.generateLazy(StandardComponentId.ExporterType.OTLP_HTTP_SPAN_EXPORTER), | ||
| mockSender, | ||
| MeterProvider::noop, | ||
| InternalTelemetryVersion.LATEST, | ||
| URI.create("http://testing:1234"), | ||
| false); | ||
|
|
||
| doAnswer( | ||
| invoc -> { | ||
| Consumer<HttpResponse> onResponse = invoc.getArgument(1); | ||
| onResponse.accept( | ||
| new FakeHttpResponse( | ||
| 500, "Internal Server Error", " ".getBytes(StandardCharsets.UTF_8))); | ||
| return null; | ||
| }) | ||
| .when(mockSender) | ||
| .send(any(), any(), any()); | ||
|
|
||
| assertThat(exporter.export(mockMarshaller, 1).join(10, TimeUnit.SECONDS).isSuccess()).isFalse(); | ||
|
|
||
| logs.assertContains("HTTP status message: Internal Server Error"); | ||
| logs.assertDoesNotContain("Response body:"); | ||
| } | ||
|
|
||
| private static class FakeHttpResponse implements HttpResponse { | ||
|
|
||
| final int statusCode; | ||
| final String statusMessage; | ||
| final byte[] responseBody; | ||
|
|
||
| FakeHttpResponse(int statusCode, String statusMessage) { | ||
| this(statusCode, statusMessage, new byte[0]); | ||
| } | ||
|
|
||
| FakeHttpResponse(int statusCode, String statusMessage, byte[] responseBody) { | ||
| this.statusCode = statusCode; | ||
| this.statusMessage = statusMessage; | ||
| this.responseBody = responseBody; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -219,7 +341,7 @@ public String getStatusMessage() { | |
|
|
||
| @Override | ||
| public byte[] getResponseBody() { | ||
| return new byte[0]; | ||
| return responseBody; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QQ: Why was this number chosen?