Skip to content

Conversation

groves
Copy link
Contributor

@groves groves commented Jan 20, 2025

Motivation

#12148

I was using this pattern to match all events:
https://stackoverflow.com/questions/62406933/aws-eventbridge-pattern-to-capture-all-events

It works in AWS and in localstack before 4.0.3.

Changes

The new rule engine was using truthiness via condition.get('prefix') to determine if a condition was a prefix condition.
That assumes a prefix pattern of '' isn't actually a prefix pattern.
This change instead checks for None to determine the condition type and gets empty prefixes to match again.

Testing

Added a new JSON test case for this

@localstack-bot
Copy link
Contributor

localstack-bot commented Jan 20, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@groves groves force-pushed the empty-event-prefix branch from 5b29261 to 1b44de8 Compare January 20, 2025 13:22
I was using this pattern to match all events:
https://stackoverflow.com/questions/62406933/aws-eventbridge-pattern-to-capture-all-events

It works in AWS and in localstack before 4.0.3.

Because the new rule engine was using truthiness to determine if the
condition was a prefix one in `condition.get('prefix')`, it would assume
a prefix pattern of `''` isn't actually a prefix pattern. This instead
checks for `None` to determine the condition type and gets empty
prefixes to match again.
@groves groves force-pushed the empty-event-prefix branch from 1b44de8 to cc69af2 Compare January 20, 2025 13:38
@groves
Copy link
Contributor Author

groves commented Jan 20, 2025

I have read the CLA Document and I hereby sign the CLA

localstack-bot added a commit that referenced this pull request Jan 20, 2025
@groves groves marked this pull request as ready for review January 20, 2025 14:08
@groves
Copy link
Contributor Author

groves commented Jan 20, 2025

I don't believe I can add labels to this PR, but I think it should be semver: patch

@bentsku bentsku self-requested a review January 20, 2025 16:44
@bentsku bentsku added semver: patch Non-breaking changes which can be included in patch releases aws:events Amazon EventBridge labels Jan 20, 2025
@bentsku bentsku linked an issue Jan 20, 2025 that may be closed by this pull request
1 task
Copy link
Contributor

@bentsku bentsku left a comment

Choose a reason for hiding this comment

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

Nice catch! This is a great fix, thanks a lot for the contribution!

The new test case should be run against AWS to be sure it properly works against it. We have documentation around it here: https://github.com/localstack/localstack/tree/master/docs/testing/integration-tests#test-against-amazon-web-services

Let me know if it is possible for you to run the validation, otherwise we could probably merge if we manually try it. You could probably add the suffix test case as well.

Regarding the fix, I think it might run deeper: we use if <condition> := dict.get(<key>) quite a lot in _evaluate_condition, and I think your fix could probably generalized and used throughout, for example in line 71 and 73.

Let me know if you'd be interested in tackling the issue throughout, or you'd rather merge it as is and somebody else will tackle the rest. This is already a great fix in itself 👌

@groves
Copy link
Contributor Author

groves commented Jan 21, 2025

Thanks! I was able to find and test this without actually building localstack myself. Y'all have excellent test cases!

It'll probably be a couple weeks till I can get time to set things up locally, run the validation, and so on. As such, I'd rather we merge it as is and leave the rest for later.

I do use the empty prefix pattern in AWS' EventBridge, so I have manually verified that it works there. I haven't used the empty suffix pattern, so we may want to remove that change till someone can verify it. Let me know what you'd prefer!

Copy link
Contributor

@bentsku bentsku left a comment

Choose a reason for hiding this comment

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

Thanks again for the PR! I've ran your test case against AWS and it indeed works, so I'll approve and merge this PR!

I'll tackle the follow-up, thank you so much for providing the fix for the most common use case and validating it. I've also validated the empty suffix works, so that's all good!

Welcome to the list of contributors of LocalStack 🙌

@bentsku bentsku merged commit 51a6a67 into localstack:master Jan 21, 2025
33 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:events Amazon EventBridge 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.

bug: empty prefix no longer matches eventbridge events
3 participants