-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: Add feature view tags to dynamo tags #5291
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
franciscojavierarceo
merged 6 commits into
feast-dev:master
from
robhowley:rh-dynamo-tags
Apr 29, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
40cb583
add feature view tags to dynamo tags
robhowley 009f829
add tag update helper method
robhowley 61a21aa
fix tag change checks
robhowley ea25f25
simplify and just untag all to re add
robhowley c7548e1
dont do tag updates for new tables
robhowley 603d302
more granular tags take priority
robhowley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
import contextlib | ||
import itertools | ||
import logging | ||
from collections import OrderedDict | ||
from collections import OrderedDict, defaultdict | ||
from datetime import datetime | ||
from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Tuple, Union | ||
|
||
|
@@ -138,6 +138,38 @@ async def close(self): | |
def async_supported(self) -> SupportedAsyncMethods: | ||
return SupportedAsyncMethods(read=True, write=True) | ||
|
||
@staticmethod | ||
def _table_tags(online_config, table_instance) -> list[dict[str, str]]: | ||
table_instance_tags = table_instance.tags or {} | ||
online_tags = online_config.tags or {} | ||
|
||
common_tags = [ | ||
{"Key": key, "Value": table_instance_tags.get(key) or value} | ||
for key, value in online_tags.items() | ||
] | ||
table_tags = [ | ||
{"Key": key, "Value": value} | ||
for key, value in table_instance_tags.items() | ||
if key not in online_tags | ||
] | ||
|
||
return common_tags + table_tags | ||
|
||
@staticmethod | ||
def _update_tags(dynamodb_client, table_name: str, new_tags: list[dict[str, str]]): | ||
table_arn = dynamodb_client.describe_table(TableName=table_name)["Table"][ | ||
"TableArn" | ||
] | ||
current_tags = dynamodb_client.list_tags_of_resource(ResourceArn=table_arn)[ | ||
"Tags" | ||
] | ||
if current_tags: | ||
remove_keys = [tag["Key"] for tag in current_tags] | ||
dynamodb_client.untag_resource(ResourceArn=table_arn, TagKeys=remove_keys) | ||
|
||
if new_tags: | ||
dynamodb_client.tag_resource(ResourceArn=table_arn, Tags=new_tags) | ||
|
||
def update( | ||
self, | ||
config: RepoConfig, | ||
|
@@ -167,40 +199,43 @@ def update( | |
online_config.endpoint_url, | ||
online_config.session_based_auth, | ||
) | ||
# Add Tags attribute to creation request only if configured to prevent | ||
# TagResource permission issues, even with an empty Tags array. | ||
kwargs = ( | ||
{ | ||
"Tags": [ | ||
{"Key": key, "Value": value} | ||
for key, value in online_config.tags.items() | ||
] | ||
} | ||
if online_config.tags | ||
else {} | ||
) | ||
|
||
do_tag_updates = defaultdict(bool) | ||
for table_instance in tables_to_keep: | ||
# Add Tags attribute to creation request only if configured to prevent | ||
# TagResource permission issues, even with an empty Tags array. | ||
table_tags = self._table_tags(online_config, table_instance) | ||
kwargs = {"Tags": table_tags} if table_tags else {} | ||
|
||
table_name = _get_table_name(online_config, config, table_instance) | ||
try: | ||
dynamodb_resource.create_table( | ||
TableName=_get_table_name(online_config, config, table_instance), | ||
TableName=table_name, | ||
KeySchema=[{"AttributeName": "entity_id", "KeyType": "HASH"}], | ||
AttributeDefinitions=[ | ||
{"AttributeName": "entity_id", "AttributeType": "S"} | ||
], | ||
BillingMode="PAY_PER_REQUEST", | ||
**kwargs, | ||
) | ||
|
||
except ClientError as ce: | ||
do_tag_updates[table_name] = True | ||
|
||
# If the table creation fails with ResourceInUseException, | ||
# it means the table already exists or is being created. | ||
# Otherwise, re-raise the exception | ||
if ce.response["Error"]["Code"] != "ResourceInUseException": | ||
raise | ||
|
||
for table_instance in tables_to_keep: | ||
dynamodb_client.get_waiter("table_exists").wait( | ||
TableName=_get_table_name(online_config, config, table_instance) | ||
) | ||
table_name = _get_table_name(online_config, config, table_instance) | ||
dynamodb_client.get_waiter("table_exists").wait(TableName=table_name) | ||
# once table is confirmed to exist, update the tags. | ||
# tags won't be updated in the create_table call if the table already exists | ||
if do_tag_updates[table_name]: | ||
tags = self._table_tags(online_config, table_instance) | ||
self._update_tags(dynamodb_client, table_name, tags) | ||
Comment on lines
+236
to
+238
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the table already exists, then we should perform tag updates. otherwise we can skip that bc the tags would've been added in the create_table call |
||
|
||
for table_to_delete in tables_to_delete: | ||
_delete_table_idempotent( | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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 table level tags override the global where applicable. eg