Skip to content

Commit

Permalink
Make quota limit overridable
Browse files Browse the repository at this point in the history
  • Loading branch information
fheinecke committed May 29, 2024
1 parent 690800c commit e19337c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions aws_quota/check/quota_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class QuotaCheck:
scope: QuotaScope = None
service_code: str = None
quota_code: str = None
quota_limit_override: int = None
warning_threshold: float = None
error_threshold: float = None
# retries are needed to handle rate limiting
Expand Down Expand Up @@ -80,6 +81,9 @@ def label_values(self):

@property
def maximum(self) -> int:
if self.quota_limit_override is not None:
return self.quota_limit_override

try:
return int(get_service_quota(self.sq_client, self.service_code, self.quota_code)['Value'])
except self.sq_client.exceptions.NoSuchResourceException:
Expand Down
17 changes: 15 additions & 2 deletions aws_quota/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ def check_keys_to_check_classes(check_string: str):
return list(
filter(lambda c: c.key not in blacklisted_check_keys, selected_checks))

def set_quota_limit_override(quotaName: str, limitValue: int):
for check in ALL_CHECKS:
if check.key == quotaName:
check.quota_limit_override = limitValue
return

logger.warn('Override for check "%s" provided, but no check was found by that name', quotaName)

def set_quota_limit_overrides(limitOverrides: typing.Dict[str, int]):
for quotaName, limitValue in limitOverrides.items():
set_quota_limit_override(quotaName, limitValue)

class Runner:
class ReportResult(enum.Enum):
Expand Down Expand Up @@ -129,14 +140,16 @@ def run_checks(self):


@click.group()
@click.option('--debug/--no-debug', default=False)
def cli(debug):
@click.option('--debug/--no-debug', "debug", default=False)
@click.option('--limit-override', "limitOverrides", type=(str, int), multiple=True)
def cli(debug, limitOverrides):
logging.basicConfig(
level=logging.DEBUG if debug else logging.INFO,
format='%(asctime)s [%(levelname)s] %(name)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S'
)
logging.getLogger('botocore.credentials').setLevel(logging.WARNING)

set_quota_limit_overrides(dict(limitOverrides))

def common_scope_options(function):
function = click.option(
Expand Down

0 comments on commit e19337c

Please sign in to comment.