Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quota monitor blueprint: don't fail quota fetch on deleted project #1931

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading