[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
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 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 @@
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 @@
// 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)}`);