Skip to content

Commit

Permalink
Add backoff logic to elb_application_lb_info (ansible-collections#977)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Alina Buzachis <None>
  • Loading branch information
marknet15 authored Mar 15, 2022
1 parent ab58075 commit 280d7a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/977-add-backoff-logic-elb-info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- Add backoff retry logic to elb_application_lb_info (https://github.com/ansible-collections/community.aws/pull/977)
17 changes: 11 additions & 6 deletions plugins/modules/elb_application_lb_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')

Expand Down

0 comments on commit 280d7a2

Please sign in to comment.