Skip to content

Commit

Permalink
Paginate ebs_snapshot_count check (#32)
Browse files Browse the repository at this point in the history
* use paginator for ebs_snapshot_count
* fix up error log wording when fail to get current value
* set default PaginationConfig with PageSize=100
  • Loading branch information
kedoodle authored Jan 10, 2022
1 parent 3be0820 commit 3d49e6e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aws_quota/check/ebs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class SnapshotCountCheck(QuotaCheck):

@property
def current(self):
return len(self.boto_session.client('ec2').describe_snapshots(OwnerIds=['self'])['Snapshots'])
return self.count_paginated_results("ec2", "describe_snapshots", "Snapshots", {"OwnerIds": ["self"]})
3 changes: 2 additions & 1 deletion aws_quota/check/quota_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def __str__(self) -> str:

def count_paginated_results(self, service: str, method: str, key: str, paginate_args: dict = {}) -> int:
paginator = self.boto_session.client(service).get_paginator(method)
page_iterable = paginator.paginate(**paginate_args)
pagination_config = {'PageSize': 100}
page_iterable = paginator.paginate(**{"PaginationConfig": pagination_config, **paginate_args})
return sum(len(page[key]) for page in page_iterable)

@property
Expand Down
2 changes: 1 addition & 1 deletion aws_quota/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ async def get_currents_job(self):
checks_to_drop.append(e.check)
except Exception:
logger.error(
'getting maximum of quota %s failed', check)
'getting current value of quota %s failed', check)

for check in checks_to_drop:
self.checks.remove(check)
Expand Down

0 comments on commit 3d49e6e

Please sign in to comment.