server: Add specific health check route that doesn't spam logs
continuous-integration/appveyor/branch AppVeyor build succeeded Details

master
Jonatan Nilsson 2022-08-15 08:39:59 +00:00
parent feb42c1ba7
commit 7755847af3
2 changed files with 23 additions and 0 deletions

View File

@ -41,6 +41,8 @@ export default class Server {
ip: ctx.req.headers['x-forwarded-for'] || ctx.req.connection.remoteAddress,
})
})
let healthChecks = 0
this.flaska.after(function(ctx) {
let ended = performance.now() - ctx.__started
@ -54,6 +56,18 @@ export default class Server {
if (ctx.status >= 500) {
level = 'error'
}
if (ctx.url === '/health') {
healthChecks++
if (healthChecks > 60 * 60 * 12) {
ctx.log[level]({
duration: Math.round(ended),
status: ctx.status,
}, `<-- ${status}${ctx.method} ${ctx.url} {has happened ${healthChecks} times}`)
healthChecks = 0
}
return
}
ctx.log[level]({
duration: Math.round(ended),

View File

@ -7,9 +7,18 @@ export default class TestRoutes {
register(server) {
server.flaska.get('/', this.static.bind(this))
server.flaska.get('/health', this.health.bind(this))
server.flaska.get('/error', this.error.bind(this))
}
health(ctx) {
ctx.body = {
name: config.get('name'),
version: config.get('version'),
environment: config.get('NODE_ENV'),
}
}
static(ctx) {
ctx.body = {
name: config.get('name'),