-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…healthcheck Add Health Check Endpoints
- Loading branch information
Showing
5 changed files
with
83 additions
and
0 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
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,25 @@ | ||
paths: | ||
/api/health/ping: | ||
get: | ||
summary: 'Test whether the REST API is responding to requests' | ||
operationId: 'health-ping' | ||
description: | | ||
This endpoint tests whether the REST API is responding to requests. | ||
It doesn't test any other aspect of system health. | ||
tags: | ||
- 'Health Check' | ||
responses: | ||
'204': | ||
description: 'Indicates that the REST API is responding to requests' | ||
|
||
/api/health/status: | ||
get: | ||
summary: 'Returns a summary of the system status' | ||
operationId: 'health-status' | ||
description: | | ||
This endpoint returns a summary of the system status, including system uptime and database connection state. | ||
tags: | ||
- 'Health Check' | ||
responses: | ||
'200': | ||
description: 'Summary of the system status' |
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,23 @@ | ||
'use strict'; | ||
|
||
// const mongoose = require('mongoose'); | ||
const logger = require('../lib/logger'); | ||
|
||
exports.getPing = function(req, res) { | ||
return res.status(204).send(); | ||
}; | ||
|
||
exports.getStatus = function(req, res) { | ||
try { | ||
const status = { | ||
// TBD: check database connection without waiting 30 seconds for timeout when not connected | ||
// dbState: mongoose.STATES[mongoose.connection.readyState], | ||
uptime: process.uptime() | ||
}; | ||
return res.status(200).send(status); | ||
} | ||
catch(err) { | ||
logger.error("Unable to retrieve system status, failed with error: " + err); | ||
return res.status(500).send("Unable to retrieve system status. Server error."); | ||
} | ||
}; |
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,24 @@ | ||
'use strict'; | ||
|
||
const express = require('express'); | ||
|
||
const healthController = require('../controllers/health-controller'); | ||
const authn = require('../lib/authn-middleware'); | ||
const authz = require('../lib/authz-middleware'); | ||
|
||
const router = express.Router(); | ||
|
||
router.route('/health/ping') | ||
.get( | ||
// No authentication or authorization required | ||
healthController.getPing | ||
); | ||
|
||
router.route('/health/status') | ||
.get( | ||
authn.authenticate, | ||
authz.requireRole(authz.visitorOrHigher, authz.readOnlyService), | ||
healthController.getStatus | ||
); | ||
|
||
module.exports = router; |
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