Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add streaming types to ASF scaffold and APIs #6552

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 7 commits into from
Aug 3, 2022
Merged

Conversation

thrau
Copy link
Member

@thrau thrau commented Jul 29, 2022

This PR updates ASF to correctly handle smithy streaming types. This is one of the last big changes to ASF, and will unblock the S3 migration.

The changes include:

  • updated scaffold to generate streaming types (see details)
  • re-generated community APIs
  • updated serializer and parser to deal with streaming types
  • added several tests on different layers
  • update lambda and API gateway providers /cc @dfangl @dominikschubert
  • changed the MetricHandler a bit (see details below) /cc @steffyP

some details on the API

After several discussions with @alexrashed, we decided not to make the service-level shapes the streaming types, but to only type hint the members of request/response objects.

  • For Requests, which are set by the server, we specify typing.IO[bytes], which will essentially be set to werkzeug.Request.stream by the parser. This will require the most changes, as we need to update all implementing services that expect payload to be bytes, to use payload.read() which will be a stream.
  • For Responses, which are set by the developer, we specify Union[bytes, IO[bytes], Iterable[bytes], making it possible to deal with the three cases outlined in implement AWS streaming trait for ASF #6527. These three types are also supported by the werkzeug.Response object, so nothing needs to be done in the serializer, and no changes are necessary im services.

metric handler change

with the new streaming trait, ServiceRequest dictionaries can contain file-like or other IO objects that cannot be serialized. in record_parsed_request we were copying the entire request using deep copy, and that was now raising errors. on certain requests.

it seems we weren't really using the entire request, but just collecting the names of the parameters that were in the request, so i simplified the logic to just collect the parameter names rather than the entire request, which is now a harmless call to list(request.keys()).

if we at some point need the entire request in the metric collection, we'll need to revisit this change.

limitations

http request IO is still a problem. when you consume an incoming request payload, e.g., in s3 PutObject, using body.read(), you are consuming the stream underlying the http request, which is shared with werkzeug's Request object. that means, if you at a later point want to call request.data on the request object, you'll get an empty byte buffer back. although this is expected and correct behavior, it's also very inconvenient and i can see a lot of hours going into debugging of weird "why is my request empty" issues.

since quite a bit of the code base still builds on the assumption of always having access to the raw http request data, we may need to make some compromises with respect to performance and memory usage. ideally, we never read from the stream until we need it, because there's always a chance that we are going to proxy large payloads to some backend (like invoking a lambda), in which case you don't want to load everything into memory, keep it there, and then flush it to the outgoing socket again. but if you want reliable access to request.data, even though we've previously run body.read(), then we're going to have to store the stream data somewhere, and make it seekable, e.g., through TemporarySpooledFiles, which would solve the problem of loading large payloads into memory (if they exceed a certain size the file is rolled to disk, otherwise it is kept in memory), but obviously still has the overhead when proxying. 🤷

fixes #6527

@thrau thrau requested a review from alexrashed as a code owner July 29, 2022 14:57
@thrau thrau temporarily deployed to localstack-ext-tests July 29, 2022 14:57 Inactive
@thrau thrau force-pushed the asf-streaming-api branch from bfe6bad to 8cd4e0e Compare July 29, 2022 14:59
@thrau thrau temporarily deployed to localstack-ext-tests July 29, 2022 15:00 Inactive
@coveralls
Copy link

coveralls commented Jul 29, 2022

Coverage Status

Coverage decreased (-0.01%) to 91.573% when pulling e2bc2fd on asf-streaming-api into 736e7ad on master.

@github-actions
Copy link

github-actions bot commented Jul 29, 2022

LocalStack integration with Pro

       3 files         3 suites   1h 4m 40s ⏱️
1 163 tests 1 121 ✔️ 42 💤 0
1 524 runs  1 451 ✔️ 73 💤 0

Results for commit 0756cc0.

♻️ This comment has been updated with latest results.

@thrau thrau force-pushed the asf-streaming-api branch from 8cd4e0e to 5bb8dfa Compare July 29, 2022 16:38
@thrau thrau temporarily deployed to localstack-ext-tests July 29, 2022 16:38 Inactive
@thrau thrau temporarily deployed to localstack-ext-tests July 29, 2022 19:47 Inactive
@thrau thrau temporarily deployed to localstack-ext-tests July 29, 2022 20:03 Inactive
@thrau thrau marked this pull request as draft July 29, 2022 20:09
@thrau thrau temporarily deployed to localstack-ext-tests July 29, 2022 20:24 Inactive
@thrau thrau requested a review from steffyP July 29, 2022 20:40
@thrau thrau force-pushed the asf-streaming-api branch from 7b61188 to 743b056 Compare July 29, 2022 20:53
@thrau thrau temporarily deployed to localstack-ext-tests July 29, 2022 20:54 Inactive
@thrau thrau temporarily deployed to localstack-ext-tests July 29, 2022 23:44 Inactive
@thrau thrau force-pushed the asf-streaming-api branch from e6f111f to b826826 Compare July 29, 2022 23:59
@thrau thrau temporarily deployed to localstack-ext-tests July 30, 2022 00:00 Inactive
@thrau thrau force-pushed the asf-streaming-api branch from b826826 to 61e3336 Compare July 30, 2022 13:11
@thrau thrau temporarily deployed to localstack-ext-tests July 30, 2022 13:11 Inactive
@thrau thrau marked this pull request as ready for review July 30, 2022 19:29
@thrau thrau temporarily deployed to localstack-ext-tests July 30, 2022 20:12 Inactive
Copy link
Member

@alexrashed alexrashed left a comment

Choose a reason for hiding this comment

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

Really nice set of changes! This is basically fixing the last real big limitation we had in ASF! 🥳
I only had really small nitpicks and only on some tests.
It's cool that the parser and serializer basically didn't need to be changed.
The newly generated API seems great, and I double-checked that all method signatures that are implemented have also been adjusted.

@alexrashed alexrashed mentioned this pull request Aug 1, 2022
@thrau thrau force-pushed the asf-streaming-api branch from e2bc2fd to ddd3fbf Compare August 3, 2022 14:26
@thrau thrau temporarily deployed to localstack-ext-tests August 3, 2022 14:26 Inactive
@thrau
Copy link
Member Author

thrau commented Aug 3, 2022

tested merge with #6583 and seems to work fine

@thrau thrau force-pushed the asf-streaming-api branch from ddd3fbf to 0756cc0 Compare August 3, 2022 14:55
@thrau thrau temporarily deployed to localstack-ext-tests August 3, 2022 14:56 Inactive
Copy link
Member

@steffyP steffyP left a comment

Choose a reason for hiding this comment

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

metric changes look good! 😄 thank you!

@thrau thrau merged commit 33ad9a8 into master Aug 3, 2022
@thrau thrau deleted the asf-streaming-api branch August 3, 2022 17:49
@localstack localstack locked and limited conversation to collaborators Aug 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement AWS streaming trait for ASF
4 participants