Skip to content

Commit

Permalink
Moving to monitoring library
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrlee committed Dec 2, 2024
1 parent 4eec95b commit 8d459d2
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 308 deletions.
2 changes: 1 addition & 1 deletion integration_tests/e2e/health.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ context('Healthcheck', () => {
cy.request({ url: '/health', method: 'GET', failOnStatusCode: false }).then(response => {
expect(response.body.components.hmppsAuth.status).to.equal('UP')
expect(response.body.components.tokenVerification.status).to.equal('DOWN')
expect(response.body.components.tokenVerification.details).to.contain({ status: 500, retries: 2 })
expect(response.body.components.tokenVerification.details).to.contain({ status: 500, attempts: 3 })
})
})

Expand Down
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-beta.2",
"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.

Loading

0 comments on commit 8d459d2

Please sign in to comment.