add streaming types to ASF scaffold and APIs#6552
Merged
Conversation
alexrashed
approved these changes
Aug 1, 2022
Member
alexrashed
left a comment
There was a problem hiding this comment.
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.
Closed
e2bc2fd to
ddd3fbf
Compare
Member
Author
|
tested merge with #6583 and seems to work fine |
ddd3fbf to
0756cc0
Compare
steffyP
approved these changes
Aug 3, 2022
Member
steffyP
left a comment
There was a problem hiding this comment.
metric changes look good! 😄 thank you!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
MetricHandlera bit (see details below) /cc @steffyPsome 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.
typing.IO[bytes], which will essentially be set towerkzeug.Request.streamby the parser. This will require the most changes, as we need to update all implementing services that expectpayloadto bebytes, to usepayload.read()which will be a stream.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 thewerkzeug.Responseobject, so nothing needs to be done in the serializer, and no changes are necessary im services.metric handler change
with the new streaming trait,
ServiceRequestdictionaries can contain file-like or other IO objects that cannot be serialized. inrecord_parsed_requestwe 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, usingbody.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 callrequest.dataon 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 runbody.read(), then we're going to have to store the stream data somewhere, and make it seekable, e.g., throughTemporarySpooledFiles, 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