-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
system
to new status page (#462)
The new `health/info` page does not contain the Version & Commit hash for the system repo. This PR will add those details.
- Loading branch information
Showing
4 changed files
with
93 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict' | ||
|
||
/** | ||
* Returns information about the `system` repo in the format required by the info service | ||
* @module FetchSystemInfoService | ||
*/ | ||
|
||
// We use promisify to wrap exec in a promise. This allows us to await it without resorting to using callbacks. | ||
const util = require('util') | ||
const exec = util.promisify(require('child_process').exec) | ||
|
||
const { version } = require('../../../package.json') | ||
|
||
/** | ||
* Returns information about the `system` repo in the format required by the info service | ||
* | ||
* @returns {Object} An object containing the `name`, `serviceName`, `version`, `commit` & `jobs` | ||
*/ | ||
async function go () { | ||
return { | ||
name: 'System', | ||
serviceName: 'system', | ||
version, | ||
commit: await _getCommitHash(), | ||
jobs: [] | ||
} | ||
} | ||
|
||
async function _getCommitHash () { | ||
try { | ||
const { stdout, stderr } = await exec('git rev-parse HEAD') | ||
return stderr ? `ERROR: ${stderr}` : stdout.replace('\n', '') | ||
} catch (error) { | ||
return `ERROR: ${error.message}` | ||
} | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict' | ||
|
||
// Test framework dependencies | ||
const Lab = require('@hapi/lab') | ||
const Code = require('@hapi/code') | ||
|
||
const { describe, it } = exports.lab = Lab.script() | ||
const { expect } = Code | ||
|
||
// Test helpers | ||
const { version } = require('../../../package.json') | ||
|
||
// Thing under test | ||
const FetchSystemInfoService = require('../../../app/services/health/fetch-system-info.service.js') | ||
|
||
describe('Fetch System Info service', () => { | ||
it('returns the systems version and commit hash', async () => { | ||
const result = await FetchSystemInfoService.go() | ||
|
||
expect(result.name).to.equal('System') | ||
expect(result.serviceName).to.equal('system') | ||
expect(result.version).to.equal(version) | ||
expect(result.commit).to.exist() | ||
expect(result.jobs).to.have.length(0) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters