Skip to content

Commit

Permalink
Move health endpoint before tenant middleware (#2818)
Browse files Browse the repository at this point in the history
  • Loading branch information
skwowet authored Feb 13, 2025
1 parent 31c0d83 commit e4ad74f
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions backend/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,38 @@ setImmediate(async () => {
next()
})

app.use('/health', async (req: any, res) => {
try {
const seq = SequelizeRepository.getSequelize(req)

const [osPingRes, redisPingRes, dbPingRes, temporalPingRes] = await Promise.all([
// ping opensearch
opensearch.ping().then((res) => res.body),
// ping redis,
redis.ping().then((res) => res === 'PONG'),
// ping database
seq.query('select 1', { type: QueryTypes.SELECT }).then((rows) => rows.length === 1),
// ping temporal
req.temporal
? (req.temporal as TemporalClient).workflowService.getSystemInfo({}).then(() => true)
: Promise.resolve(true),
])

if (osPingRes && redisPingRes && dbPingRes && temporalPingRes) {
res.sendStatus(200)
} else {
res.status(500).json({
opensearch: osPingRes,
redis: redisPingRes,
database: dbPingRes,
temporal: temporalPingRes,
})
}
} catch (err) {
res.status(500).json({ error: err.message, stack: err.stack })
}
})

// Configure the Entity routes
const routes = express.Router()

Expand Down Expand Up @@ -207,38 +239,6 @@ setImmediate(async () => {

app.use('/', routes)

app.use('/health', async (req: any, res) => {
try {
const seq = SequelizeRepository.getSequelize(req)

const [osPingRes, redisPingRes, dbPingRes, temporalPingRes] = await Promise.all([
// ping opensearch
opensearch.ping().then((res) => res.body),
// ping redis,
redis.ping().then((res) => res === 'PONG'),
// ping database
seq.query('select 1', { type: QueryTypes.SELECT }).then((rows) => rows.length === 1),
// ping temporal
req.temporal
? (req.temporal as TemporalClient).workflowService.getSystemInfo({}).then(() => true)
: Promise.resolve(true),
])

if (osPingRes && redisPingRes && dbPingRes && temporalPingRes) {
res.sendStatus(200)
} else {
res.status(500).json({
opensearch: osPingRes,
redis: redisPingRes,
database: dbPingRes,
temporal: temporalPingRes,
})
}
} catch (err) {
res.status(500).json({ error: err.message, stack: err.stack })
}
})

app.use(errorMiddleware)
})

Expand Down

0 comments on commit e4ad74f

Please sign in to comment.