summaryrefslogtreecommitdiffstats
path: root/healthcheck-container/healthcheck.js
diff options
context:
space:
mode:
authorJack Lucas <jflos@sonoris.net>2021-12-07 17:13:49 -0500
committerJack Lucas <jflos@sonoris.net>2021-12-09 10:55:36 -0500
commit2afffed5e9487fab47ddcb49063dd2cb55170841 (patch)
tree612d78027831c5ad7cf291569c94c72a2037f7e8 /healthcheck-container/healthcheck.js
parentc17752a8dc6920d027108c7afa45b1d62443a8d0 (diff)
[HEALTHCHECK] Add healthcheck for dynamically-deployed microservices2.4.0
Add health checks for DCAE microservices deployed after the initial installation of dcaegen2-services. Issue-ID: DCAEGEN2-2959 Signed-off-by: Jack Lucas <jflos@sonoris.net> Change-Id: I9da0216db695f65ed520b509db183170977fce51
Diffstat (limited to 'healthcheck-container/healthcheck.js')
-rw-r--r--healthcheck-container/healthcheck.js36
1 files changed, 22 insertions, 14 deletions
diff --git a/healthcheck-container/healthcheck.js b/healthcheck-container/healthcheck.js
index 9197e4d..a0670f3 100644
--- a/healthcheck-container/healthcheck.js
+++ b/healthcheck-container/healthcheck.js
@@ -1,6 +1,8 @@
/*
+============LICENSE_START=========================================================================
Copyright(c) 2018-2020 AT&T 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.
@@ -12,6 +14,7 @@ Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
+============LICENSE_END===========================================================================
*/
// Expect ONAP and DCAE namespaces and Helm "release" name to be passed via environment variables
@@ -31,16 +34,16 @@ 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')
+const log = require('./log');
-// List of deployments expected to be created via Helm
-let helmDeps = [];
+// List of microservices expected to be deployed automatically at DCAE installation time
+let expectedMicroservices = [];
try {
- helmDeps = JSON.parse(fs.readFileSync(EXPECTED_COMPONENTS, {encoding: 'utf8'}));
+ expectedMicroservices = JSON.parse(fs.readFileSync(EXPECTED_COMPONENTS, {encoding: 'utf8'}));
}
catch (error) {
log.error(`Could not access ${EXPECTED_COMPONENTS}: ${error}`);
@@ -51,10 +54,13 @@ const status = require('./get-status');
const http = require('http');
// Helm deployments are always in the ONAP namespace and prefixed by Helm release name
-const helmList = helmDeps.map(function(name) {
+const expectedList = expectedMicroservices.map(function(name) {
return {namespace: ONAP_NS, deployment: HELM_REL.length > 0 ? HELM_REL + '-' + name : name};
});
+// List of deployment names for the microservices deployed automatically at DCAE installation time
+const expectedDepNames = expectedList.map((d) => d.deployment);
+
const isHealthy = function(summary) {
// Current healthiness criterion is simple--all deployments are ready
return summary.hasOwnProperty('count') && summary.hasOwnProperty('ready') && summary.count === summary.ready;
@@ -62,22 +68,24 @@ const isHealthy = function(summary) {
const checkHealth = function (callback) {
// Makes queries to Kubernetes and checks results
- // If we encounter some kind of error contacting k8s (or other), health status is UNKNOWN (500)
- // If we get responses from k8s but don't find all deployments ready, health status is UNHEALTHY (503)
+ // If we encounter some kind of error contacting k8s (or other), health status is UNKNOWN (503)
+ // If we get responses from k8s but don't find all deployments ready, health status is UNHEALTHY (500)
// If we get responses from k8s and all deployments are ready, health status is HEALTHY (200)
- // This could be a lot more nuanced, but what's here should be sufficient for R2 OOM healthchecking
+ // This could be a lot more nuanced, but what's here should be sufficient for OOM healthchecking
// Query k8s to find all the deployments with specified DEPLOY_LABEL
status.getLabeledDeploymentsPromise(DCAE_NS, DEPLOY_LABEL)
.then(function(fullDCAEList) {
- // Now get status for Helm deployments and CM deployments
- return status.getStatusListPromise(helmList.concat(fullDCAEList));
+ // Remove expected deployments from the list
+ dynamicDCAEDeps = fullDCAEList.filter( (n) => !(expectedDepNames.includes(n.deployment)) );
+ // Get status for expected deployments and any dynamically deployed components
+ return status.getStatusListPromise(expectedList.concat(dynamicDCAEDeps));
})
.then(function(body) {
callback({status: isHealthy(body) ? HEALTHY : UNHEALTHY, body: body});
})
.catch(function(error){
- callback({status: UNKNOWN, body: [error]})
+ callback({status: UNKNOWN, body: [error]});
});
};
@@ -91,4 +99,4 @@ const server = http.createServer(function(req, res) {
});
});
server.listen(LISTEN_PORT);
-log.info(`Listening on port ${LISTEN_PORT} -- expected components: ${JSON.stringify(helmDeps)}`);
+log.info(`Listening on port ${LISTEN_PORT} -- expected components: ${JSON.stringify(expectedMicroservices)}`);