Skip to content

Commit

Permalink
Adding monitoring library
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrlee committed Nov 19, 2024
1 parent 06eefd6 commit e2dccba
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 307 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"dependencies": {
"@aws-sdk/client-sqs": "^3.682.0",
"@ministryofjustice/frontend": "^3.0.1",
"@ministryofjustice/hmpps-monitoring": "^0.0.1-alpha.6",
"agentkeepalive": "^4.5.0",
"applicationinsights": "^2.9.6",
"body-parser": "^1.20.3",
Expand Down
2 changes: 1 addition & 1 deletion server/applicationInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type ApplicationInfo = {
buildNumber: string
gitRef: string
gitShortHash: string
productId?: string
productId: string
branchName: string
}

Expand Down
2 changes: 2 additions & 0 deletions server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default {
apis: {
hmppsAuth: {
url: get('HMPPS_AUTH_URL', 'http://localhost:9090/auth', requiredInProduction),
healthPath: '/health/ping`',
externalUrl: get('HMPPS_AUTH_EXTERNAL_URL', get('HMPPS_AUTH_URL', 'http://localhost:9090/auth')),
timeout: {
response: Number(get('HMPPS_AUTH_TIMEOUT_RESPONSE', 10000)),
Expand All @@ -83,6 +84,7 @@ export default {
},
tokenVerification: {
url: get('TOKEN_VERIFICATION_API_URL', 'http://localhost:8100', requiredInProduction),
healthPath: '/health/ping`',
timeout: {
response: Number(get('TOKEN_VERIFICATION_API_TIMEOUT_RESPONSE', 5000)),
deadline: Number(get('TOKEN_VERIFICATION_API_TIMEOUT_DEADLINE', 5000)),
Expand Down
83 changes: 0 additions & 83 deletions server/data/healthCheck.test.ts

This file was deleted.

43 changes: 0 additions & 43 deletions server/data/healthCheck.ts

This file was deleted.

36 changes: 10 additions & 26 deletions server/middleware/setUpHealthChecks.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
import express, { Router } from 'express'

import healthcheck from '../services/healthCheck'
import { monitoringMiddleware, endpointHealthComponent } from '@ministryofjustice/hmpps-monitoring'
import type { ApplicationInfo } from '../applicationInfo'
import logger from '../../logger'
import config from '../config'

export default function setUpHealthChecks(applicationInfo: ApplicationInfo): Router {
const router = express.Router()

router.get('/health', (req, res, next) => {
healthcheck(applicationInfo, result => {
if (result.status !== 'UP') {
res.status(503)
}
res.json(result)
})
})
const apiConfig = Object.entries(config.apis)

router.get('/ping', (req, res) => {
res.send({
status: 'UP',
})
const middleware = monitoringMiddleware({
applicationInfo,
healthComponents: apiConfig.map(([name, options]) => endpointHealthComponent(logger, name, options)),
})

router.get('/info', (req, res) => {
res.json({
git: {
branch: applicationInfo.branchName,
},
build: {
artifact: applicationInfo.applicationName,
version: applicationInfo.buildNumber,
name: applicationInfo.applicationName,
},
productId: applicationInfo.productId,
})
})
router.get('/health', middleware.health)
router.get('/info', middleware.info)
router.get('/ping', middleware.ping)

return router
}
81 changes: 0 additions & 81 deletions server/services/healthCheck.test.ts

This file was deleted.

73 changes: 0 additions & 73 deletions server/services/healthCheck.ts

This file was deleted.

0 comments on commit e2dccba

Please sign in to comment.