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

fix: event parsing iterator #2829

Merged

Conversation

yenfryherrerafeliz
Copy link
Contributor

The EventParsingIterator implementation does not parse correctly events when their payload do not have the eventpayload property set. The current behavior is that if said property "eventpayload" is not present then it fallback to extracting the value from the headers, but this is not a reliable method for parsing event streams since seems that not all services uses this pattern to provide the events. One example is the InvokeModelWithResponseStream operation from bedrock-runtime service. To fix this we check if the event key is set in the headers, and if so then we pick the value from the headers, otherwise we set the event key value based on the event payload.

Issues #2817, #2787

Description of changes:

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
Member

@stobrien89 stobrien89 left a comment

Choose a reason for hiding this comment

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

Looking good so far, just a few suggestions. Let's get the tests ready and go from there.

src/Api/Parser/EventParsingIterator.php Show resolved Hide resolved
src/Api/Parser/EventParsingIterator.php Outdated Show resolved Hide resolved
src/Api/Parser/EventParsingIterator.php Outdated Show resolved Hide resolved
@yenfryherrerafeliz yenfryherrerafeliz force-pushed the fix_event_parsing_iterator branch 4 times, most recently from 177f2f8 to 96b045e Compare December 1, 2023 17:59
Copy link
Member

@stobrien89 stobrien89 left a comment

Choose a reason for hiding this comment

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

Requested a few changes

tests/Api/Parser/EventParsingIteratorTest.php Show resolved Hide resolved
tests/Api/Parser/EventParsingIteratorTest.php Outdated Show resolved Hide resolved
tests/Api/Parser/EventParsingIteratorTest.php Outdated Show resolved Hide resolved
tests/Api/Parser/EventParsingIteratorTest.php Outdated Show resolved Hide resolved
tests/Api/Parser/EventParsingIteratorTest.php Outdated Show resolved Hide resolved
tests/Api/Parser/EventParsingIteratorTest.php Outdated Show resolved Hide resolved
tests/Api/Parser/EventParsingIteratorTest.php Outdated Show resolved Hide resolved
tests/Api/Parser/EventParsingIteratorTest.php Outdated Show resolved Hide resolved
tests/Api/Parser/EventParsingIteratorTest.php Show resolved Hide resolved
tests/Api/Parser/EventParsingIteratorTest.php Outdated Show resolved Hide resolved
@yenfryherrerafeliz yenfryherrerafeliz force-pushed the fix_event_parsing_iterator branch from 96b045e to b092a56 Compare December 4, 2023 04:15
@stobrien89 stobrien89 marked this pull request as ready for review December 4, 2023 19:26
@yenfryherrerafeliz yenfryherrerafeliz force-pushed the fix_event_parsing_iterator branch from b092a56 to 52874eb Compare December 11, 2023 16:18
@yenfryherrerafeliz yenfryherrerafeliz force-pushed the fix_event_parsing_iterator branch from 52874eb to 08e961d Compare December 11, 2023 20:55
Copy link
Member

@stobrien89 stobrien89 left a comment

Choose a reason for hiding this comment

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

Just needs a changelog entry 🚢

@yenfryherrerafeliz yenfryherrerafeliz force-pushed the fix_event_parsing_iterator branch from 08e961d to 1dde0de Compare December 11, 2023 23:12
The EventParsingIterator implementation does not parse correctly events when their payload do not have the eventpayload property set. The current behavior is that if said property "eventpayload" is not present then it fallback to extracting the value from the headers, but this is not a reliable method for parsing event streams since seems that not all services uses this pattern to provide the events. One example is the InvokeModelWithResponseStream operation from bedrock-runtime service. To fix this we pretty much followed the specs found in the smithy reference: https://smithy.io/2.0/spec/streaming.html#eventpayload-trait#id6, which explains that when eventpayload and eventheader is not set for any of the members of the shape then, the payload  itself should be considered as the top level shape structure to be parsed.
The test implementation for eventstream  have also been refactored as follow:
 - We now have to specify the rest protocol that the input test data will be using, and based on that protocol we have a factory method to create either a rest xml or rest JSON parser.
 - Instead of validating if a specific member is present to validate if the parsed data type is the correct one, we now validate each parsed member to make sure they are all parsed into the expected data type.
@yenfryherrerafeliz yenfryherrerafeliz force-pushed the fix_event_parsing_iterator branch from 1dde0de to 55dfcfe Compare December 12, 2023 17:14
@stobrien89 stobrien89 merged commit ba5192a into aws:master Dec 12, 2023
15 checks passed
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.

2 participants