-
Notifications
You must be signed in to change notification settings - Fork 966
Response body bounds #8224
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
Response body bounds #8224
Changes from 2 commits
441391d
94e1052
440519a
9746611
094bde3
cc98859
1cfb972
3aebc41
95ba71f
b86d921
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,7 @@ | ||
| Comparing source compatibility of opentelemetry-sdk-common-1.61.0-SNAPSHOT.jar against opentelemetry-sdk-common-1.60.1.jar | ||
| No changes. | ||
| *** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.common.export.GrpcSenderConfig (not serializable) | ||
| === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
| +++ NEW METHOD: PUBLIC(+) long getMaxResponseBodySize() | ||
| *** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.sdk.common.export.HttpSenderConfig (not serializable) | ||
| === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
| +++ NEW METHOD: PUBLIC(+) long getMaxResponseBodySize() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| Comparing source compatibility of opentelemetry-sdk-extension-jaeger-remote-sampler-1.61.0-SNAPSHOT.jar against opentelemetry-sdk-extension-jaeger-remote-sampler-1.60.1.jar | ||
| No changes. | ||
| *** MODIFIED CLASS: PUBLIC FINAL io.opentelemetry.sdk.extension.trace.jaeger.sampler.JaegerRemoteSamplerBuilder (not serializable) | ||
| === CLASS FILE FORMAT VERSION: 52.0 <- 52.0 | ||
| +++ NEW METHOD: PUBLIC(+) io.opentelemetry.sdk.extension.trace.jaeger.sampler.JaegerRemoteSamplerBuilder setMaxSamplingStrategyResponseBodySize(long) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,7 @@ public final class JdkHttpSender implements HttpSender { | |
| private final Supplier<Map<String, List<String>>> headerSupplier; | ||
| @Nullable private final RetryPolicy retryPolicy; | ||
| private final Predicate<IOException> retryExceptionPredicate; | ||
| private final long maxResponseBodySize; | ||
|
|
||
| // Visible for testing | ||
| JdkHttpSender( | ||
|
|
@@ -82,7 +83,8 @@ public final class JdkHttpSender implements HttpSender { | |
| Duration timeout, | ||
| Supplier<Map<String, List<String>>> headerSupplier, | ||
| @Nullable RetryPolicy retryPolicy, | ||
| @Nullable ExecutorService executorService) { | ||
| @Nullable ExecutorService executorService, | ||
| long maxResponseBodySize) { | ||
|
Member
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. JaegerRemoteSamplerBuilder.setMaxSamplingStrategyResponseBodySize validates bytes > 0. But the sender constructors (JdkHttpSender, OkHttpHttpSender, OkHttpGrpcSender) accept any long without
Member
Author
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. All the sender constructors are internal, and have a bunch of other unvalidated parameters which could be equally corrupted if a user goes around the guards. There's a conversation here discussing where to add additional null checks beyond the guarantees from nullaway. I think we should adopt a policy of adding additional null checks at the API boundaries, but trusting nullaway once we're within the walled garden of internal code. The same would apply to parameter validation, I think.
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. Well... setting directly to a low value like -1 or 0 will effectively bloc data export... All bodies will be bigger that that. |
||
| this.client = client; | ||
| this.endpoint = endpoint; | ||
| this.contentType = contentType; | ||
|
|
@@ -101,6 +103,7 @@ public final class JdkHttpSender implements HttpSender { | |
| this.executorService = executorService; | ||
| this.managedExecutor = false; | ||
| } | ||
| this.maxResponseBodySize = maxResponseBodySize; | ||
| } | ||
|
|
||
| JdkHttpSender( | ||
|
|
@@ -113,7 +116,8 @@ public final class JdkHttpSender implements HttpSender { | |
| @Nullable RetryPolicy retryPolicy, | ||
| @Nullable ProxyOptions proxyOptions, | ||
| @Nullable SSLContext sslContext, | ||
| @Nullable ExecutorService executorService) { | ||
| @Nullable ExecutorService executorService, | ||
| long maxResponseBodySize) { | ||
| this( | ||
| configureClient(sslContext, connectTimeout, proxyOptions), | ||
| endpoint, | ||
|
|
@@ -122,7 +126,8 @@ public final class JdkHttpSender implements HttpSender { | |
| timeout, | ||
| headerSupplier, | ||
| retryPolicy, | ||
| executorService); | ||
| executorService, | ||
| maxResponseBodySize); | ||
| } | ||
|
|
||
| private static ExecutorService newExecutor() { | ||
|
|
@@ -287,7 +292,19 @@ private static String responseStringRepresentation(HttpResponse<?> response) { | |
| private HttpResponse<byte[]> sendRequest( | ||
| HttpRequest.Builder requestBuilder, ByteBufferPool byteBufferPool) throws IOException { | ||
| try { | ||
| return client.send(requestBuilder.build(), HttpResponse.BodyHandlers.ofByteArray()); | ||
| return client.send( | ||
| requestBuilder.build(), | ||
| responseInfo -> | ||
| HttpResponse.BodySubscribers.mapping( | ||
| HttpResponse.BodySubscribers.ofInputStream(), | ||
| inputStream -> { | ||
| try (inputStream) { | ||
| return inputStream.readNBytes( | ||
| (int) Math.min(maxResponseBodySize, Integer.MAX_VALUE)); | ||
| } catch (IOException e) { | ||
| throw new UncheckedIOException(e); | ||
| } | ||
| })); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| throw new IllegalStateException(e); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ OkHttpGrpcSender createSender(String endpoint) { | |
| null, | ||
| null, | ||
| null, | ||
| null); | ||
| null, | ||
| Long.MAX_VALUE); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,7 @@ OkHttpHttpSender createSender(String endpoint) { | |
| null, | ||
| null, | ||
| null, | ||
| null); | ||
| null, | ||
| Long.MAX_VALUE); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.