Merge pull request #133 from coreos-inc/alembichealth
Add health check endpoint to verify that the locally running DB revis…
This commit is contained in:
commit
34c06b0932
2 changed files with 27 additions and 0 deletions
|
@ -55,6 +55,8 @@ RUN mkdir /usr/local/nginx/logs/
|
||||||
RUN TEST=true venv/bin/python -m unittest discover -f
|
RUN TEST=true venv/bin/python -m unittest discover -f
|
||||||
RUN TEST=true venv/bin/python -m test.registry_tests -f
|
RUN TEST=true venv/bin/python -m test.registry_tests -f
|
||||||
|
|
||||||
|
RUN PYTHONPATH=. venv/bin/alembic heads > ALEMBIC_HEAD
|
||||||
|
|
||||||
VOLUME ["/conf/stack", "/var/log", "/datastorage", "/tmp", "/conf/etcd"]
|
VOLUME ["/conf/stack", "/var/log", "/datastorage", "/tmp", "/conf/etcd"]
|
||||||
|
|
||||||
EXPOSE 443 8443 80
|
EXPOSE 443 8443 80
|
||||||
|
|
|
@ -8,6 +8,7 @@ from urlparse import urlparse
|
||||||
from health.healthcheck import get_healthchecker
|
from health.healthcheck import get_healthchecker
|
||||||
|
|
||||||
from data import model
|
from data import model
|
||||||
|
from data.database import db
|
||||||
from data.model.oauth import DatabaseAuthorizationProvider
|
from data.model.oauth import DatabaseAuthorizationProvider
|
||||||
from app import app, billing as stripe, build_logs, avatar, signer, log_archive
|
from app import app, billing as stripe, build_logs, avatar, signer, log_archive
|
||||||
from auth.auth import require_session_login, process_oauth
|
from auth.auth import require_session_login, process_oauth
|
||||||
|
@ -227,6 +228,30 @@ def endtoend_health():
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@web.route('/health/dbrevision', methods=['GET'])
|
||||||
|
@route_show_if(features.BILLING) # Since this is only used in production.
|
||||||
|
@no_cache
|
||||||
|
def dbrevision_health():
|
||||||
|
# Find the revision from the database.
|
||||||
|
result = db.execute_sql('select * from alembic_version limit 1').fetchone()
|
||||||
|
db_revision = result[0]
|
||||||
|
|
||||||
|
# Find the local revision from the file system.
|
||||||
|
with open('ALEMBIC_HEAD', 'r') as f:
|
||||||
|
local_revision = f.readline().split(' ')[0]
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'db_revision': db_revision,
|
||||||
|
'local_revision': local_revision,
|
||||||
|
}
|
||||||
|
|
||||||
|
status_code = 200 if db_revision == local_revision else 400
|
||||||
|
|
||||||
|
response = jsonify(dict(data=data, status_code=status_code))
|
||||||
|
response.status_code = status_code
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
@web.route('/tos', methods=['GET'])
|
@web.route('/tos', methods=['GET'])
|
||||||
@no_cache
|
@no_cache
|
||||||
def tos():
|
def tos():
|
||||||
|
|
Reference in a new issue