Skip to content

Commit

Permalink
Start doing the minimum in /status checks (#356)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4096

AWS ELBs require an endpoint they can hit to confirm whether an app is running. They are commonly referred to as health checks and are used to determine whether the ELB should route traffic through to an app instance. In our apps, it is the `/status` endpoint.

The endpoint in all our repos currently reads in the `package.json` file to get the app's version number. This information is then used to support the `/service-status` page in the water-abstraction-ui. Some of the repos also include a test query to the DB to confirm it can connect.

Having checks that confirm you can connect to dependent services (databases, other apps etc) is a good thing. But the ELB health checks are made multiple times a second across all instances. They only care whether an app is up or not. So if, for example, you include querying your DB in  `/status` you're hitting your DB with multiple connections per second, multiplied by the number of server instances you have running.

Including reading a file from disk each time means we're adding an unnecessary load on a service that already has performance and resource usage issues.

We've already added a new `/health/info` endpoint to each repo and we do DB connection checks elsewhere. So, we can reduce the work of our `/status` endpoint across all the repos to the bare minimum; returning a static `{ "status": "alive" }` response.

This issue was originally raised in DEFRA/water-abstraction-team#67
  • Loading branch information
Jozzey authored Aug 23, 2023
1 parent 7fb203b commit 2a9c465
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 94 deletions.
18 changes: 0 additions & 18 deletions src/lib/connectors/status.js

This file was deleted.

16 changes: 6 additions & 10 deletions src/modules/core/controller.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
const Boom = require('@hapi/boom')
const statusConnector = require('../../lib/connectors/status')
'use strict'

const getStatus = async () => {
try {
const status = await statusConnector.getStatus()
return status
} catch (e) {
throw Boom.badImplementation(e)
}
function getStatus () {
return { status: 'alive' }
}

exports.getStatus = getStatus
module.exports = {
getStatus
}
43 changes: 0 additions & 43 deletions test/lib/connectors/status.test.js

This file was deleted.

30 changes: 7 additions & 23 deletions test/modules/core/controller.test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
const { experiment, test, afterEach, beforeEach } = exports.lab = require('@hapi/lab').script()
const { expect } = require('@hapi/code')

const sinon = require('sinon')
const sandbox = sinon.createSandbox()
'use strict'

const statusConnector = require('../../../src/lib/connectors/status')
const { experiment, test } = exports.lab = require('@hapi/lab').script()
const { expect } = require('@hapi/code')
const controller = require('../../../src/modules/core/controller')

experiment('modules/core/controller', () => {
experiment('.getStatus', () => {
beforeEach(async () => {
sandbox.stub(statusConnector, 'getStatus').resolves({ test: true })
})

afterEach(async () => {
sandbox.restore()
})

test('returns the status', async () => {
const response = await controller.getStatus()
expect(response.test).to.be.true()
})

test('throw if the status connector errors', async () => {
statusConnector.getStatus.rejects()
await expect(controller.getStatus()).to.reject()
experiment('getStatus', () => {
test('returns an object with the application status', () => {
const response = controller.getStatus()
expect(response.status).to.equal('alive')
})
})
})

0 comments on commit 2a9c465

Please sign in to comment.