From ff4693610c937d9b7e11a0a75cde4dee50a903e6 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 15 Mar 2022 12:24:34 +0000 Subject: [PATCH] Add backoff logic to elb_application_lb_info (#977) (#996) [PR #977/280d7a2f backport][stable-3] Add backoff logic to elb_application_lb_info This is a backport of PR #977 as merged into main (280d7a2). SUMMARY From time to time rate limiting failures occur on the usage of this module, this PR adds backoff logic to the module to improve its stability. fatal: [127.0.0.1 -> 127.0.0.1]: FAILED! => changed=false boto3_version: 1.20.34 botocore_version: 1.23.34 error: code: Throttling message: Rate exceeded type: Sender msg: 'Failed to list load balancers: An error occurred (Throttling) when calling the DescribeLoadBalancers operation (reached max retries: 4): Rate exceeded' response_metadata: http_headers: content-length: '271' content-type: text/xml date: Thu, 10 Mar 2022 10:34:23 GMT x-amzn-requestid: xxxxx http_status_code: 400 max_attempts_reached: true request_id: xxxxx retry_attempts: 4 ISSUE TYPE Bugfix Pull Request COMPONENT NAME elb_application_lb_info ADDITIONAL INFORMATION --- .../977-add-backoff-logic-elb-info.yml | 2 ++ plugins/modules/elb_application_lb_info.py | 17 +++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/977-add-backoff-logic-elb-info.yml diff --git a/changelogs/fragments/977-add-backoff-logic-elb-info.yml b/changelogs/fragments/977-add-backoff-logic-elb-info.yml new file mode 100644 index 00000000000..6a9ecc13a53 --- /dev/null +++ b/changelogs/fragments/977-add-backoff-logic-elb-info.yml @@ -0,0 +1,2 @@ +bugfixes: + - Add backoff retry logic to elb_application_lb_info (https://github.com/ansible-collections/community.aws/pull/977) diff --git a/plugins/modules/elb_application_lb_info.py b/plugins/modules/elb_application_lb_info.py index ddac4fe9629..d0176a4ce34 100644 --- a/plugins/modules/elb_application_lb_info.py +++ b/plugins/modules/elb_application_lb_info.py @@ -151,7 +151,13 @@ from ansible_collections.amazon.aws.plugins.module_utils.core import AnsibleAWSModule from ansible_collections.amazon.aws.plugins.module_utils.core import is_boto3_error_code -from ansible_collections.amazon.aws.plugins.module_utils.ec2 import boto3_tag_list_to_ansible_dict +from ansible_collections.amazon.aws.plugins.module_utils.ec2 import AWSRetry, boto3_tag_list_to_ansible_dict + + +@AWSRetry.jittered_backoff() +def get_paginator(connection, **kwargs): + paginator = connection.get_paginator('describe_load_balancers') + return paginator.paginate(**kwargs).build_full_result() def get_elb_listeners(connection, module, elb_arn): @@ -205,13 +211,12 @@ def list_load_balancers(connection, module): names = module.params.get("names") try: - load_balancer_paginator = connection.get_paginator('describe_load_balancers') if not load_balancer_arns and not names: - load_balancers = load_balancer_paginator.paginate().build_full_result() + load_balancers = get_paginator(connection) if load_balancer_arns: - load_balancers = load_balancer_paginator.paginate(LoadBalancerArns=load_balancer_arns).build_full_result() + load_balancers = get_paginator(connection, LoadBalancerArns=load_balancer_arns) if names: - load_balancers = load_balancer_paginator.paginate(Names=names).build_full_result() + load_balancers = get_paginator(connection, Names=names) except is_boto3_error_code('LoadBalancerNotFound'): module.exit_json(load_balancers=[]) except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: # pylint: disable=duplicate-except @@ -255,7 +260,7 @@ def main(): ) try: - connection = module.client('elbv2') + connection = module.client('elbv2', retry_decorator=AWSRetry.jittered_backoff(retries=10)) except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, msg='Failed to connect to AWS')