Skip to content

Add support for event stream requests over RPC #2388

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

Merged
merged 1 commit into from
Apr 29, 2021

Conversation

rschmitt
Copy link
Contributor

@rschmitt rschmitt commented Apr 7, 2021

This commit adds support for RPC services that use client->server or
bidirectional event streaming. In the RPC formats (i.e. AWS JSON), the
marshalled request and response objects are sent as the first event in
the request and response stream respectively. This is different from the
REST formats, such as REST JSON, which bind the request and response
fields to non-payload positions (headers, URI, method, status code,
query string) when event streaming is used.

The implementation of this feature is mainly performed by a new global
interceptor, EventStreamInitialRequestInterceptor. The interceptor
detects when an initial-request event needs to be sent and transforms
the async response body by constructing the initial-request message
and prepending it to the event stream. Due to the high precedence of
global interceptors, any subsequent service or override interceptors
that run on the body will see the transformed version. This also applies
to the EventStreamAws4Signer, which will produce a signature over the
initial-request event.

I confirm that this pull request can be released under the Apache 2 license.

@codecov-io
Copy link

Codecov Report

Merging #2388 (4edce20) into master (a0b8ddd) will decrease coverage by 0.06%.
The diff coverage is 45.88%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2388      +/-   ##
============================================
- Coverage     77.69%   77.63%   -0.07%     
  Complexity      366      366              
============================================
  Files          1245     1247       +2     
  Lines         39294    39369      +75     
  Branches       3106     3112       +6     
============================================
+ Hits          30531    30563      +32     
- Misses         7277     7315      +38     
- Partials       1486     1491       +5     
Flag Coverage Δ Complexity Δ
unittests 77.63% <45.88%> (-0.07%) 0.00 <0.00> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
...erceptor/EventStreamInitialRequestInterceptor.java 0.00% <0.00%> (ø) 0.00 <0.00> (?)
...sdk/core/client/handler/ClientExecutionParams.java 95.45% <33.33%> (-4.55%) 0.00 <0.00> (ø)
...json/internal/marshall/JsonProtocolMarshaller.java 95.45% <60.00%> (-3.57%) 0.00 <0.00> (ø)
...ssdk/core/internal/async/AsyncStreamPrepender.java 64.28% <64.28%> (ø) 0.00 <0.00> (?)
...dk/codegen/poet/client/specs/JsonProtocolSpec.java 91.62% <66.66%> (-0.40%) 0.00 <0.00> (ø)
...sform/protocols/EventStreamJsonMarshallerSpec.java 83.33% <80.00%> (ø) 0.00 <0.00> (ø)
.../awscore/client/handler/AwsClientHandlerUtils.java 90.32% <100.00%> (+0.15%) 0.00 <0.00> (ø)
...sdk/protocols/json/BaseAwsJsonProtocolFactory.java 100.00% <100.00%> (ø) 0.00 <0.00> (ø)
...ternal/marshall/JsonProtocolMarshallerBuilder.java 93.33% <100.00%> (+1.02%) 0.00 <0.00> (ø)
...ore/interceptor/SdkInternalExecutionAttribute.java 100.00% <100.00%> (ø) 0.00 <0.00> (ø)
... and 7 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9f190d7...4edce20. Read the comment docs.

@dagnir
Copy link
Contributor

dagnir commented Apr 7, 2021

@rschmitt Awesome! Appreciate the contribution. We will need schedule some time on our side to review this so there will be a delay, but we'll have a look soon.

@rschmitt rschmitt force-pushed the rpc-event-streaming branch 6 times, most recently from bcf7e77 to b91234d Compare April 8, 2021 00:26
@rschmitt rschmitt force-pushed the rpc-event-streaming branch 2 times, most recently from 00f890a to 3232587 Compare April 9, 2021 23:58
@dagnir
Copy link
Contributor

dagnir commented Apr 21, 2021

I think for this change, it makes sense to add some codegen reftests, just to make sure we're actually generating things like .withInitialRequestEvent(true) for the json services. I think you can just a JSON-RPC specific test here

@dagnir
Copy link
Contributor

dagnir commented Apr 21, 2021

I think ideally, we'd leverage the marshallers to marshall the request directly to a suitable initial-request instead of "remarshalling" in the interceptor, but I'm fine with this approach as well since the marshaller route would require a bit more work in the codegen; we could save that for a second iteration in the future.

@dagnir
Copy link
Contributor

dagnir commented Apr 22, 2021

Integ tests seem to be failing. Can you take a look?

Locally, I'm seeing software.amazon.awssdk.services.s3.S3PresignerIntegrationTest fail, but there may be others. You can run them using

mvn clean install -P integration-tests

@rschmitt rschmitt force-pushed the rpc-event-streaming branch 2 times, most recently from 7049cc1 to 10226de Compare April 27, 2021 20:26
@rschmitt
Copy link
Contributor Author

