Skip to content

Commit

Permalink
Fix throttling issue when describing cloudwatch log groups (#2019)
Browse files Browse the repository at this point in the history
cloudwatch_log_groups_info - Fix throttling issue when describing cloudwatch log groups

SUMMARY

Closes #2011

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

cloudwatch_log_groups_info

Reviewed-by: Mandar Kulkarni <[email protected]>
Reviewed-by: Helen Bailey <[email protected]>
Reviewed-by: Alina Buzachis
(cherry picked from commit 196a875)
  • Loading branch information
abikouo authored and patchback[bot] committed Mar 21, 2024
1 parent 63bcca3 commit cf39292
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.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

0 comments on commit cf39292

Please sign in to comment.