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
Feature: Eventbridge v2: Add input path #10733
base: master
Are you sure you want to change the base?
Conversation
LocalStack Community integration with Pro 2 files ±0 2 suites ±0 1h 39m 10s ⏱️ + 2m 10s Results for commit f05b155. ± Comparison against base commit 84f4a31a. This pull request removes 1 and adds 4 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
03803b1
to
76e25d8
Compare
8efe19e
to
9c8e0c6
Compare
50418c9
to
96012b4
Compare
968a98c
to
f05b155
Compare
|
||
def _create_sqs_events_target(queue_name: str | None = None) -> tuple[str, str]: | ||
if not queue_name: | ||
queue_name = f"tests-queue-{short_uid()}" | ||
sqs_client = aws_client.sqs | ||
queue_url = sqs_client.create_queue(QueueName=queue_name)["QueueUrl"] |
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.
This on purpose does not use the sqs_create_queue
fixture here, since it would need to be moved to helper functions because no cleanup and thus no factory would be required, which in turn would not valid this to be a fixture. This would in turn require passing in the aws_client as input.
I believe it is easier to read if the queue is created with the boot client here directly.
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.
ok, fair point 👍
Why is no cleanup required here? Wouldn't the factory remove the need for an explicit cleanup after the yield here? It might have to do with the proper cleanup order 🤔
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.
My main concern is regarding the introduction of an implicit transitive dependency and I'm not quite sure about the typings 😕
Otherwise, it looks good now 👍
localstack/services/events/target.py
Outdated
from localstack.utils.strings import to_bytes | ||
from localstack.utils.time import now_utc | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def transform_event_with_target_input_path( | ||
input_path: TargetInputPath, event: PutEventsRequestEntry | ||
) -> PutEventsRequestEntry: |
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.
The type PutEventsRequestEntry
might be misleading because the event has not much to do with a request here anymore 🤔
localstack/services/events/target.py
Outdated
def transform_event_with_target_input_path( | ||
input_path: TargetInputPath, event: PutEventsRequestEntry | ||
) -> PutEventsRequestEntry: | ||
event = extract_jsonpath(event, input_path) |
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.
nice utils reuse ✨
Rule=rule_name, | ||
EventBusName=bus_name, | ||
Targets=[{"Id": target_id, "Arn": queue_arn, "InputPath": "$.detail"}], | ||
@markers.aws.validated |
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.
🚀
@@ -634,9 +634,8 @@ def check_stream_status(): | |||
assert_valid_event(data) | |||
|
|||
|
|||
@markers.aws.unknown | |||
@markers.aws.needs_fixing |
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.
Do we know what's broken here?
{ | ||
"Id": target_id_1, |
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.
good clarification 👍
super nit: using the same single-line formatting would make it more consistent and easier to read
|
||
def _create_sqs_events_target(queue_name: str | None = None) -> tuple[str, str]: | ||
if not queue_name: | ||
queue_name = f"tests-queue-{short_uid()}" | ||
sqs_client = aws_client.sqs | ||
queue_url = sqs_client.create_queue(QueueName=queue_name)["QueueUrl"] |
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.
ok, fair point 👍
Why is no cleanup required here? Wouldn't the factory remove the need for an explicit cleanup after the yield here? It might have to do with the proper cleanup order 🤔
from typing import Optional | ||
from typing import Optional, TypeAlias | ||
|
||
from pydantic import BaseModel, Field |
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.
Is it worth introducing this new dependency here?
pydantic
is a transitive dependency (through aws-sam-translator
) and we should not rely on it without properly introducing it.
@@ -102,3 +106,20 @@ class InvalidEventPatternException(Exception): | |||
def __init__(self, reason=None, message=None) -> None: | |||
self.reason = reason | |||
self.message = message or f"Event pattern is not valid. Reason: {reason}" | |||
|
|||
|
|||
class FormattedEvent(BaseModel): |
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.
I'm not sure how much we gain by defining non-trivial types at this stage. Are we really sure this typing is correct?
It looks quite different than the previous type PutEventsRequestEntry, so at least one of these was/is quite wrong 😕
Motivation
Enable the input path (transformer) feature (https://docs.aws.amazon.com/eventbridge/latest/APIReference/API_Target.html).
This allows to specify an input path for the target, the body of matching event is parsed based on the specified json path and only the filtered content is sent to the target.
Changes
Add input transformer functionality to rule class.
Add
process_event
method that transforms the event content with the input path transformer if an input path is specified in the target.Change from
send_event
toprocess_event
method invoced by the provider.