8000 eventbridge: fix handling of list elements by baermat · Pull Request #10600 · localstack/localstack · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

eventbridge: fix handling of list elements #10600

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 5 commits into from
Apr 8, 2024
Merged

Conversation

baermat
Copy link
Member
@baermat baermat commented Apr 3, 2024

Motivation

A customer reported internal errors when submitting events that contained a list within a dict. This PR adds the presumably correct behavior as AWS does it (checked with 2 validated tests). During the replication, another issue surfaced in our own testing code: The function that collects the event logs will also discard actual messages if the message happens to contain certain key words, while we should only discard messages that start with said keywords.
/cc @maxhoheiser

Changes

  • Fixes handling of list entries in dicts in eventbridge
  • Fixes the discarding of status event logs

TODO

What's left to do:

  • For some reason, no entry is created in validations.json for test_put_events_with_target_lambda_list_entry?

@baermat baermat added the semver: patch Non-breaking changes which can be included in patch releases label Apr 3, 2024
@baermat baermat marked this pull request as ready for review April 3, 2024 22:38
@baermat baermat requested a review from joe4dev April 3, 2024 22:54
@baermat baermat force-pushed the events-fix-list-entries branch from 1162b52 to 0465c03 Compare April 4, 2024 10:05
Copy link
github-actions bot commented Apr 4, 2024

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 32m 2s ⏱️ + 3m 41s
2 834 tests +3  2 550 ✅ +3  284 💤 ±0  0 ❌ ±0 
2 836 runs  +3  2 550 ✅ +3  286 💤 ±0  0 ❌ ±0 

Results for commit 9326b86. ± Comparison against base commit 389d942.

♻️ This comment has been updated with latest results.

Copy link
Member
@joe4dev joe4dev left a comment

Choose a reason for hiding this comment

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

Thank you @baermat for tackling this tricky event pattern matching 🙏

@baermat Can you apply the patch to the refactored version in the new utils.py after rebasing to resolve the merge conflicts?
Sorry for the inconvenience after merging #10599. I think it makes sense to have the test suite available to catch any potential regressions.

You can make use of the new test suite added in #10599. Use the test test_test_event_pattern and uncomment any "Failing tests" that this PR fixes or add a new scenario much easier by creating a file under event_pattern_templates. Check out my Demo from last Thursday for details. It also links the relevant Notion backlog items with more information.

or raw_message.startswith("END")
or raw_message.startswith(
"REPORT"
) # necessary until tail is updated in docker images. See this PR:
8000
Copy link
Member

Choose a reason for hiding this comment

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

That PR links a patch from 2015 🤔 Is there a better open issue we could link to track this?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have to admit that I didn't check this PR at all. The fix here is mostly that a message can contain the words we filter for by accident (which is exactly what happened), while we should only filter for these words at the start

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for the clarification. Would be a nice-to-have clarifying comment 👍

@@ -1,4 +1,7 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why the new test test_put_events_with_target_lambda_list_entry does not show up here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was wondering the same thing really, no idea

Copy link
Member

Choose a reason for hiding this comment

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

Looks fixed now :)


assert "FailedEntryCount" in rs
assert "FailedEntries" in rs
assert rs["FailedEntryCount"] == 0
Copy link
Member

Choose a reason for hiding this comment

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

good to fail early here 👍

@@ -573,8 +573,11 @@ def filter_event(event_pattern_filter: dict[str, Any], event: dict[str, Any]):
elif isinstance(value, (str, dict)):
try:
value = json.loads(value) if isinstance(value, str) else value
if isinstance(value, dict) and not filter_event(value, event_value):
return False
if isinstance(event_value, list):
Copy link
Member

Choose a reason for hiding this comment

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

nice addition of being able to handle lists of operators following the AND logic 👍 👏

@baermat baermat force-pushed the events-fix-list-entries branch from 0465c03 to b324a55 Compare April 8, 2024 17:45
@baermat baermat requested a review from joe4dev April 8, 2024 18:56
Copy link
Member
@joe4dev joe4dev left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Thank you @baermat 👏👏👏

I added a regression test case to the new test suite to simplify the unification of all our implementations.

@@ -70,13 +70,16 @@ def matches_event(event_pattern: dict[str, any], event: dict[str, Any]) -> bool:
):
return False

# 3. recursively call filter_event(..) for dict types
# 3. recursively call matches_event(..) for dict types
Copy link
Member

Choose a reason for hiding this comment

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

nice catch. Thank you @baermat 🙏

or raw_message.startswith("END")
or raw_message.startswith(
"REPORT"
) # necessary until tail is updated in docker images. See this PR:
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for the clarification. Would be a nice-to-have clarifying comment 👍

@@ -1,4 +1,7 @@
{
Copy link
Member

Choose a reason for hiding this comment

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

Looks fixed now :)

@baermat baermat merged commit 5b15be1 into master Apr 8, 2024
30 checks passed
@baermat baermat deleted the events-fix-list-entries branch April 8, 2024 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: patch Non-breaking changes which can be included in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0