From 280d7a2f130d5aaa993ed45dc501fa66f69d9582 Mon Sep 17 00:00:00 2001 From: Mark Woolley Date: Tue, 15 Mar 2022 11:52:43 +0000 Subject: [PATCH] Add backoff logic to elb_application_lb_info (#977) Add backoff logic to elb_application_lb_info 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 Reviewed-by: Markus Bergholz Reviewed-by: Alina Buzachis --- .../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 d1de312df11..dbd4b7e0ab6 100644 --- a/plugins/modules/elb_application_lb_info.py +++ b/plugins/modules/elb_application_lb_info.py @@ -220,7 +220,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_alb_listeners(connection, module, alb_arn): @@ -274,13 +280,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 @@ -324,7 +329,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')