mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-27 06:13:51 +00:00
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:
parent
398d2deb07
commit
49784e8ac0
3 changed files with 33 additions and 2 deletions
|
@ -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) {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue