From 40f6494b198585c619a4378ffbde58c29107b844 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Wed, 7 Aug 2019 16:25:23 +0100 Subject: [PATCH] add a combined health check for mongo and redis --- services/document-updater/app.coffee | 25 +++++++++++++++++++ .../app/coffee/mongojs.coffee | 7 +++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/services/document-updater/app.coffee b/services/document-updater/app.coffee index 9623a36c2c..6c1d8d1136 100644 --- a/services/document-updater/app.coffee +++ b/services/document-updater/app.coffee @@ -16,6 +16,8 @@ RedisManager = require('./app/js/RedisManager') DispatchManager = require('./app/js/DispatchManager') Errors = require "./app/js/Errors" HttpController = require "./app/js/HttpController" +mongojs = require "./app/js/mongojs" +async = require "async" Path = require "path" @@ -92,6 +94,29 @@ app.get "/health_check/redis_cluster", (req, res, next) -> else res.send 200 +app.get "/health_check", (req, res, next) -> + async.series [ + (cb) -> + pubsubClient.healthCheck (error) -> + if error? + logger.err {err: error}, "failed redis health check" + cb(error) + (cb) -> + docUpdaterRedisClient.healthCheck (error) -> + if error? + logger.err {err: error}, "failed redis cluster health check" + cb(error) + (cb) -> + mongojs.healthCheck (error) -> + if error? + logger.err {err: error}, "failed mongo health check" + cb(error) + ] , (error) -> + if error? + res.send 500 + else + res.send 200 + app.use (error, req, res, next) -> if error instanceof Errors.NotFoundError res.send 404 diff --git a/services/document-updater/app/coffee/mongojs.coffee b/services/document-updater/app/coffee/mongojs.coffee index 8f8f1a9ab9..dfeebb788f 100644 --- a/services/document-updater/app/coffee/mongojs.coffee +++ b/services/document-updater/app/coffee/mongojs.coffee @@ -1,7 +1,12 @@ Settings = require "settings-sharelatex" mongojs = require "mongojs" db = mongojs(Settings.mongo.url, ["docSnapshots"]) + module.exports = db: db ObjectId: mongojs.ObjectId - + healthCheck: (callback) -> + db.runCommand {ping: 1}, (err, res) -> + return callback(err) if err? + return callback(new Error("failed mongo ping")) if !res.ok + callback()