From c390a0507644dd89476d69f4ac1755973ce6d634 Mon Sep 17 00:00:00 2001 From: Wyatt Preul Date: Fri, 15 Sep 2017 11:44:12 -0500 Subject: [PATCH] feat(portal-api): use primaryIp for health checks --- docker-compose.yml | 2 +- docker/api/package.json | 4 +- local-compose.yml | 2 +- .../portal-api/lib/watch/container-pilot.js | 71 +++---------------- packages/portal-api/package.json | 2 +- 5 files changed, 14 insertions(+), 67 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1e0a4898..f1d52ea3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -81,7 +81,7 @@ frontend: # BACKEND ############################################################################# api: - image: joyent/copilot-api:1.8.9 + image: joyent/copilot-api:1.8.10 mem_limit: 1g expose: - 3000 diff --git a/docker/api/package.json b/docker/api/package.json index 0ce8185b..54a09b44 100644 --- a/docker/api/package.json +++ b/docker/api/package.json @@ -1,6 +1,6 @@ { "name": "api", - "version": "1.0.0", + "version": "1.8.10", "description": "", "main": "./server.js", "scripts": { @@ -21,7 +21,7 @@ "joi": "^10.6.0", "joyent-cp-gql-schema": "^1.7.0", "piloted": "^3.1.1", - "portal-api": "^1.8.9", + "portal-api": "^1.8.10", "toppsy": "^1.1.0", "triton": "^5.2.0" } diff --git a/local-compose.yml b/local-compose.yml index 8aa54ea2..f809db94 100644 --- a/local-compose.yml +++ b/local-compose.yml @@ -66,7 +66,7 @@ frontend: # BACKEND ############################################################################# api: - image: joyent/copilot-api:1.8.9 + image: joyent/copilot-api:1.8.10 mem_limit: 512m links: - consul:consul diff --git a/packages/portal-api/lib/watch/container-pilot.js b/packages/portal-api/lib/watch/container-pilot.js index ff8cfcb3..0415c872 100644 --- a/packages/portal-api/lib/watch/container-pilot.js +++ b/packages/portal-api/lib/watch/container-pilot.js @@ -120,55 +120,10 @@ module.exports = class ContainerPilotWatcher extends Events { this._data.getPortal({}, getDeploymentGroups); } - _getNetworks (networkIds = [], cb) { - VAsync.forEachParallel({ - inputs: networkIds, - func: (id, next) => { - this._triton.getNetwork(id, next); - } - }, (err, results) => { - cb(err, ForceArray((results || {}).successes)); - }); - } - - _getPublicIps (machine, cb) { - this._getNetworks(machine.networks, (err, networks) => { - if (err) { - return cb(err); - } - - const privateNetworkSubnets = networks - .filter((network) => { - return !network['public']; - }) - .map((network) => { - return network.subnet; - }) - .filter(Boolean); - - const cidr = new CIDRMatcher(privateNetworkSubnets); - - const nonPrivateIps = machine.ips.filter((ip) => { - return !cidr.contains(ip); - }); - - cb(null, nonPrivateIps); - }); - } - _fetchInstanceStatus (instance, cb) { const { machineId } = instance; - const handleStatuses = (err, results) => { - if (err) { - this.emit('error', err); - return cb(); - } - - const statuses = ForceArray((results || {}).successes); - - const status = statuses.filter(Boolean).shift(); - + const handleStatus = (status) => { if (!status) { return cb(null, instance); } @@ -184,39 +139,31 @@ module.exports = class ContainerPilotWatcher extends Events { })); }; - const fetchStatus = (ip, next) => { + const fetchStatus = (ip) => { Wreck.get(`http://${ip}:9090/status`, { timeout: 2000, // 2 seconds json: 'force' }, (err, res, status) => { if (err) { this.emit('error', err); - return next(); + return cb(); } - next(null, status); + handleStatus(status); }); }; - const handlePublicIps = (err, ips) => { - if (err) { - this.emit('error', err); - return cb(); - } - - VAsync.forEachParallel({ - inputs: ips, - func: fetchStatus - }, handleStatuses); - }; - this._triton.getMachine(machineId, (err, machine) => { if (err) { this.emit('error', err); return cb(); } - this._getPublicIps(machine, handlePublicIps); + if (!machine) { + return cb(); + } + + fetchStatus(machine.primaryIp); }); } diff --git a/packages/portal-api/package.json b/packages/portal-api/package.json index 778c930b..06abeb2d 100644 --- a/packages/portal-api/package.json +++ b/packages/portal-api/package.json @@ -1,6 +1,6 @@ { "name": "portal-api", - "version": "1.8.9", + "version": "1.8.10", "description": "", "main": "./lib/index.js", "scripts": {