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

Update log group tag handling #9

Merged
merged 22 commits into from
Dec 9, 2024
Merged

Conversation

markdboyd
Copy link

@markdboyd markdboyd commented Dec 6, 2024

Changes proposed in this pull request:

Related to #8

  • Add expiration of cache for log group tags after 1 hour
  • Add Rubocop configuration
  • Apply code formatting suggestions from Rubocop

Things to check

  • For any logging statements, is there any chance that they could be logging sensitive data?
  • Are log statements using a logging library with a logging level set? Setting a logging level means that log statements "below" that level will not be written to the output. For example, if the logging level is set to INFO and debugging statements are written with log.debug or similar, then they won't be written to the otput, which can prevent unintentional leaks of sensitive data.

Security considerations

None, just improving behavior of plugin so that tags are refreshed every hour

@markdboyd markdboyd requested a review from a team as a code owner December 6, 2024 22:52
Comment on lines +194 to +207
def should_fetch_tags(log_group_name)
# only fetch tags if
# - there is no timestamp for when the tags were last updated
# - OR the tags were last updated more than an hour ago (60 seconds * 60 minutes)
@tag_cache[log_group_name][:last_updated].nil? ||
((Time.now - @tag_cache[log_group_name][:last_updated]) > (60 * 60))
end

def fetch_tags(log_group_name)
if @tag_cache.key?(log_group_name)
return @tag_cache[log_group_name][:tags]
else
tags = fetch_tags_from_cloudwatch(log_group_name)
@tag_cache[log_group_name] = { tags: tags}
return tags
end
return @tag_cache[log_group_name][:tags] if @tag_cache.key?(log_group_name) && !should_fetch_tags(log_group_name)

tags = fetch_tags_from_cloudwatch(log_group_name)
@tag_cache[log_group_name] = { tags: tags, last_updated: Time.now }
tags
Copy link
Author

Choose a reason for hiding this comment

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

These are the only meaningful changes in the PR. The rest are formatting changes suggested by Rubocop which I do think makes the code more readable and maintainable

Copy link

@JasonTheMain JasonTheMain left a comment

Choose a reason for hiding this comment

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

Really like the changes

@markdboyd markdboyd merged commit 457c7de into main Dec 9, 2024
2 checks passed
@markdboyd markdboyd deleted the update-log-group-tag-handling branch December 9, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants