-
Notifications
You must be signed in to change notification settings - Fork 936
Sync streaming compression #4135
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
Sync streaming compression #4135
Conversation
Could you please update |
Updated to add description |
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.
Please add test cases to improve the coverage to 80% plus.https://sonarcloud.io/component_measures?id=aws_aws-sdk-java-v2&pullRequest=4135&metric=new_coverage&view=list
...ain/java/software/amazon/awssdk/core/internal/interceptor/RequestCompressionInterceptor.java
Outdated
Show resolved
Hide resolved
...ain/java/software/amazon/awssdk/core/internal/interceptor/RequestCompressionInterceptor.java
Outdated
Show resolved
Hide resolved
core/sdk-core/src/main/java/software/amazon/awssdk/core/compression/Compressor.java
Outdated
Show resolved
Hide resolved
core/sdk-core/src/main/java/software/amazon/awssdk/core/compression/Compressor.java
Outdated
Show resolved
Hide resolved
core/sdk-core/src/main/java/software/amazon/awssdk/core/compression/Compressor.java
Show resolved
Hide resolved
.../sdk-core/src/main/java/software/amazon/awssdk/core/internal/compression/GzipCompressor.java
Show resolved
Hide resolved
.../sdk-core/src/main/java/software/amazon/awssdk/core/internal/compression/GzipCompressor.java
Outdated
Show resolved
Hide resolved
.../sdk-core/src/main/java/software/amazon/awssdk/core/internal/compression/GzipCompressor.java
Outdated
Show resolved
Hide resolved
...ain/java/software/amazon/awssdk/core/internal/interceptor/RequestCompressionInterceptor.java
Outdated
Show resolved
Hide resolved
...dk-core/src/main/java/software/amazon/awssdk/core/internal/io/AwsCompressionInputStream.java
Outdated
Show resolved
Hide resolved
core/sdk-core/src/main/java/software/amazon/awssdk/core/compression/Compressor.java
Show resolved
Hide resolved
core/sdk-core/src/main/java/software/amazon/awssdk/core/compression/Compressor.java
Show resolved
Hide resolved
...ain/java/software/amazon/awssdk/core/internal/interceptor/RequestCompressionInterceptor.java
Outdated
Show resolved
Hide resolved
core/sdk-core/src/main/java/software/amazon/awssdk/core/compression/Compressor.java
Outdated
Show resolved
Hide resolved
.../sdk-core/src/main/java/software/amazon/awssdk/core/internal/compression/GzipCompressor.java
Outdated
Show resolved
Hide resolved
CompressionContentStreamProvider streamProvider = | ||
new CompressionContentStreamProvider(requestBody.contentStreamProvider(), compressor); | ||
return Optional.of(RequestBody.fromContentProvider(streamProvider, requestBody.contentType())); |
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.
It looks like this enables chunked encoding? Are we missing the Transfer-Encoding: chunked
header? Are we making sure that there is no Content-Length
header?
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.
adding Transfer-Encoding : chunked header
Modeling tools should throw an error for operations with both streaming
and requiresLength
, will remove the Content-Length
header just in case
…treaming-compression
input = updateContentEncodingHeader(input, compressor); | ||
return updateContentLengthHeader(input); | ||
// non-streaming OR transfer-encoding chunked | ||
if (!isStreaming(context) || isTransferEncodingChunked(input)) { |
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.
In which case we use isTransferEncodingChunked for non streaming ? I was assuming that transferEncodingChunked is always for streaming.
How is isTransferEncodingChunked() set on the input ? is it via user or on the model itself
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.
Correct, TE:chunked is only for streaming. This is checking for the 2 separate cases, not the combined case.
The specification states that when the request is already TE : chunked , we should compress the entire stream first, instead of compressing in chunks.
It is set in the marshallers: AbstractStreamingRequestMarshaller and JsonProtocolMarshaller
...ain/java/software/amazon/awssdk/core/internal/http/pipeline/stages/CompressRequestStage.java
Outdated
Show resolved
Hide resolved
...ain/java/software/amazon/awssdk/core/internal/http/pipeline/stages/CompressRequestStage.java
Outdated
Show resolved
Hide resolved
...dk-core/src/main/java/software/amazon/awssdk/core/internal/io/AwsCompressionInputStream.java
Outdated
Show resolved
Hide resolved
...dwatch/src/it/java/software/amazon/awssdk/services/cloudwatch/CloudWatchIntegrationTest.java
Show resolved
Hide resolved
https://sonarcloud.io/component_measures?id=aws_aws-sdk-java-v2&pullRequest=4135&metric=new_coverage&view=list |
This was run before the latest commits. Looks like a Github issue, as the commits were missing from the PR (had to change base branch to fix). Retried the checks through CodeBuild, running |
core/sdk-core/src/main/java/software/amazon/awssdk/core/compression/CompressionType.java
Outdated
Show resolved
Hide resolved
.../sdk-core/src/main/java/software/amazon/awssdk/core/internal/http/AmazonAsyncHttpClient.java
Show resolved
Hide resolved
...ain/java/software/amazon/awssdk/core/internal/http/pipeline/stages/CompressRequestStage.java
Show resolved
Hide resolved
...ain/java/software/amazon/awssdk/core/internal/http/pipeline/stages/CompressRequestStage.java
Outdated
Show resolved
Hide resolved
|
||
long contentLength = Long.parseLong(input.firstMatchingHeader("Content-Length").orElse("0")); | ||
return contentLength >= minimumCompressionThreshold; | ||
int requestSize = SdkBytes.fromInputStream(input.contentStreamProvider().newStream()).asByteArray().length; |
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.
We are reading the entire stream here to get the request size,
We should avoid intermediate reading of the streams this can cause performance impact , can we discuss this with team ?
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.
the content length header isn't set yet for nonstreaming operations. not sure how we would get the content length if not by reading the stream, can discuss with team
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.
updated method to check for content length header first, and if not present, then read the stream to determine length
...-core/src/test/java/software/amazon/awssdk/core/internal/compression/GzipCompressorTest.java
Show resolved
Hide resolved
...rated-classes-test/src/test/java/software/amazon/awssdk/services/RequestCompressionTest.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
@Override | ||
public int hashCode() { |
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.
We can improve the Coverage of newly added classes by performing EqualsVerifier test , this will make sure equals and hashcode are tested
(generic comment for newly added classes as part of this feature)
import nl.jqno.equalsverifier.EqualsVerifier;
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.
added tests for CompressionType and RequestCompressionConfiguration
SonarCloud Quality Gate failed.
|
…4bbc94a63 Pull request: release <- staging/06b7e1ba-f147-418e-94ce-8504bbc94a63
Motivation and Context
Implementing sync streaming compression
The
ContentStreamProvider
of the originalRequestBody
will be wrapped byCompressionContentStreamProvider
, which will wrap the underlyingInputStream
withAwsCompressionInputStream
. TheAwsCompressionInputStream
overridesread(byte[] b, int off, int len)
to return compressed chunks.Modifications
Added new class
AwsChunkedEncodingInputStream
to compress request in chunks.Added overloaded
compress()
methods toCompressor
andGzipCompressor
to compressbyte[]
andByteBuffer
.Renamed
DecodedStreamBuffer
toUnderlyingStreamBuffer
for more general useTesting
added tests
Screenshots (if appropriate)
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License