Skip to content

Commit

Permalink
elb_application_lb_info - ensure queries for additional ALB data have…
Browse files Browse the repository at this point in the history
… retries enabled (#1768)

elb_application_lb_info - ensure queries for additional ALB data have retries enabled

SUMMARY
As per #1767 the queries to pull extra info about ALBs are hitting rate limits when there's a lot of ALBs.  Unfortunately the initial list operation has limited server-side filtering capabilities (and we don't have consistent client side filtering implemented at this time).
Ensure that all of the extra queries have retries with jittered backoff enabled.
Additionally, drops a redundant describe_load_balancers call to retrieve the ip_address_type information.  (added by ansible-collections/community.aws#499)
ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME
elb_application_lb_info
ADDITIONAL INFORMATION
I don't consider this a full fix for #1767 so I'm not using the "fixes".

Reviewed-by: Alina Buzachis
(cherry picked from commit d1c5f05)
  • Loading branch information
tremble authored and patchback[bot] committed Sep 27, 2023
1 parent 1b38b2b commit a0d4869
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bugfixes:
- elb_application_lb_info - ensure all API queries use the retry decorator (https://github.com/ansible-collections/amazon.aws/issues/1767).
minor_changes:
- elb_application_lb_info - drop redundant ``describe_load_balancers`` call fetching ``ip_address_type`` (https://github.com/ansible-collections/amazon.aws/pull/1768).
40 changes: 18 additions & 22 deletions plugins/modules/elb_application_lb_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,31 @@ def get_paginator(connection, **kwargs):

def get_alb_listeners(connection, module, alb_arn):
try:
return connection.describe_listeners(LoadBalancerArn=alb_arn)["Listeners"]
return connection.describe_listeners(
aws_retry=True,
LoadBalancerArn=alb_arn,
)["Listeners"]
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to describe alb listeners")


def get_listener_rules(connection, module, listener_arn):
try:
return connection.describe_rules(ListenerArn=listener_arn)["Rules"]
return connection.describe_rules(
aws_retry=True,
ListenerArn=listener_arn,
)["Rules"]
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to describe listener rules")


def get_load_balancer_attributes(connection, module, load_balancer_arn):
try:
load_balancer_attributes = boto3_tag_list_to_ansible_dict(
connection.describe_load_balancer_attributes(LoadBalancerArn=load_balancer_arn)["Attributes"]
)
attributes = connection.describe_load_balancer_attributes(
aws_retry=True,
LoadBalancerArn=load_balancer_arn,
)["Attributes"]
load_balancer_attributes = boto3_tag_list_to_ansible_dict(attributes)
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to describe load balancer attributes")

Expand All @@ -262,22 +270,15 @@ def get_load_balancer_attributes(connection, module, load_balancer_arn):

def get_load_balancer_tags(connection, module, load_balancer_arn):
try:
return boto3_tag_list_to_ansible_dict(
connection.describe_tags(ResourceArns=[load_balancer_arn])["TagDescriptions"][0]["Tags"]
)
tag_descriptions = connection.describe_tags(
aws_retry=True,
ResourceArns=[load_balancer_arn],
)["TagDescriptions"]
return boto3_tag_list_to_ansible_dict(tag_descriptions[0]["Tags"])
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to describe load balancer tags")


def get_load_balancer_ipaddresstype(connection, module, load_balancer_arn):
try:
return connection.describe_load_balancers(LoadBalancerArns=[load_balancer_arn])["LoadBalancers"][0][
"IpAddressType"
]
except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e:
module.fail_json_aws(e, msg="Failed to describe load balancer ip address type")


def list_load_balancers(connection, module):
load_balancer_arns = module.params.get("load_balancer_arns")
names = module.params.get("names")
Expand Down Expand Up @@ -308,11 +309,6 @@ def list_load_balancers(connection, module):
for listener in load_balancer["listeners"]:
listener["rules"] = get_listener_rules(connection, module, listener["ListenerArn"])

# Get ALB ip address type
load_balancer["IpAddressType"] = get_load_balancer_ipaddresstype(
connection, module, load_balancer["LoadBalancerArn"]
)

# Turn the boto3 result in to ansible_friendly_snaked_names
snaked_load_balancers = [
camel_dict_to_snake_dict(load_balancer) for load_balancer in load_balancers["LoadBalancers"]
Expand Down

0 comments on commit a0d4869

Please sign in to comment.