terminus
terminus copied to clipboard
Custom status response
Closes https://github.com/godaddy/terminus/issues/189.
As noted in the PR, the hardcoded values for the top-level status
property aren't playing well with other monitoring systems, such as Netfilx's Eureka Discovery server. Other monitoring systems may even expect a whole different JSON as status of an application.
Since Kubernetes assures liveness of a container by an HTTP response with an HTTP code >= 200
and < 400
, the hardcoded ok
makes no difference to the health check process. Therefore, a response body of: { status: 'up' }
, with HTTP code 200
, would easily serve as a liveness indicator for both Kubernetes and the Netfilx's Eureka Discovery server.
The proposed resolution in this PR, is to add two new configuration properties: statusOkResponse
and statusErrorResponse
. Those properties will allow to globally configure the HTTP response body, used to respond with on a successful or an unsuccessful healthcheck respectively.
An unsuccessful healthcheck may override the global statusErrorResponse
property by setting the statusResponse
property on the Error
object.
As an example, the following configuration excerpt (for Express) can help monitoring application liveness for both Kubernetes and the Netfilx's Eureka Discovery server:
const http = require('http');
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('ok');
});
const server = http.createServer(app);
const options = {
// opts,
statusOkResponse: { status: 'up' },
statusErrorResponse: {status: 'down' }
};
createTerminus(server, options);
server.listen(PORT || 3000);
@gergelyke, @rxmarbles, any chance you can review the PR and, hopefully, merge it in any time soon? Being able to set custom status responses is a real need for me, and am eagerly waiting for the new version of terminus
with this functionality!
@gergelyke, @rxmarbles, pinging to make sure there is a possibility for you to review the PR, and, hopefully, merge it in. The proposed functionality is of high demand in my project.
@sindilevich sorry for the delay in this. Looks like this PR has conflicts. Mind taking care of that so this can land?
@rxmarbles, thank you for finding time to look into my PR! I've resolved all the conflicts with the main branch. Would greatly appreciate your review and an approval! Hope the PR'd finally land!
@gergelyke Mind giving this a review when you have a chance.
@gergelyke, @rxmarbles. thank you for investing your time, reviewing and approving the PR! Would greatly appreciate this PR be merged and land in the next version of this great tool! Thank you!
@rxmarbles, thank you so much for advancing merging the fix!