Skip to content

Commit

Permalink
Update documentation & add ES reset in GET /health* endpoint
Browse files Browse the repository at this point in the history
- the /health endpoint now checks availability of ES host
  - if ES is available, the `useES` setting will be set to `true`
  • Loading branch information
mverkerk-godaddy committed Jan 5, 2018
1 parent 6ad63fa commit 44d628a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
6 changes: 3 additions & 3 deletions CONFIG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ The config file can be located **anywhere on your local filesystem**. Point the

## Startup commands

Install type|Startup command
Install type|Startup command (where `{path}` is the absolute path to the config file)
---|---
docker-compose|`$ docker-compose -e CONFIGFILE={path} up`
docker-compose|`$ CONFIGFILE={path} docker-compose up`
git clone|`$ node ./server.js --config-file {path}`
NPM global install|`$ timings --config-file {path}`
Docker (stand-alone)|`$ docker run -d -v {path to config}:/src/.config.js -p {VM_port}:{Host_port} mverkerk/timings:{version}`
Docker (stand-alone)|`$ docker run -d -v {path}:/src/.config.js -p {VM_port}:{Host_port} mverkerk/timings:{version}`

NOTE: For non-docker installs, you may need elevated permissions to run the API on ports < 1024

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ For more info, check the repo here: [https://github.com/Verkurkie/timings-docker
Activity|Command
---|---
Install|`$ git clone https://github.com/verkurkie/timings-docker`
Startup|`$ cd timings-docker`<br>`$ docker-compose -e CONFIGFILE={path} up`
Upgrade|`$ git pull`<br>`$ docker-compose -e CONFIGFILE={path} up --build`
Config|Can Can be anywhere! Use `-e CONFIGFILE={path}` argument for docker-compose!
Startup|`$ cd timings-docker`<br>`$ CONFIGFILE={path} docker-compose up`
Upgrade|`$ git pull`<br>`$ CONFIGFILE={path} docker-compose up --build`
Config|Can Can be anywhere! Set `$ CONFIGFILE={path}` variable before the docker-compose command!

## Git clone

Expand Down
34 changes: 24 additions & 10 deletions routes/v2/static-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const router = express.Router();
const path = require('path');
// const config = require('../../.config.js');
const nconf = require('nconf');
const esUtils = require('../../src/v2/es-utils');

const htmlDir = path.join(__dirname, '../../public/');

Expand All @@ -21,20 +22,33 @@ router.get('/waterfall', function (req, res) {
});

router.get('/health*', function (req, res) {
res.send(health());
checkES(new esUtils.ESClass())
.then(function (resp) {
res.send(health(resp));
});
});

router.get('/v2/api/cicd/health*', function (req, res) {
res.send(health());
checkES(new esUtils.ESClass())
.then(function (resp) {
res.send(health(resp));
});
});

// // Catch-all -> Not Found page
// router.get('*', function (req, res) {
// res.sendFile(htmlDir + '404.html');
// });

function health() {
async function checkES(es) {
try {
await es.ping(500);
nconf.set('env:useES', true);
return { result: `ES server [${nconf.get('env:ES_HOST')}:${nconf.get('env:ES_PORT')}] is available!` };
} catch (err) {
return {
result: `ES server [${nconf.get('env:ES_HOST')}:${nconf.get('env:ES_PORT')}] could not be reached`,
error: err.message
};
}
}

function health(resp) {
const ret = {
server: {
APP_HOST: nconf.get('env:HOST') + ':' + nconf.get('env:HTTP_PORT'),
Expand Down Expand Up @@ -68,10 +82,10 @@ function health() {
KB_HOST: nconf.get('env:KB_HOST') || 'Not set!',
KB_PORT: nconf.get('env:KB_PORT') || 'Not set!'
};
} else {
ret.es = resp;
}

return ret;

}

function secToTimeString(sec) {
Expand Down
4 changes: 2 additions & 2 deletions src/v2/es-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class ESClass {
this.client = new elasticsearch.Client(esConfig);
}

async ping() {
await this.client.ping({ requestTimeout: 5000 })
async ping(timeout) {
await this.client.ping({ requestTimeout: (timeout || 5000) })
.then(function (resp) {
return resp;
}, function (err) {
Expand Down

0 comments on commit 44d628a

Please sign in to comment.