Skip to content
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

Avoid exposing aws_smithy_http::event_stream::receiver::Receiver in SDK's public API #3114

Merged
merged 15 commits into from
Nov 7, 2023

Conversation

ysaito1001
Copy link
Contributor

@ysaito1001 ysaito1001 commented Oct 30, 2023

Motivation and Context

Implements #3100

Description

Currently, we expose aws_smithy_http::event_stream::Receiver in generated SDKs, as shown in the following S3's example (see a generated diff for tmp-codegen-diff/aws-sdk/sdk/s3/src/operation/select_object_content/_select_object_content_output.rs):

pub struct SelectObjectContentOutput {
    <p>The array of results.</p>
    pub payload: ::aws_smithy_http::event_stream::Receiver<
        crate::types::SelectObjectContentEventStream,
        crate::types::error::SelectObjectContentEventStreamError,
    >,
...

This PR wraps Receiver in a new-type, called EventReceiver, which then supports pub async fn recv method whose signature is the same as aws_smithy_http::event_stream::Receiver::recv.

Testing

Relied on existing tests (e.g. s3 and transcribestreaming integration tests cover uses cases affected by this change).

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@jdisanti
Copy link
Collaborator

Do you think we should also wrap the EventStreamSender? Is there an advantage to that?

It seems like one of the advantages to wrapping the receiver is that we get to properly hide methods such as try_recv_initial. Wrapping the sender would allow for adding such methods in the future.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@ysaito1001
Copy link
Contributor Author

ysaito1001 commented Oct 31, 2023

Do you think we should also wrap the EventStreamSender? Is there an advantage to that?

It seems like one of the advantages to wrapping the receiver is that we get to properly hide methods such as try_recv_initial. Wrapping the sender would allow for adding such methods in the future.

Yeah, I can see value in doing that, benefiting the event sender the same way it benefited the event receiver. Two things:

  • It will be MessageStreamAdapter that'll be wrapped in a new-type EventSender, and EventSender will probably have a method pub async send whose implementation likely re-uses today's MessageStreamAdapter::poll_next.
  • Since we currently do not expose MessageStreamAdapter in public API within a stable crate, it can be done later outside this PR in a non-breaking fashion.

So all in all, I think it's worth tracking it via an issue. Will create one. #3118 created.

Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@ysaito1001 ysaito1001 marked this pull request as ready for review October 31, 2023 18:05
@ysaito1001 ysaito1001 requested review from a team as code owners October 31, 2023 18:05
@ysaito1001 ysaito1001 added breaking-change This will require a breaking change needs-sdk-review labels Oct 31, 2023
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

github-merge-queue bot pushed a commit that referenced this pull request Nov 6, 2023
…thy-eventstream` to `aws-smithy-types` (#3139)

## Motivation and Context
Fixes the following statement in
#3114

> A notable breaking change is the error type of the new recv method.
Previously, it was [SdkError<E,
RawMessage>>](https://docs.rs/aws-smithy-http/0.57.0/aws_smithy_http/event_stream/struct.Receiver.html#method.recv)
but it is now a BoxError. This means that upon an event receive error,
customers can only show what the error is, but not match on it and take
some actions.

so that the `recv` method on a new-type wrapper
`aws_smithy_http::event_stream::Receiver` can expose `SdkError<E,
RawMessage>>` in public API. It is the responsibility of the above PR to
move
[RawMessage](https://github.com/awslabs/smithy-rs/blob/c7f0d5dc33937d65841d74b5b828cc77ed1d2db4/rust-runtime/aws-smithy-http/src/event_stream/receiver.rs#L92-L98)
from `aws-smithy-http` to `aws-smithy-types` but doing so first requires
`Message` to be moved to `aws-smithy-types`, hence this PR.


## Description
Moving `Message` to `aws-smithy-types` also requires moving the types it
depends upon, namely `Header`, `HederValue`, and `StrBytes`. However,
their serialization/deserialization methods (`read_from` and `write_to`)
remain in `aws-smithy-eventstream` and they are converted to free
functions, with the aim of moving things as minimally as possible.

`aws-smithy-eventstream` has fuzz testing. It previously implemented the
`Arbitrary` trait for moved types, but since they are now in
`aws-smithy-types`, we need to have newtypes for them to enable the
trait due to the orphan rules. A newly added module
`aws-smithy-eventstream::arbitrary` is exactly for that purpose.

## Testing
Relied on the existing tests.

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
Copy link

github-actions bot commented Nov 6, 2023

A new generated diff is ready to view.

A new doc preview is ready to view.

@ysaito1001 ysaito1001 added this pull request to the merge queue Nov 7, 2023
Merged via the queue into main with commit f9c0526 Nov 7, 2023
41 checks passed
@ysaito1001 ysaito1001 deleted the ysaito/new-type-event-stream-receiver branch November 7, 2023 03:09
aws-sdk-rust-ci pushed a commit to awslabs/aws-sdk-rust that referenced this pull request Nov 16, 2023
…rom `aws-smithy-eventstream` to `aws-smithy-types` (#3139)

## Motivation and Context
Fixes the following statement in
smithy-lang/smithy-rs#3114

> A notable breaking change is the error type of the new recv method.
Previously, it was [SdkError<E,
RawMessage>>](https://docs.rs/aws-smithy-http/0.57.0/aws_smithy_http/event_stream/struct.Receiver.html#method.recv)
but it is now a BoxError. This means that upon an event receive error,
customers can only show what the error is, but not match on it and take
some actions.

so that the `recv` method on a new-type wrapper
`aws_smithy_http::event_stream::Receiver` can expose `SdkError<E,
RawMessage>>` in public API. It is the responsibility of the above PR to
move
[RawMessage](https://github.com/awslabs/smithy-rs/blob/c7f0d5dc33937d65841d74b5b828cc77ed1d2db4/rust-runtime/aws-smithy-http/src/event_stream/receiver.rs#L92-L98)
from `aws-smithy-http` to `aws-smithy-types` but doing so first requires
`Message` to be moved to `aws-smithy-types`, hence this PR.

## Description
Moving `Message` to `aws-smithy-types` also requires moving the types it
depends upon, namely `Header`, `HederValue`, and `StrBytes`. However,
their serialization/deserialization methods (`read_from` and `write_to`)
remain in `aws-smithy-eventstream` and they are converted to free
functions, with the aim of moving things as minimally as possible.

`aws-smithy-eventstream` has fuzz testing. It previously implemented the
`Arbitrary` trait for moved types, but since they are now in
`aws-smithy-types`, we need to have newtypes for them to enable the
trait due to the orphan rules. A newly added module
`aws-smithy-eventstream::arbitrary` is exactly for that purpose.

## Testing
Relied on the existing tests.

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
ysaito1001 added a commit that referenced this pull request Dec 11, 2023
## Motivation and Context
Adds re-export for `EventReceiver` in a generated client crate

## Description
`EventReceiver` was added in
#3114 but the struct itself
could not be referenced as `pub`. Our SDK integration tests did not
break in the said PR because they only called the `next` method on it
and never referred to that struct name.

This PR adds a re-export for `EventReceiver` in case customers need to
refer to the name in their code.

## Testing
Added a unit test and edited a `transcribestreaming` integration test to
verify the re-export.

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

---------

Co-authored-by: AWS SDK Rust Bot <aws-sdk-rust-primary@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change This will require a breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants