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
Feat: Eventbridge v2: Add pattern matching #10664
Feat: Eventbridge v2: Add pattern matching #10664
Conversation
LocalStack Community integration with Pro 2 files ±0 2 suites ±0 1h 37m 53s ⏱️ -55s Results for commit aae673a. ± Comparison against base commit 0f7d49f. This pull request removes 5 and adds 5 tests. Note that renamed tests count towards both.
This pull request skips 1 test.
♻️ This comment has been updated with latest results. |
except KeyError: | ||
LOG.error(f"Error deleting target worker {target_arn}.") | ||
|
||
def _put_entries( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename to a more meaningful function name, also include docstring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe dispatch_events, deliver_events, ...?
The API is called put_entries but that's from a user's perspective. Within the EventBridge service, using active terminology such as dispatch makes more sense. Just reading over the AWS docs and drafting a docstring might help decide upon a better name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed in: da0f12a
d47fceb
to
4153a06
Compare
a5ce64c
to
24ed318
Compare
bc536f6
to
08b80f9
Compare
6c48233
to
b011d8a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Can we avoid duplicating the InternalInvalidEventPatternException
before merging?
There are also a couple of enabled tests, which still have the unknown
marker (see comments).
"time": get_event_time(event), | ||
"region": region, | ||
"resources": event.get("Resources", []), | ||
"detail": json.loads(event.get("Detail", "{}")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the AWS docs, detail
should always be a JSON object. Hence, I guess we can safely assume that other strings or base64-encoded content is not expected here, right?
detail — A JSON object that contains information about the event. For more information about what can be included in this field, see Event message detail field.
} | ||
) | ||
return failed_entries | ||
event_pattern = rule.event_pattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super nit: event_pattern_str
or str typing could clarify the type here (especially given we have both versions in our codebase)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now for the v2 provider, since we use only the Java matching engine we only ever have event pattern as a string, we don't parse it into a JSON object. In addition, the API string type is called EventPattern
, therefor I would keep it without the str suffix.
Also, I think the naming convention of match_rule is misleading since we don't match the rule but the rule_pattern and only pass in the pattern. We should think of updating this in the event_ruler
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now for the v2 provider, since we use only the Java matching engine we only ever have event pattern as a string, we don't parse it into a JSON object. In addition, the API string type is called EventPattern, therefor I would keep it without the str suffix.
It's a good thing we don't need JSON parsing for the event pattern anymore in the new provider, but right one line below we have the counter-example of transforming an event
into an event_str
😬 . Looking over the many implementations in LocalStack, this str
vs json
duality was very confusing, and being explicit can help to clarify the API usage here.
How do you think does rule
differ from rule_pattern
?
the naming convention of match_rule is misleading since we don't match the rule but the rule_pattern and only pass in the pattern.
Background
The terminology Ruler.matchesRule(event, rule)
in the event_ruler.py
follows the official AWS event-ruler and aims to be more generic than just for EventBridge. Notice that different services use slightly different terminology:
- Amazon EventBridge event patterns
- Amazon EventBridge Pipes filtering, also called
FilterCriteria
- Event Source Mapping Lambda event filtering, also called
FilterCriteria
- Amazon SNS message filtering, also called
filter policy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
json vs strg makes sense - the old fallacy if you build it you know it and think its obvious to everyone else
d2b4586
to
aae673a
Compare
Motivation
This PR adds pattern matching to distribute incoming events based on event bus specified in the event, rules in the matching event bus and matches the patterns in the rules.
It uses the existing rule matching algorithm from v1, which is limited, e.g. patterns with
anything but
orexists = True
.Changes
Add parsing for event pattern to a dictionary, and add validating of pattern.
Add correct formatting of events and add additional keys.
Add API method to test event pattern using same matching algorithm as for distributing events to targets.
Remove skip markers from now passing tests.
Testing
Set the env variable
PROVIDER_OVERRIDE_EVENTS=v2
and run tests in events folder. All unsupported tests have the appropriate skip markers.