From c4440624b5d41709208d6b265157a772bea8e2c3 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Sat, 4 Jun 2022 09:42:41 +0000 Subject: [PATCH] Add AWSRetry.jittered_backoff to rds_instance_info (#1026) (#1213) [PR #1026/6a2793af backport][stable-3] Add AWSRetry.jittered_backoff to rds_instance_info This is a backport of PR #1026 as merged into main (6a2793a). SUMMARY Add AWSRetry.jittered_backoff to the rds_instance_info module. When calling rds_instance_info we have been seeing API rate limit errors from AWS. When calling this module, it usually runs to about 90-150 times in a minute before we get rate limited. Using jittered_backoff should significantly decrease the number of times we see API rate limits here. 02:20:36 An exception occurred during task execution. To see the full traceback, use -vvv. The error was: botocore.exceptions.ClientError: An error occurred (Throttling) when calling the DescribeDBInstances operation (reached max retries: 4): Rate exceeded 02:20:36 fatal: [polaris -> localhost]: FAILED! => {"boto3_version": "1.20.22", "botocore_version": "1.23.22", "changed": false, "error": {"code": "Throttling", "message": "Rate exceeded", "type": "Sender"}, "msg": "Couldn't get instance information: An error occurred (Throttling) when calling the DescribeDBInstances operation (reached max retries: 4): Rate exceeded", "response_metadata": {"http_headers": {"connection": "close", "content-length": "254", "content-type": "text/xml", "date": "Tue, 15 Mar 2022 09:20:34 GMT", "x-amzn-requestid": "5de8131e-3f59-4b04-af25-5f7083ee09b9"}, "http_status_code": 400, "max_attempts_reached": true, "request_id": "5de8131e-3f59-4b04-af25-5f7083ee09b9", "retry_attempts": 4}} ISSUE TYPE Bugfix Pull Request COMPONENT NAME rds_instance_info ADDITIONAL INFORMATION Decorated rds_instance_info with AWSRetry.jittered_backoff Reviewed-by: Markus Bergholz --- .../1026-aws-retry-rds-instance-info.yml | 2 ++ plugins/modules/rds_instance_info.py | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/1026-aws-retry-rds-instance-info.yml diff --git a/changelogs/fragments/1026-aws-retry-rds-instance-info.yml b/changelogs/fragments/1026-aws-retry-rds-instance-info.yml new file mode 100644 index 00000000000..68ddab36ab0 --- /dev/null +++ b/changelogs/fragments/1026-aws-retry-rds-instance-info.yml @@ -0,0 +1,2 @@ +minor_changes: +- rds_instance_info - add retries on common AWS failures (https://github.com/ansible-collections/community.aws/pull/1026). diff --git a/plugins/modules/rds_instance_info.py b/plugins/modules/rds_instance_info.py index 6e41ea62940..e26e0f680a6 100644 --- a/plugins/modules/rds_instance_info.py +++ b/plugins/modules/rds_instance_info.py @@ -365,6 +365,17 @@ pass # handled by AnsibleAWSModule +@AWSRetry.jittered_backoff() +def _describe_db_instances(conn, **params): + paginator = conn.get_paginator('describe_db_instances') + try: + results = paginator.paginate(**params).build_full_result()['DBInstances'] + except is_boto3_error_code('DBInstanceNotFound'): + results = [] + + return results + + def instance_info(module, conn): instance_name = module.params.get('db_instance_identifier') filters = module.params.get('filters') @@ -375,12 +386,9 @@ def instance_info(module, conn): if filters: params['Filters'] = ansible_dict_to_boto3_filter_list(filters) - paginator = conn.get_paginator('describe_db_instances') try: - results = paginator.paginate(**params).build_full_result()['DBInstances'] - except is_boto3_error_code('DBInstanceNotFound'): - results = [] - except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except + results = _describe_db_instances(conn, **params) + except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, "Couldn't get instance information") for instance in results: