Skip to content

Commit

Permalink
Tie Oncall healthcheck to database availability (linkedin#320)
Browse files Browse the repository at this point in the history
* Tie healthcheck to db availability

* add correct number of substitutions

* pin greenlet version

* update flake8 settings
  • Loading branch information
diegocepedaw authored Oct 2, 2020
1 parent 9d9493d commit 9d67c00
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
install_requires=[
'falcon==1.4.1',
'falcon-cors',
'greenlet==0.4.16',
'asn1crypto==1.0.0',
'gevent==1.4.0',
'ujson',
'sqlalchemy',
Expand Down
2 changes: 1 addition & 1 deletion src/oncall/api/v0/ical_key_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def on_delete(req, resp, requester):
if not (challenger == requester or check_ical_key_admin(challenger)):
raise HTTPForbidden(
'Unauthorized',
'Action not allowed: "%s" is not allowed to delete ical_keys of "%s"' % (challenger, ),
'Action not allowed: "%s" is not allowed to delete ical_keys of "%s"' % (challenger, requester),
)

invalidate_ical_key_by_requester(requester)
11 changes: 10 additions & 1 deletion src/oncall/healthcheck.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright (c) LinkedIn Corporation. All rights reserved. Licensed under the BSD-2 Clause license.
# See LICENSE in the project root for license information.

from falcon import HTTPNotFound
from falcon import HTTPNotFound, HTTPInternalServerError
from . import db


class HealthCheck(object):
Expand All @@ -21,6 +22,14 @@ def on_get(self, req, resp):
if self.dummy_status:
status = self.dummy_status
else:
try:
connection = db.connect()
cursor = connection.cursor()
cursor.execute("SELECT VERSION();")
cursor.close()
connection.close()
except:
raise HTTPInternalServerError()
try:
with open(self.path) as f:
status = f.readline().strip()
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ envlist = py27
[flake8]
exclude = .tox,./build
filename = *.py
ignore = E101,E741,W292,E722,E731,W503,W504
ignore = E101,E741,W292,E722,E731,W503,W504,E402
max-line-length = 160

[testenv]
Expand Down

0 comments on commit 9d67c00

Please sign in to comment.