Skip to content

Commit

Permalink
#538 wip
Browse files Browse the repository at this point in the history
  • Loading branch information
arawinters committed Apr 9, 2024
1 parent 0901af0 commit 53de52a
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 89 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ ARG PROD_IMAGE=node:16-alpine3.18@sha256:a1f9d027912b58a7c75be7716c97cfbc6d3099f
ARG TEST_IMAGE=node:16-bullseye-slim@sha256:503446c15c6236291222f8192513c2eb56a02a8949cbadf4fe78cce19815c734

FROM ${BUILD_IMAGE}
ENV REFRESHED_AT=2023-09-29
ENV REFRESHED_AT=2024-04-09

LABEL Name="senzing/entity-search-web-app" \
Maintainer="[email protected]" \
Version="2.9.2"
Version="2.9.3"

HEALTHCHECK CMD ["/app/healthcheck.sh"]

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@senzing/entity-search-web-app",
"version": "2.9.3",
"version": "2.9.4",
"license": "Apache-2.0",
"scripts": {
"ng": "ng",
Expand Down
46 changes: 35 additions & 11 deletions run/health/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,42 @@ const inMemoryConfig = require("../runtime.datastore");
const inMemoryConfigFromInputs = require('../runtime.datastore.config');

if(inMemoryConfigFromInputs && inMemoryConfigFromInputs.web && inMemoryConfigFromInputs.web.url) {
let hcUrl = inMemoryConfigFromInputs.web.url + '/health';
var request = http.get(hcUrl, (res) => {
if (res.statusCode == 200) {
process.exit(0);
} else {
process.exit(1);
let hcUrl = inMemoryConfigFromInputs.web.url + '/health';
let protocol = inMemoryConfigFromInputs.web.protocol ? inMemoryConfigFromInputs.web.protocol : undefined;
if(protocol === undefined && hcUrl && hcUrl.indexOf && hcUrl.indexOf('://')) {
// try and get it from web url
let url_parts = hcUrl.split('://');
if(url_parts && url_parts[0]) {
protocol = url_parts[0];
}
});
request.on("error", function (err) {
process.exit(1);
});
request.end();
}
if(protocol === 'https') {
// use ssl
var request = https.get(hcUrl, (res) => {
if (res.statusCode == 200) {
process.exit(0);
} else {
process.exit(1);
}
});
request.on("error", function (err) {
process.exit(1);
});
request.end();
} else {
// assume http
var request = http.get(hcUrl, (res) => {
if (res.statusCode == 200) {
process.exit(0);
} else {
process.exit(1);
}
});
request.on("error", function (err) {
process.exit(1);
});
request.end();
}
} else {
process.exit(1);
}
158 changes: 117 additions & 41 deletions run/health/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const http = require('http');
const https = require('https');
let EventEmitter = require('events').EventEmitter;
const { replacePortNumber } = require("../utils");

Expand Down Expand Up @@ -31,31 +32,69 @@ class HealthCheckerUtility extends EventEmitter {
return this.inMemoryConfig.config;
}
checkIfWebServerAlive() {
let reqUrl = this.config.web.url;
let req = http.get(reqUrl, (res => {
//console.log('checkIfWebServerAlive.response: ', res.statusCode);
//res.on('end',(() => {
if(res.statusCode === 200) {
if(this.isWebserverAlive !== true) {
this.isWebserverAlive = true;
let reqUrl = this.config.web.url;
let protocol = this.config.web.protocol ? this.config.web.protocol : undefined;
if(protocol === undefined && reqUrl && reqUrl.indexOf && reqUrl.indexOf('://')) {
// try and get it from web url
let url_parts = reqUrl.split('://');
if(url_parts && url_parts[0]) {
protocol = url_parts[0];
}
}
if(protocol === 'https') {
// use ssl
let req = https.get(reqUrl, (res => {
//console.log('checkIfWebServerAlive.response: ', res.statusCode);
//res.on('end',(() => {
if(res.statusCode === 200) {
if(this.isWebserverAlive !== true) {
this.isWebserverAlive = true;
this.emit('statusChange', this.status);
}
//console.log('Response ended: \n', _dataRes);
} else if(this.isWebserverAlive == true) {
this.isWebserverAlive = false;
this.emit('statusChange', this.status);
}
//}).bind(this));

}).bind(this)).on('error', (error => {
//console.log('checkIfWebServerAlive: '+ error.code +' | ['+ reqUrl +']');
if(this.isWebserverAlive == true) {
this.isWebserverAlive = false;
this.emit('statusChange', this.status);
}
//console.log('Response ended: \n', _dataRes);
} else if(this.isWebserverAlive == true) {
this.isWebserverAlive = false;
this.emit('statusChange', this.status);
}
//}).bind(this));

}).bind(this)).on('error', (error => {
//console.log('checkIfWebServerAlive: '+ error.code +' | ['+ reqUrl +']');
if(this.isWebserverAlive == true) {
//console.log(error)
}).bind(this))
} else {
// assume http
let req = http.get(reqUrl, (res => {
//console.log('checkIfWebServerAlive.response: ', res.statusCode);
//res.on('end',(() => {
if(res.statusCode === 200) {
if(this.isWebserverAlive !== true) {
this.isWebserverAlive = true;
this.emit('statusChange', this.status);
}
//console.log('Response ended: \n', _dataRes);
} else if(this.isWebserverAlive == true) {
this.isWebserverAlive = false;
this.emit('statusChange', this.status);
}
//}).bind(this));

}).bind(this)).on('error', (error => {
//console.log('checkIfWebServerAlive: '+ error.code +' | ['+ reqUrl +']');
if(this.isWebserverAlive == true) {
this.isWebserverAlive = false;
this.emit('statusChange', this.status);
}
this.isWebserverAlive = false;
this.emit('statusChange', this.status);
}
this.isWebserverAlive = false;
//console.log(error)
}).bind(this))
//console.log(error)
}).bind(this))
}

}
checkIfApiServerAlive() {
let reqUrl = this.config.web.apiServerUrl+'/server-info';
Expand Down Expand Up @@ -90,32 +129,69 @@ class HealthCheckerUtility extends EventEmitter {
//console.log('checkIfProxyServerAlive: port', this.config.configServer.port);
//console.log('checkIfProxyServerAlive: url', reqUrl);
//console.log(this.config);

let req = http.get(reqUrl, (res => {
//console.log('checkIfProxyServerAlive.response: ', res.statusCode);
//res.on('end',(() => {
if(res.statusCode === 200) {
//console.log('\t isProxyAlive('+ this.isProxyAlive +')', (this.isProxyAlive !== true));
if(this.isProxyAlive !== true) {
this.isProxyAlive = true;
let protocol = this.config.web.protocol ? this.config.web.protocol : undefined;
if(protocol === undefined && reqUrl && reqUrl.indexOf && reqUrl.indexOf('://')) {
// try and get it from web url
let url_parts = reqUrl.split('://');
if(url_parts && url_parts[0]) {
protocol = url_parts[0];
}
}
if(protocol === 'https') {
// use ssl
let req = https.get(reqUrl, (res => {
//console.log('checkIfProxyServerAlive.response: ', res.statusCode);
//res.on('end',(() => {
if(res.statusCode === 200) {
//console.log('\t isProxyAlive('+ this.isProxyAlive +')', (this.isProxyAlive !== true));
if(this.isProxyAlive !== true) {
this.isProxyAlive = true;
this.emit('statusChange', this.status);
}
//console.log('Response ended: \n', _dataRes);
} else if(this.isProxyAlive == true) {
this.isProxyAlive = false;
this.emit('statusChange', this.status);
}
//console.log('Response ended: \n', _dataRes);
} else if(this.isProxyAlive == true) {
//}).bind(this));

}).bind(this)).on('error', (error => {
//console.log('checkIfProxyServerAlive: '+ error.code +' | ['+ reqUrl +']');
if(this.isProxyAlive == true) {
this.isProxyAlive = false;
this.emit('statusChange', this.status);
}
//}).bind(this));

}).bind(this)).on('error', (error => {
//console.log('checkIfProxyServerAlive: '+ error.code +' | ['+ reqUrl +']');
if(this.isProxyAlive == true) {
this.isProxyAlive = false;
this.emit('statusChange', this.status);
}
this.isProxyAlive = false;
//console.log(error)
}).bind(this))
//console.log(error)
}).bind(this))
} else {
//assume http
let req = http.get(reqUrl, (res => {
//console.log('checkIfProxyServerAlive.response: ', res.statusCode);
//res.on('end',(() => {
if(res.statusCode === 200) {
//console.log('\t isProxyAlive('+ this.isProxyAlive +')', (this.isProxyAlive !== true));
if(this.isProxyAlive !== true) {
this.isProxyAlive = true;
this.emit('statusChange', this.status);
}
//console.log('Response ended: \n', _dataRes);
} else if(this.isProxyAlive == true) {
this.isProxyAlive = false;
this.emit('statusChange', this.status);
}
//}).bind(this));

}).bind(this)).on('error', (error => {
//console.log('checkIfProxyServerAlive: '+ error.code +' | ['+ reqUrl +']');
if(this.isProxyAlive == true) {
this.isProxyAlive = false;
this.emit('statusChange', this.status);
}
this.isProxyAlive = false;
//console.log(error)
}).bind(this))
}
}
}

Expand Down
Loading

0 comments on commit 53de52a

Please sign in to comment.