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

Feature: Eventbridge v2: Add input path #10733

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

maxhoheiser
Copy link
Member

@maxhoheiser maxhoheiser commented Apr 26, 2024

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 to process_event method invoced by the provider.

@maxhoheiser maxhoheiser added aws:events Amazon EventBridge semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases labels Apr 26, 2024
@maxhoheiser maxhoheiser self-assigned this Apr 26, 2024
Copy link

github-actions bot commented Apr 26, 2024

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 39m 10s ⏱️ + 2m 10s
2 935 tests +3  2 641 ✅ +3  294 💤 ±0  0 ❌ ±0 
2 937 runs  +3  2 641 ✅ +3  296 💤 ±0  0 ❌ ±0 

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.
tests.aws.services.events.test_events_inputs.TestEventsInputPath ‑ test_put_events_with_input_path_multiple
tests.aws.services.events.test_events_inputs.TestEventsInputPath ‑ test_put_events_with_input_path_max_level_depth
tests.aws.services.events.test_events_inputs.TestEventsInputPath ‑ test_put_events_with_input_path_multiple_targets
tests.aws.services.events.test_events_inputs.TestEventsInputPath ‑ test_put_events_with_input_path_nested[event_detail0]
tests.aws.services.events.test_events_inputs.TestEventsInputPath ‑ test_put_events_with_input_path_nested[event_detail1]

♻️ This comment has been updated with latest results.

@maxhoheiser maxhoheiser force-pushed the feature/eventbridge_v2-add-input-path branch 4 times, most recently from 03803b1 to 76e25d8 Compare May 8, 2024 06:55
@maxhoheiser maxhoheiser marked this pull request as ready for review May 8, 2024 06:55
@maxhoheiser maxhoheiser force-pushed the feature/eventbridge_v2-add-input-path branch 3 times, most recently from 8efe19e to 9c8e0c6 Compare May 8, 2024 07:16
@maxhoheiser maxhoheiser force-pushed the feature/eventbridge_v2-add-input-path branch 2 times, most recently from 50418c9 to 96012b4 Compare May 8, 2024 13:37
@maxhoheiser maxhoheiser force-pushed the feature/eventbridge_v2-add-input-path branch from 968a98c to f05b155 Compare May 8, 2024 14:20

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"]
Copy link
Member Author

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.

Copy link
Member

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 🤔

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.

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 👍

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:
Copy link
Member

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 🤔

def transform_event_with_target_input_path(
input_path: TargetInputPath, event: PutEventsRequestEntry
) -> PutEventsRequestEntry:
event = extract_jsonpath(event, input_path)
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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,
Copy link
Member

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"]
Copy link
Member

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
Copy link
Member

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):
Copy link
Member

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 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:events Amazon EventBridge semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants