Merge pull request #2990 from overleaf/bg-add-health-check-on-active-handles

add health check limit on active handles (optional)

GitOrigin-RevId: c26071c96b220935178012d881bb53013df64155
This commit is contained in:
Brian Gough 2020-07-09 14:28:46 +01:00 committed by Copybot
parent 398d2deb07
commit 49784e8ac0
3 changed files with 33 additions and 2 deletions

View file

@ -57,6 +57,26 @@ module.exports = HealthCheckController = {
})
},
checkActiveHandles(req, res, next) {
if (!(settings.maxActiveHandles > 0) || !process._getActiveHandles) {
return next()
}
const activeHandlesCount = (process._getActiveHandles() || []).length
if (activeHandlesCount > settings.maxActiveHandles) {
logger.err(
{ activeHandlesCount, maxActiveHandles: settings.maxActiveHandles },
'exceeded max active handles, failing health check'
)
return res.sendStatus(500)
} else {
logger.debug(
{ activeHandlesCount, maxActiveHandles: settings.maxActiveHandles },
'active handles are below maximum'
)
next()
}
},
checkApi(req, res, next) {
rclient.healthCheck(err => {
if (err) {

View file

@ -981,8 +981,16 @@ function initialize(webRouter, privateApiRouter, publicApiRouter) {
// used by kubernetes health-check and acceptance tests
webRouter.get('/dev/csrf', (req, res) => res.send(res.locals.csrfToken))
publicApiRouter.get('/health_check', HealthCheckController.check)
privateApiRouter.get('/health_check', HealthCheckController.checkApi)
publicApiRouter.get(
'/health_check',
HealthCheckController.checkActiveHandles,
HealthCheckController.check
)
privateApiRouter.get(
'/health_check',
HealthCheckController.checkActiveHandles,
HealthCheckController.checkApi
)
publicApiRouter.get('/health_check/redis', HealthCheckController.checkRedis)
privateApiRouter.get('/health_check/redis', HealthCheckController.checkRedis)

View file

@ -231,6 +231,9 @@ module.exports = settings =
maxUploadSize: 50 * 1024 * 1024 # 50 MB
# start failing the health check if active handles exceeds this limit
maxActiveHandles: if process.env['MAX_ACTIVE_HANDLES'] then parseInt(process.env['MAX_ACTIVE_HANDLES'], 10)
# Security
# --------
security: