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 tagging #10840

Merged
merged 23 commits into from
May 17, 2024

Conversation

maxhoheiser
Copy link
Member

@maxhoheiser maxhoheiser commented May 16, 2024

Motivation

Event bridge allows for adding tags to event buses and rules: https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-tagging.html
This PR introduces the ability to create event buses and rules with tags, add and remove tags to existing buses or rules and list tags for buses and rules.

Changes

Use most widely used pattern of handling tags from multiple other services by extend store with TagDict mapping resource arn to the dictionary of tags.
Exten test suite to cover all different options of tagging.

@maxhoheiser maxhoheiser self-assigned this May 16, 2024
@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 May 16, 2024
@maxhoheiser maxhoheiser requested a review from joe4dev May 16, 2024 12:14
@maxhoheiser maxhoheiser changed the title Feature/eventbridge v2 add tagging Feature: Eventbridge v2: Add tagging May 16, 2024
Copy link

github-actions bot commented May 16, 2024

LocalStack Community integration with Pro

    2 files  ± 0      2 suites  ±0   1h 39m 6s ⏱️ -12s
2 979 tests +13  2 674 ✅ +9  305 💤 +4  0 ❌ ±0 
2 981 runs  +13  2 674 ✅ +9  307 💤 +4  0 ❌ ±0 

Results for commit 8628c6f. ± Comparison against base commit 179a8e3.

This pull request removes 1 and adds 14 tests. Note that renamed tests count towards both.
tests.aws.services.events.test_events.TestEvents ‑ test_list_tags_for_resource
tests.aws.services.events.test_events_tags ‑ test_recreate_tagged_resource_without_tags[event_bus-event_bus_custom]
tests.aws.services.events.test_events_tags ‑ test_recreate_tagged_resource_without_tags[event_bus-event_bus_default]
tests.aws.services.events.test_events_tags ‑ test_recreate_tagged_resource_without_tags[rule-event_bus_custom]
tests.aws.services.events.test_events_tags ‑ test_recreate_tagged_resource_without_tags[rule-event_bus_default]
tests.aws.services.events.test_events_tags ‑ tests_tag_list_untag_not_existing_resource[not_existing_event_bus]
tests.aws.services.events.test_events_tags ‑ tests_tag_list_untag_not_existing_resource[not_existing_rule]
tests.aws.services.events.test_events_tags ‑ tests_tag_untag_resource[event_bus-event_bus_custom]
tests.aws.services.events.test_events_tags ‑ tests_tag_untag_resource[event_bus-event_bus_default]
tests.aws.services.events.test_events_tags ‑ tests_tag_untag_resource[rule-event_bus_custom]
tests.aws.services.events.test_events_tags ‑ tests_tag_untag_resource[rule-event_bus_default]
…

♻️ This comment has been updated with latest results.

@maxhoheiser maxhoheiser marked this pull request as ready for review May 16, 2024 16:54
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.

The tests are quite comprehensive. Nice coverage 👍

My main question is whether it would be feasible to reuse the tagging service (maybe not because the resource type differentiation is too specific)?
I added some suggestions to simplify the code and resolve potential smaller bugs.


class EventsStore(BaseStore):
# Map of eventbus names to eventbus objects. The name MUST be unique per account and region (works with AccountRegionBundle)
event_buses: EventBusDict = LocalAttribute(default=dict)

# Maps resource ARN to tags
TAGS: TagDict = CrossRegionAttribute(default=dict)
Copy link
Member

Choose a reason for hiding this comment

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

We have a TaggingService that implements tagging transparently (noticed by looking into DMS models as one of our new implementations). Is that applicable here or does different handling based on the resource type require a special case?

Copy link
Member Author

Choose a reason for hiding this comment

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

used TaggingService in: df9b76c

The only issue I see is, that the pattern other services use is to store the TagginService objects in the store, which violates a bit of what we discussed a couple of weeks ago that data and functions should be strictly separated. This comes back to the issue that the AcountRegionBundle needs additional logic that handles this separation which would make a lot of providers cleaner.

Copy link
Member

Choose a reason for hiding this comment

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

Very neat ✨
IMHO, that's a compromise worth taking vs. re-implementing the same thing for every service. The likelihood of a major change in tagging is very low.

localstack/services/events/provider.py Outdated Show resolved Hide resolved
localstack/services/events/provider.py Outdated Show resolved Hide resolved
store = self.get_store(context)
resource_type = get_bus_or_rule(resource_arn)
if not resource_type:
pass # TODO handle error for tagging not rule or event_bus
Copy link
Member

Choose a reason for hiding this comment

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

any particular reason why we don't handle that? It looks like an easy case

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in: bd3f9db

localstack/services/events/provider.py Outdated Show resolved Hide resolved
localstack/services/events/provider.py Outdated Show resolved Hide resolved
if "arn:aws:events" not in resource_arn_or_name:
return resource_arn_or_name
resource_type = get_bus_or_rule(resource_arn_or_name)
# TODO how to deal with / in event bus name or rule name
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a recurring theme (see #10789 (comment)). Can we get that fixed before we introduce this bug at too many different places?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really, I do not have any approach to fixing this, and we seam to also assume in many other providers that names will not contain /

@@ -596,12 +688,21 @@ def _get_limited_dict_and_next_token(
return limited_dict, next_token

def _extract_event_bus_name(
Copy link
Member

Choose a reason for hiding this comment

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

This method is getting increasingly complex. Could be a candidate for a unit test to cover edge cases easily (as long as we can ensure AWS parity).

tests/aws/services/events/test_events_tags.py Show resolved Hide resolved
tests/aws/services/events/test_events_tags.py Show resolved Hide resolved
@maxhoheiser maxhoheiser force-pushed the feature/eventbridge_v2-add-tagging branch from bd3f9db to 067d9a7 Compare May 17, 2024 11:20
@maxhoheiser maxhoheiser merged commit 6eeb7cc into master May 17, 2024
30 checks passed
@maxhoheiser maxhoheiser deleted the feature/eventbridge_v2-add-tagging branch May 17, 2024 15:12
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