From 9888ba3d4e7f941c06abca90a8e94f6336972f40 Mon Sep 17 00:00:00 2001 From: Athanasios Voutsadakis Date: Wed, 28 Mar 2018 17:19:02 +0100 Subject: [PATCH 1/3] Add http health-check for the api app Also rename the 'elb' argument to 'simple' to be more descriptive. The healthcheck is going to issue requests to `/_status?simple=true` just to check that gunicorn is up and running - we don't need to go all the way to the database, as this would have adverse impact when api is under load. --- app/status/healthcheck.py | 2 +- manifest-api-base.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/status/healthcheck.py b/app/status/healthcheck.py index e704e6b73..da305c9e2 100644 --- a/app/status/healthcheck.py +++ b/app/status/healthcheck.py @@ -11,7 +11,7 @@ status = Blueprint('status', __name__) @status.route('/_status', methods=['GET', 'POST']) def show_status(): - if request.args.get('elb', None): + if request.args.get('simple', None): return jsonify(status="ok"), 200 else: return jsonify( diff --git a/manifest-api-base.yml b/manifest-api-base.yml index e8197575f..bc043e351 100644 --- a/manifest-api-base.yml +++ b/manifest-api-base.yml @@ -51,6 +51,8 @@ memory: 1G applications: - name: notify-api + health-check-type: http + health-check-http-endpoint: /_status?simple=true - name: notify-api-db-migration command: sleep infinity From 23cfe73c488072968bd501838021df4d6d2f519b Mon Sep 17 00:00:00 2001 From: Athanasios Voutsadakis Date: Wed, 11 Apr 2018 15:01:45 +0100 Subject: [PATCH 2/3] Add 5 second sleep before stopping old api instances This is to allow the new instances to start responding to the http healthchecks and start serving traffic. --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index ebf56145a..57585e43b 100644 --- a/Makefile +++ b/Makefile @@ -208,6 +208,7 @@ cf-deploy: ## Deploys the app to Cloud Foundry cf rename ${CF_APP} ${CF_APP}-rollback cf push ${CF_APP} -f <(make -s generate-manifest) cf scale -i $$(cf curl /v2/apps/$$(cf app --guid ${CF_APP}-rollback) | jq -r ".entity.instances" 2>/dev/null || echo "1") ${CF_APP} + if [ "${CF_APP}" == "notify-api" ]; then sleep 5; fi cf stop ${CF_APP}-rollback # sleep for 10 seconds to try and make sure that all worker threads (either web api or celery) have finished before we delete # when we delete the DB is unbound from the app, which can cause "permission denied for relation" psycopg2 errors. From 0766e680998bff16db1ec2a8a60ebb19a8ff6053 Mon Sep 17 00:00:00 2001 From: Athanasios Voutsadakis Date: Wed, 11 Apr 2018 15:38:41 +0100 Subject: [PATCH 3/3] Revert "Add 5 second sleep before stopping old api instances" This reverts commit 23cfe73c488072968bd501838021df4d6d2f519b. --- Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/Makefile b/Makefile index 57585e43b..ebf56145a 100644 --- a/Makefile +++ b/Makefile @@ -208,7 +208,6 @@ cf-deploy: ## Deploys the app to Cloud Foundry cf rename ${CF_APP} ${CF_APP}-rollback cf push ${CF_APP} -f <(make -s generate-manifest) cf scale -i $$(cf curl /v2/apps/$$(cf app --guid ${CF_APP}-rollback) | jq -r ".entity.instances" 2>/dev/null || echo "1") ${CF_APP} - if [ "${CF_APP}" == "notify-api" ]; then sleep 5; fi cf stop ${CF_APP}-rollback # sleep for 10 seconds to try and make sure that all worker threads (either web api or celery) have finished before we delete # when we delete the DB is unbound from the app, which can cause "permission denied for relation" psycopg2 errors.