server: Add specific health check route that doesn't spam logs
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
All checks were successful
continuous-integration/appveyor/branch AppVeyor build succeeded
This commit is contained in:
parent
feb42c1ba7
commit
7755847af3
2 changed files with 23 additions and 0 deletions
|
@ -41,6 +41,8 @@ export default class Server {
|
||||||
ip: ctx.req.headers['x-forwarded-for'] || ctx.req.connection.remoteAddress,
|
ip: ctx.req.headers['x-forwarded-for'] || ctx.req.connection.remoteAddress,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let healthChecks = 0
|
||||||
|
|
||||||
this.flaska.after(function(ctx) {
|
this.flaska.after(function(ctx) {
|
||||||
let ended = performance.now() - ctx.__started
|
let ended = performance.now() - ctx.__started
|
||||||
|
@ -54,6 +56,18 @@ export default class Server {
|
||||||
if (ctx.status >= 500) {
|
if (ctx.status >= 500) {
|
||||||
level = 'error'
|
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]({
|
ctx.log[level]({
|
||||||
duration: Math.round(ended),
|
duration: Math.round(ended),
|
||||||
|
|
|
@ -7,9 +7,18 @@ export default class TestRoutes {
|
||||||
|
|
||||||
register(server) {
|
register(server) {
|
||||||
server.flaska.get('/', this.static.bind(this))
|
server.flaska.get('/', this.static.bind(this))
|
||||||
|
server.flaska.get('/health', this.health.bind(this))
|
||||||
server.flaska.get('/error', this.error.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) {
|
static(ctx) {
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
name: config.get('name'),
|
name: config.get('name'),
|
||||||
|
|
Loading…
Reference in a new issue