Skip to content

Commit

Permalink
Manual backport: Fix throttling issue when describing cloudwatch log …
Browse files Browse the repository at this point in the history
…groups (#2019) (#2029)

Manual backport: Fix throttling issue when describing cloudwatch log groups (#2019)

Manual backport of #2019

Reviewed-by: Mike Graves <mgraves@redhat.com>
Reviewed-by: Helen Bailey <hebailey@redhat.com>
  • Loading branch information
hakbailey authored Apr 2, 2024
1 parent d6cfb85 commit 0aa365c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
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.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.botocore import is_boto3_error_code
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

0 comments on commit 0aa365c

Please sign in to comment.