8000 Put events fix for multiple targets by zaingz · Pull Request #11880 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

Put events fix for multiple targets #11880

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 4 commits into from
Nov 21, 2024
Merged

Conversation

zaingz
Copy link
Contributor
@zaingz zaingz commented Nov 19, 2024

Motivation

Fixes EventBridge PutEvents response so it correctly returns event IDs only once per event, regardless of how many rules or targets match. Currently, the response includes duplicate EventIds for each matching target, which doesn't match AWS behavior and can cause issues when clients try to track events by their IDs.

Related issue: #11597

Changes

  • Modified _process_entries and related methods in events provider to track and return event IDs only once
  • Refactored event processing logic to maintain a single event result per input event
  • Added test case to verify the fix and prevent regressions

Testing

  1. Create an EventBridge rule with multiple targets
  2. Send an event that matches the rule
  3. Verify that:
    • PutEvents response contains each EventId only once
    • All targets still receive the event correctly
    • Event IDs are consistent between response and delivered messages

Copy link
github-actions bot commented Nov 19, 2024

LocalStack Community integration with Pro

    2 files      2 suites   1h 2m 57s ⏱️
2 025 tests 1 905 ✅ 120 💤 0 ❌
2 027 runs  1 905 ✅ 122 💤 0 ❌

Results for commit 9698788.

♻️ This comment has been updated with latest results.

@zaingz zaingz self-assigned this Nov 20, 2024
@zaingz zaingz added the semver: patch Non-breaking changes which can be included in patch releases label Nov 20, 2024
@zaingz zaingz marked this pull request as ready for review November 20, 2024 09:28
Copy link
Member
@maxhoheiser maxhoheiser left a comment

Choose a reason for hiding this comment

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

Nice changes - I am not 100% sure about AWS parity with removing the InternalException ErrorCode though.

except Exception as error:
processed_entries.append(
Copy link
Member

Choose a reason for hiding this comment

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

how is this now handled, vaguely remember that AWS handles errors with targets this way - but I see that we don't have a test for this. If testing this I would do it via a missing IAM permission e.g. for EventBrdige to write to an SQS target because this should invoke a failed on send message and result in a similar error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback Max! After running the test against AWS, I discovered that AWS actually returns a successful EventId even when there are target permission failures. I've updated the code and tests to match this behavior.

Specifically:

  • PutEvents returns a successful EventId and FailedEntryCount=0
  • The failure to deliver to targets (due to missing permissions) doesn't affect the API response
  • Added a snapshot test that verifies this behavior

Copy link
Member

Choose a reason for hiding this comment

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

Ok nice - yes it is a bit strange why they do it like this - they also silently fail if you put an event to a non-existent event bus (see line 1357)

events_put_rule(
Name=rule_name,
EventPattern=json.dumps(
{"source": ["test.source"], "detail-type": ["test.detail.type"]}
Copy link
Member

Choose a reason for hiding this comment

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

it would make sense to use the constant pattern here too: TEST_EVENT_PATTERN_NO_DETAIL from test_events.py and similarly use TEST_EVENT_PATTERN as test event in line 647

Copy link
Member
@maxhoheiser maxhoheiser left a comment

Choose a reason for hiding this comment

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

Nice implementation to fix the problem 👍 (LGTMT when tests are green :) )

@zaingz zaingz force-pushed the eventbridge-multiple-target-fix-2 branch from 50578d0 to 9698788 Compare November 20, 2024 19:46
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 👍

"""Verify the message content matches what we sent."""
body = json.loads(message["Body"])

assert (
Copy link
Member

Choose a reason for hiding this comment

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

are individual asserts easier than snapshotting the body? It can make the initial failure more explicit 🤔

):
"""Test that put_events returns successful EventId even when target delivery fails due to non-existent queue."""
# Create a queue and get its ARN
queue_url = sqs_create_queue()
Copy link
Member

Choose a reason for hiding this comment

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

minor: we probably don't even need to create a queue in the first place, just makes it a bit easier to get an ARN :)

@zaingz zaingz merged commit b9502f8 into master Nov 21, 2024
32 checks passed
@zaingz zaingz deleted the eventbridge-multiple-target-fix-2 branch November 21, 2024 08:53
@zaingz zaingz removed their assignment Nov 25, 2024
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
319C
0