Skip to content

Commit

Permalink
don't fail quota fetch on deleted project
Browse files Browse the repository at this point in the history
  • Loading branch information
ludoo committed Dec 15, 2023
1 parent c50b732 commit 6d46dc4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions blueprints/cloud-operations/quota-monitoring/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
}])


class NotFound(Exception):
pass


class Quota(_Quota):
'Compute quota.'

Expand Down Expand Up @@ -152,6 +156,9 @@ def fetch(request, delete=False):
except json.JSONDecodeError as e:
logging.critical(e)
raise SystemExit(f'Error decoding response: {response.content}')
if response.status_code == 404:
raise NotFound(
f'Resource not found. Error: {rdata.get("error")} URL: {request.url}')
if response.status_code != 200:
logging.critical(rdata)
error = rdata.get('error', {})
Expand All @@ -175,10 +182,14 @@ def get_quotas(project, region='global'):
request = HTTPRequest(URL_PROJECT.format(project))
else:
request = HTTPRequest(URL_REGION.format(project, region))
resp = fetch(request)
ts = datetime.datetime.utcnow()
for quota in resp.get('quotas'):
yield Quota(project, region, ts, **quota)
try:
resp = fetch(request)
except NotFound as e:
logging.warn(e.args[0])
else:
ts = datetime.datetime.utcnow()
for quota in resp.get('quotas'):
yield Quota(project, region, ts, **quota)


@click.command()
Expand Down

0 comments on commit 6d46dc4

Please sign in to comment.