Sync streaming compression#4135
Sync streaming compression#4135davidh44 wants to merge 28 commits intofeature/master/request-compressionfrom
Conversation
|
Could you please update |
Updated to add description |
There was a problem hiding this comment.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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
ContentStreamProviderof the originalRequestBodywill be wrapped byCompressionContentStreamProvider, which will wrap the underlyingInputStreamwithAwsCompressionInputStream. TheAwsCompressionInputStreamoverridesread(byte[] b, int off, int len)to return compressed chunks.Modifications
Added new class
AwsChunkedEncodingInputStreamto compress request in chunks.Added overloaded
compress()methods toCompressorandGzipCompressorto compressbyte[]andByteBuffer.Renamed
DecodedStreamBuffertoUnderlyingStreamBufferfor more general useTesting
added tests
Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License