summaryrefslogtreecommitdiffstats
path: root/healthcheck-container/get-status.js
diff options
context:
space:
mode:
authorJack Lucas <jflos@sonoris.net>2021-10-28 14:55:54 -0400
committerJack Lucas <jflos@sonoris.net>2021-11-16 11:07:41 -0500
commitc441166003e84b137124c7655f8572048b31f7e9 (patch)
tree2805d2daef27d4742b3309c7ad9a9161b2d4aec8 /healthcheck-container/get-status.js
parentf752cec2b6be1307c59168d5dbc88e7264daea32 (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/get-status.js')
-rw-r--r--healthcheck-container/get-status.js23
1 files changed, 13 insertions, 10 deletions
diff --git a/healthcheck-container/get-status.js b/healthcheck-container/get-status.js
index f3c4f97..1480e21 100644
--- a/healthcheck-container/get-status.js
+++ b/healthcheck-container/get-status.js
@@ -1,6 +1,7 @@
/*
Copyright(c) 2018 AT&T Intellectual Property. All rights reserved.
Copyright(c) 2020 Nokia Intellectual Property. All rights reserved.
+Copyright(c) 2021 J. F. Lucas. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -21,6 +22,7 @@ See the License for the specific language governing permissions and limitations
const fs = require('fs');
const https = require('https');
+const log = require('./log');
const K8S_CREDS = '/var/run/secrets/kubernetes.io/serviceaccount';
const K8S_HOST = 'kubernetes.default.svc.cluster.local'; // Full name to match cert for TLS
@@ -38,7 +40,7 @@ const summarizeDeploymentList = function(list) {
let ret =
{
- type: "summary",
+ type: 'summary',
count: 0,
ready: 0,
items: []
@@ -64,24 +66,25 @@ const queryKubernetes = function(path, callback) {
// Make GET request to Kubernetes API
const options = {
host: K8S_HOST,
- path: "/" + path,
+ path: '/' + path,
ca : ca,
headers: {
Authorization: 'bearer ' + token
}
};
- console.log ("request url: " + options.host + options.path);
+
const req = https.get(options, function(resp) {
- let rawBody = "";
- resp.on("data", function(data) {
+ let rawBody = '';
+ resp.on('data', function(data) {
rawBody += data;
});
- resp.on("error", function (error) {
- console.error("error: " + error);
+ resp.on('error', function (error) {
+ log.debug(`k8s API query: ${options.host}${options.path} -- error: ${error}`);
callback(error, null, null)
});
- resp.on("end", function() {
- console.log ("status: " + resp.statusCode ? resp.statusCode: "NONE")
+ resp.on('end', function() {
+ const deployment = JSON.parse(rawBody);
+ log.debug (`k8s API query: ${options.host}${options.path} -- status: ${resp.statusCode ? resp.statusCode: 'NONE'}`);
callback(null, resp, JSON.parse(rawBody));
});
});
@@ -92,7 +95,7 @@ const getStatusSinglePromise = function (item) {
// Expect item to be of the form {namespace: "namespace", deployment: "deployment_name"}
return new Promise(function(resolve, reject){
const path = K8S_PATH + item.namespace + '/deployments/' + item.deployment;
- queryKubernetes(path, function(error, res, body){
+ queryKubernetes(path, function(error, res, body) {
if (error) {
reject(error);
}