From c441166003e84b137124c7655f8572048b31f7e9 Mon Sep 17 00:00:00 2001 From: Jack Lucas Date: Thu, 28 Oct 2021 14:55:54 -0400 Subject: [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 Change-Id: Ib275afbd0c871d4e82dda269606d243f3b6d89e4 --- healthcheck-container/healthcheck.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'healthcheck-container/healthcheck.js') 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)}`); -- cgit 1.2.3-korg