terminus icon indicating copy to clipboard operation
terminus copied to clipboard

Custom status response

Open sindilevich opened this issue 3 years ago • 2 comments

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);

sindilevich avatar Jun 07 '21 21:06 sindilevich

@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!

sindilevich avatar Jun 11 '21 08:06 sindilevich

@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 avatar Jul 04 '21 14:07 sindilevich

@sindilevich sorry for the delay in this. Looks like this PR has conflicts. Mind taking care of that so this can land?

rxmarbles avatar Feb 23 '23 20:02 rxmarbles

@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!

sindilevich avatar Feb 25 '23 21:02 sindilevich

@gergelyke Mind giving this a review when you have a chance.

rxmarbles avatar Mar 14 '23 21:03 rxmarbles

@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!

sindilevich avatar Mar 14 '23 21:03 sindilevich

@rxmarbles, thank you so much for advancing merging the fix!

sindilevich avatar Apr 14 '23 09:04 sindilevich