Skip to content

Commit c2cbf29

Browse files
authored
Add ability to turn off health check, added deployment guide (#80)
1 parent 41c943f commit c2cbf29

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

datahub/server/app/server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from flask import send_from_directory
1+
import os
2+
from flask import send_from_directory, abort
23

34
from app import auth
45
from app.datasource import register, abort_request
@@ -24,6 +25,8 @@ def datasource_four_oh_four(*args, **kwargs):
2425
@limiter.exempt
2526
def get_health_check():
2627
"""This is a health check endpoint"""
28+
if os.path.exists("/tmp/datahub/deploying"):
29+
abort(503)
2730
return "pong"
2831

2932

datahub/tests/test_app/test_server.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from app.server import get_health_check
23

34
get_health_check
@@ -7,6 +8,16 @@ def test_ping_api(flask_client):
78
assert b"pong" == flask_client.get("/ping/").get_data()
89

910

11+
def test_ping_deploy_api(flask_client, monkeypatch):
12+
with monkeypatch.context() as m:
13+
m.setattr(
14+
os.path,
15+
"exists",
16+
lambda p: True if p == "/tmp/datahub/deploying" else False,
17+
)
18+
assert 503 == flask_client.get("/ping/").status_code
19+
20+
1021
def test_four_oh_four(flask_client, fake_user):
1122
assert 404 == flask_client.get("/ds/some/random/path/").status_code
1223

docs/admin_guide/deployment_guide.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
id: deployment_guide
3+
title: Deployment Guide
4+
sidebar_label: Deployment Guide
5+
---
6+
7+
While there are many ways to deploy datahub to production, there are some general principles
8+
that are recommended when setting up your own production deployment.
9+
10+
1. Please make sure the web server, the beat scheduler, and the celery worker are using the production Docker image. Please refer to `containers/docker-compose.prod.yml` to see how to launch these images for production.
11+
2. To get logs, make sure /var/log/datahub/ is mounted as a Docker volume so that the logs can be moved to the host machine.
12+
3. Use the /ping/ endpoint for health checks.
13+
1. During deployments, you can create a file that has the path `/tmp/datahub/deploying` to make the health check return 503 and remove it after completion.
14+
4. Please make sure celery worker is ran with concurrent mode as it is the only mode that can have a memory limit.
15+
5. During worker deployments, you can run the following first to make the celery worker stop receving new tasks and exit once all current tasks are finished: `celery multi stopwait datahub_worker@%h -A tasks.all_tasks --pidfile=/opt/celery_%n.pid`. This will make deployment time take much longer but users' running queries won't be killed.

0 commit comments

Comments
 (0)