From cf392920e59c669718c2bd3c175b347a38d9e4b3 Mon Sep 17 00:00:00 2001 From: Bikouo Aubin <79859644+abikouo@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:36:50 +0100 Subject: [PATCH] Fix throttling issue when describing cloudwatch log groups (#2019) 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 Reviewed-by: Helen Bailey Reviewed-by: Alina Buzachis (cherry picked from commit 196a87506d5e8bab0abaa78549d8e35af4001071) --- ...log_group_info-fix-throttling-exceptions.yml | 3 +++ .../modules/cloudwatchlogs_log_group_info.py | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/20240314-cloudwatchlogs_log_group_info-fix-throttling-exceptions.yml diff --git a/changelogs/fragments/20240314-cloudwatchlogs_log_group_info-fix-throttling-exceptions.yml b/changelogs/fragments/20240314-cloudwatchlogs_log_group_info-fix-throttling-exceptions.yml new file mode 100644 index 00000000000..f7180acb4fd --- /dev/null +++ b/changelogs/fragments/20240314-cloudwatchlogs_log_group_info-fix-throttling-exceptions.yml @@ -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). diff --git a/plugins/modules/cloudwatchlogs_log_group_info.py b/plugins/modules/cloudwatchlogs_log_group_info.py index 0cfe22e22e0..453d268d52b 100644 --- a/plugins/modules/cloudwatchlogs_log_group_info.py +++ b/plugins/modules/cloudwatchlogs_log_group_info.py @@ -82,6 +82,18 @@ 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): @@ -89,15 +101,14 @@ def describe_log_group(client, log_group_name, module): 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}")