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

fix(aws): Don't build the cache on cold start #879

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions aws/logs_monitoring/caching/cloudwatch_log_group_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ def __init__(
logging.getLevelName(os.environ.get("DD_LOG_LEVEL", "INFO").upper())
)

# Initialize the cache
if self._should_fetch_tags():
self._build_tags_cache()

def get(self, log_group_arn):
"""Get the tags for the Cloudwatch Log Group from the cache

Expand All @@ -67,29 +63,6 @@ def get(self, log_group_arn):
def _should_fetch_tags(self):
return os.environ.get("DD_FETCH_LOG_GROUP_TAGS", "false").lower() == "true"

def _build_tags_cache(self):
Copy link
Member

Choose a reason for hiding this comment

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

nit: you may want to keep this code there and just remove its usage above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not called somewhere else, it will be a dead code. If we want to revert it, it's preferable to revert the commit I think.

try:
prefix = self._get_cache_file_prefix()
response = self.s3_client.list_objects_v2(
Bucket=DD_S3_BUCKET_NAME, Prefix=prefix
)
cache_files = [content["Key"] for content in response.get("Contents", [])]
for cache_file in cache_files:
log_group_tags, last_modified = self._get_log_group_tags_from_cache(
cache_file
)
if log_group_tags and not self._is_expired(last_modified):
log_group = cache_file.split("/")[-1].split(".")[0]
self.tags_by_log_group[log_group] = {
"tags": log_group_tags,
"last_modified": last_modified,
}
self.logger.debug(
f"loggroup_tags_cache initialized successfully {self.tags_by_log_group}"
)
except Exception:
self.logger.exception("failed to build log group tags cache", exc_info=True)

def _fetch_log_group_tags(self, log_group_arn):
# first, check in-memory cache
log_group_tags_struct = self.tags_by_log_group.get(log_group_arn, None)
Expand Down
Loading