Просмотр исходного кода

Merge pull request #82 from overleaf/bg-mongo-health-check

add a combined health check for mongo and redis
Simon Detheridge 7 лет назад
Родитель
Сommit
6721b904a7

+ 25 - 0
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

+ 6 - 1
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()