events: fix Event Ruler to not evaluate the full payload #12394
Merged
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.
Motivation
As reported by #12390, when evaluate large payload for
PutEvents
, LocalStack would fail. I could reproduce the issue and saw LocalStack consumes as much as 20GB of memory while trying to evaluate the payload given by the user.This payload was very complex, with lots of nested dictionaries and list. List are "exploding" the complexity, creating "or" conditions and new "branches" to evaluate.
This is because we're using recursion to evaluate EventPattern against payload, and we would try to get the event payload in a flat shape to be able to be evaluated against the Pattern (due to how AWS treats the
.
notation).I've added some conditions checks to only evaluate the payload when relevant to the Event Pattern, and to not evaluate "branches" of the payload. This fixes the issue and the memory usage, as payloads now stay "simple" and without the bounds.
I've also added some small unit tests because the doc strings were getting a bit too big to explain all the behavior.
\cc @cloutierMat as we worked on this together for SNS
fixes #12390
See https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-pattern.html
Reading again, this should have been considered from the start with the following (my bad!):
Changes
We will need to port this fix to the SNS Filter policy engine as well, I'll tackle that in a follow up.