summaryrefslogtreecommitdiffstats
path: root/healthcheck-container/healthcheck.js
diff options
context:
space:
mode:
Diffstat (limited to 'healthcheck-container/healthcheck.js')
-rw-r--r--healthcheck-container/healthcheck.js79
1 files changed, 49 insertions, 30 deletions
diff --git a/healthcheck-container/healthcheck.js b/healthcheck-container/healthcheck.js
index a1c45e9..7a03f1e 100644
--- a/healthcheck-container/healthcheck.js
+++ b/healthcheck-container/healthcheck.js
@@ -24,52 +24,71 @@ const UNHEALTHY = 500;
const UNKNOWN = 503;
// List of deployments expected to be created via Helm
-const helmDeps =
- [
- 'dcae-cloudify-manager'
- ];
+const helmDeps =
+ [
+ 'dcae-cloudify-manager'
+ ];
+
+// List of deployments expected to be created by CM at boot time
+const bootDeps =
+ [
+ 'dep-config-binding-service',
+ 'dep-deployment-handler',
+ 'dep-inventory',
+ 'dep-service-change-handler',
+ 'dep-policy-handler',
+ 'dep-dcae-ves-collector',
+ 'dep-dcae-tca-analytics',
+ 'dep-dcae-prh',
+ 'dep-dcae-hv-ves-collector',
+ 'dep-dcae-datafile-collector'
+ ];
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) {
- return {namespace: ONAP_NS, deployment: HELM_REL.length > 0 ? HELM_REL + '-' + name : name};
+ return {namespace: ONAP_NS, deployment: HELM_REL.length > 0 ? HELM_REL + '-' + name : name};
});
const isHealthy = function(summary) {
- // Current healthiness criterion is simple--all deployments are ready
- return summary.count && summary.ready && summary.count === summary.ready;
+ // Current healthiness criterion is simple--all deployments are ready
+ return summary.count && summary.ready && summary.count === summary.ready;
};
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 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
+ // 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 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
- // Query k8s to find all the deployments launched by CM (they all have a 'cfydeployment' label)
- status.getDCAEDeploymentsPromise(DCAE_NS)
- .then(function(dcaeList) {
- // Now get status for Helm deployments and CM deployments
- return status.getStatusListPromise(helmList.concat(dcaeList));
- })
- .then(function(body) {
- callback({status: isHealthy(body) ? HEALTHY : UNHEALTHY, body: body});
- })
- .catch(function(error){
- callback({status: UNKNOWN, body: [error]})
- });
+ // Query k8s to find all the deployments launched by CM (they all have a 'cfydeployment' label)
+ status.getDCAEDeploymentsPromise(DCAE_NS)
+ .then(function(fullDCAEList) {
+ // Remove any expected boot-time CM deployments from the list to avoid duplicates
+ dynamicDCAEDeps = fullDCAEList.filter(function(i) {return !(bootDeps.includes(i.deployment));})
+ // Create full list of CM deployments to check: boot deployments and anything else created by CM
+ dcaeList = (bootDeps.map(function(name){return {namespace: DCAE_NS, deployment: name}})).concat(dynamicDCAEDeps);
+ // Now get status for Helm deployments and CM deployments
+ return status.getStatusListPromise(helmList.concat(dcaeList));
+ })
+ .then(function(body) {
+ callback({status: isHealthy(body) ? HEALTHY : UNHEALTHY, body: body});
+ })
+ .catch(function(error){
+ callback({status: UNKNOWN, body: [error]})
+ });
};
// 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));
- res.statusCode = ret.status;
- res.setHeader('Content-Type', 'application/json');
- res.end(JSON.stringify(ret.body || {}), 'utf8');
- });
+ checkHealth(function(ret) {
+ console.log ((new Date()).toISOString() + ": " + JSON.stringify(ret));
+ res.statusCode = ret.status;
+ res.setHeader('Content-Type', 'application/json');
+ res.end(JSON.stringify(ret.body || {}), 'utf8');
+ });
});
server.listen(80);