diff options
author | 2021-10-28 14:55:54 -0400 | |
---|---|---|
committer | 2021-11-16 11:07:41 -0500 | |
commit | c441166003e84b137124c7655f8572048b31f7e9 (patch) | |
tree | 2805d2daef27d4742b3309c7ad9a9161b2d4aec8 /healthcheck-container/healthcheck.js | |
parent | f752cec2b6be1307c59168d5dbc88e7264daea32 (diff) |
[HEALTHCHECK] Enhance healthcheck logging
Add a timestamp to every log entry
Make a log entry when the application starts
Make a single log entry (instead of 2) for the outbound HTTP requests to the k8s API
Update node.js base image to the 16.x.x LTS release (from 14.x.x).
Issue-ID: DCAEGEN2-2958
Issue-ID: DCAEGEN2-2983
Signed-off-by: Jack Lucas <jflos@sonoris.net>
Change-Id: Ib275afbd0c871d4e82dda269606d243f3b6d89e4
Diffstat (limited to 'healthcheck-container/healthcheck.js')
-rw-r--r-- | healthcheck-container/healthcheck.js | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/healthcheck-container/healthcheck.js b/healthcheck-container/healthcheck.js index 574859f..9197e4d 100644 --- a/healthcheck-container/healthcheck.js +++ b/healthcheck-container/healthcheck.js @@ -31,9 +31,11 @@ const HEALTHY = 200; const UNHEALTHY = 500; const UNKNOWN = 503; -const EXPECTED_COMPONENTS='/opt/app/expected-components.json' +const EXPECTED_COMPONENTS = '/opt/app/expected-components.json' +const LISTEN_PORT = 8080; const fs = require('fs'); +const log = require('./log') // List of deployments expected to be created via Helm let helmDeps = []; @@ -41,8 +43,8 @@ try { helmDeps = JSON.parse(fs.readFileSync(EXPECTED_COMPONENTS, {encoding: 'utf8'})); } catch (error) { - console.log(`Could not access ${EXPECTED_COMPONENTS}: ${error}`); - console.log ('Using empty list of expected components'); + log.error(`Could not access ${EXPECTED_COMPONENTS}: ${error}`); + log.error ('Using empty list of expected components'); } const status = require('./get-status'); @@ -82,10 +84,11 @@ const checkHealth = function (callback) { // Simple HTTP server--any incoming request triggers a health check const server = http.createServer(function(req, res) { checkHealth(function(ret) { - console.log ((new Date()).toISOString() + ": " + JSON.stringify(ret)); + log.info(`Incoming request: ${req.url} -- response: ${JSON.stringify(ret)}`); res.statusCode = ret.status; res.setHeader('Content-Type', 'application/json'); res.end(JSON.stringify(ret.body || {}), 'utf8'); }); }); -server.listen(8080); +server.listen(LISTEN_PORT); +log.info(`Listening on port ${LISTEN_PORT} -- expected components: ${JSON.stringify(helmDeps)}`); |