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

cloudwatch_log_groups_info - Fix throttling issue when describing cloudwatch log groups #2019

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- cloudwatchlogs_log_group_info - Implement exponential backoff when making API calls to prevent throttling exceptions (https://github.com/ansible-collections/amazon.aws/issues/2011).
17 changes: 14 additions & 3 deletions plugins/modules/cloudwatchlogs_log_group_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,33 @@

from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.retries import AWSRetry


@AWSRetry.exponential_backoff()
def list_tags_log_group_with_backoff(client, log_group_name):
return client.list_tags_log_group(logGroupName=log_group_name)


@AWSRetry.exponential_backoff()
def describe_log_groups_with_backoff(client, **kwargs):
paginator = client.get_paginator("describe_log_groups")
return paginator.paginate(**kwargs).build_full_result()


def describe_log_group(client, log_group_name, module):
params = {}
if log_group_name:
params["logGroupNamePrefix"] = log_group_name
try:
paginator = client.get_paginator("describe_log_groups")
desc_log_group = paginator.paginate(**params).build_full_result()
desc_log_group = describe_log_groups_with_backoff(client, **params)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg=f"Unable to describe log group {log_group_name}")

for log_group in desc_log_group["logGroups"]:
log_group_name = log_group["logGroupName"]
try:
tags = client.list_tags_log_group(logGroupName=log_group_name)
tags = list_tags_log_group_with_backoff(client, log_group_name)
except is_boto3_error_code("AccessDeniedException"):
tags = {}
module.warn(f"Permission denied listing tags for log group {log_group_name}")
Expand Down
Loading