Integ tests seem to be failing. Can you take a look?

Locally, I'm seeing software.amazon.awssdk.services.s3.S3PresignerIntegrationTest fail, but there may be others. You can run them using

mvn clean install -P integration-tests

I wasn't immediately able to reproduce this particular failure.

[INFO] Running software.amazon.awssdk.services.s3.S3PresignerIntegrationTest
[INFO] Tests run: 11, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.305 s - in software.amazon.awssdk.services.s3.S3PresignerIntegrationTest

@rschmitt rschmitt force-pushed the rpc-event-streaming branch from 10226de to 5baf8c2 Compare April 27, 2021 20:41
@rschmitt
Copy link
Contributor Author

I think for this change, it makes sense to add some codegen reftests, just to make sure we're actually generating things like .withInitialRequestEvent(true) for the json services. I think you can just a JSON-RPC specific test here

It looks like the JSON tests are actually rest-json tests; I need RPC tests, and I'm not sure any exist currently.

@rschmitt rschmitt force-pushed the rpc-event-streaming branch from 5baf8c2 to 09afe78 Compare April 27, 2021 21:57
@codecov-commenter
Copy link

codecov-commenter commented Apr 27, 2021

Codecov Report

Merging #2388 (09afe78) into master (4719dcb) will increase coverage by 0.04%.
The diff coverage is 88.57%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2388      +/-   ##
============================================
+ Coverage     77.71%   77.76%   +0.04%     
  Complexity      366      366              
============================================
  Files          1247     1249       +2     
  Lines         39471    39569      +98     
  Branches       3088     3099      +11     
============================================
+ Hits          30675    30769      +94     
- Misses         7311     7314       +3     
- Partials       1485     1486       +1     
Flag Coverage Δ Complexity Δ
unittests 77.76% <88.57%> (+0.04%) 366.00 <0.00> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
...sdk/core/client/handler/ClientExecutionParams.java 95.45% <33.33%> (-4.55%) 0.00 <0.00> (ø)
...json/internal/marshall/JsonProtocolMarshaller.java 95.61% <60.00%> (-3.45%) 0.00 <0.00> (ø)
...dk/codegen/poet/client/specs/JsonProtocolSpec.java 91.62% <66.66%> (-0.40%) 0.00 <0.00> (ø)
...sform/protocols/EventStreamJsonMarshallerSpec.java 83.33% <80.00%> (ø) 0.00 <0.00> (ø)
...ntstream/EventStreamInitialRequestInterceptor.java 87.09% <87.09%> (ø) 0.00 <0.00> (?)
.../awscore/client/handler/AwsClientHandlerUtils.java 90.32% <100.00%> (+0.15%) 0.00 <0.00> (ø)
...sdk/protocols/json/BaseAwsJsonProtocolFactory.java 100.00% <100.00%> (ø) 0.00 <0.00> (ø)
...ternal/marshall/JsonProtocolMarshallerBuilder.java 93.33% <100.00%> (+1.02%) 0.00 <0.00> (ø)
...ore/interceptor/SdkInternalExecutionAttribute.java 100.00% <100.00%> (ø) 0.00 <0.00> (ø)
...ssdk/core/internal/async/AsyncStreamPrepender.java 100.00% <100.00%> (ø) 0.00 <0.00> (?)
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 69546d5...09afe78. Read the comment docs.

@rschmitt rschmitt force-pushed the rpc-event-streaming branch 3 times, most recently from 6ebdcb0 to eaa1eba Compare April 28, 2021 21:50
Copy link
Contributor

@dagnir dagnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall!

This commit adds support for RPC services that use client->server or
bidirectional event streaming. In the RPC formats (i.e. AWS JSON), the
marshalled request and response objects are sent as the first event in
the request and response stream respectively. This is different from the
REST formats, such as REST JSON, which bind the request and response
fields to non-payload positions (headers, URI, method, status code,
query string) when event streaming is used.

The implementation of this feature is mainly performed by a new global
interceptor, `EventStreamInitialRequestInterceptor`. The interceptor
detects when an `initial-request` event needs to be sent and transforms
the async response body by constructing the `initial-request` message
and prepending it to the event stream. Due to the high precedence of
global interceptors, any subsequent service or override interceptors
that run on the body will see the transformed version. This also applies
to the `EventStreamAws4Signer`, which will produce a signature over the
`initial-request` event.
@rschmitt rschmitt force-pushed the rpc-event-streaming branch from eaa1eba to 94cc4cc Compare April 29, 2021 00:32
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

91.9% 91.9% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@dagnir dagnir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@dagnir dagnir merged commit 8763931 into aws:master Apr 29, 2021
aws-sdk-java-automation added a commit that referenced this pull request Feb 15, 2023
…f143a87fb

Pull request: release <- staging/49d2e997-95f3-4a8c-b933-d1af143a87fb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants