Skip to content
Snippets Groups Projects
Commit 8466b925 authored by Ole Langbehn's avatar Ole Langbehn
Browse files

feat: /ready and /health endpoints, readiness/liveness checks

parent b4cb6ed4
No related branches found
No related tags found
No related merge requests found
......@@ -263,10 +263,9 @@ const isDbConnectionAlive = async (sql: Sql): Promise<Response> => {
if (e instanceof DeadlineError) {
console.error(`Liveness check timed out after ${timeout} ms`)
return new Response(null, { status: 503 })
} else {
console.error('Liveness check failed, reason: ', e)
return new Response(null, { status: 500 })
}
console.error('Liveness check failed, reason: ', e)
return new Response(null, { status: 500 })
}
}
......@@ -299,8 +298,9 @@ export const startServer = (config: ServerConfig, sql: postgres.Sql): Deno.HttpS
hostname: '0.0.0.0',
handler: (req: Request) => {
const url = new URL(req.url)
if (url.pathname.startsWith('/liveness')) return isDbConnectionAlive(sql)
else return graphQLServer.handleRequest(req)
const pathname = url.pathname
if (pathname.startsWith('/health') || pathname.startsWith('/ready')) return isDbConnectionAlive(client)
return graphQLServer.handleRequest(req)
},
onListen({ port, hostname }) {
logger.info(
......@@ -308,7 +308,7 @@ export const startServer = (config: ServerConfig, sql: postgres.Sql): Deno.HttpS
)
if (config.fake) {
logger.info(
`Server is serving fake data due to FAKE env var set to true`,
'Server is serving fake data due to FAKE env var set to true',
)
}
},
......
......@@ -54,9 +54,17 @@ resource "google_cloud_run_service" "volunteering_api" {
ports {
container_port = 8004
}
startup_probe {
http_get {
path = "/ready"
}
timeout_seconds = 10
period_seconds = 10
failure_threshold = 6
}
liveness_probe {
http_get {
path = "/liveness"
path = "/health"
}
timeout_seconds = 10
period_seconds = 60
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment