Skip to content

Commit

Permalink
Add AWSRetry.jittered_backoff to rds_instance_info (#1026) (#1213)
Browse files Browse the repository at this point in the history
[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 <[email protected]>
  • Loading branch information
patchback[bot] authored Jun 4, 2022
1 parent 58335f7 commit c444062
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/1026-aws-retry-rds-instance-info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- rds_instance_info - add retries on common AWS failures (https://github.com/ansible-collections/community.aws/pull/1026).
18 changes: 13 additions & 5 deletions plugins/modules/rds_instance_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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:
Expand Down

0 comments on commit c444062

Please sign in to comment.