1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-14 23:30:05 +02:00

feat(portal-api): use primaryIp for health checks

This commit is contained in:
Wyatt Preul 2017-09-15 11:44:12 -05:00 committed by Sérgio Ramos
parent 1b5a2bfa9a
commit c390a05076
5 changed files with 14 additions and 67 deletions

View File

@ -81,7 +81,7 @@ frontend:
# BACKEND # BACKEND
############################################################################# #############################################################################
api: api:
image: joyent/copilot-api:1.8.9 image: joyent/copilot-api:1.8.10
mem_limit: 1g mem_limit: 1g
expose: expose:
- 3000 - 3000

View File

@ -1,6 +1,6 @@
{ {
"name": "api", "name": "api",
"version": "1.0.0", "version": "1.8.10",
"description": "", "description": "",
"main": "./server.js", "main": "./server.js",
"scripts": { "scripts": {
@ -21,7 +21,7 @@
"joi": "^10.6.0", "joi": "^10.6.0",
"joyent-cp-gql-schema": "^1.7.0", "joyent-cp-gql-schema": "^1.7.0",
"piloted": "^3.1.1", "piloted": "^3.1.1",
"portal-api": "^1.8.9", "portal-api": "^1.8.10",
"toppsy": "^1.1.0", "toppsy": "^1.1.0",
"triton": "^5.2.0" "triton": "^5.2.0"
} }

View File

@ -66,7 +66,7 @@ frontend:
# BACKEND # BACKEND
############################################################################# #############################################################################
api: api:
image: joyent/copilot-api:1.8.9 image: joyent/copilot-api:1.8.10
mem_limit: 512m mem_limit: 512m
links: links:
- consul:consul - consul:consul

View File

@ -120,55 +120,10 @@ module.exports = class ContainerPilotWatcher extends Events {
this._data.getPortal({}, getDeploymentGroups); 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) { _fetchInstanceStatus (instance, cb) {
const { machineId } = instance; const { machineId } = instance;
const handleStatuses = (err, results) => { const handleStatus = (status) => {
if (err) {
this.emit('error', err);
return cb();
}
const statuses = ForceArray((results || {}).successes);
const status = statuses.filter(Boolean).shift();
if (!status) { if (!status) {
return cb(null, instance); return cb(null, instance);
} }
@ -184,30 +139,18 @@ module.exports = class ContainerPilotWatcher extends Events {
})); }));
}; };
const fetchStatus = (ip, next) => { const fetchStatus = (ip) => {
Wreck.get(`http://${ip}:9090/status`, { Wreck.get(`http://${ip}:9090/status`, {
timeout: 2000, // 2 seconds timeout: 2000, // 2 seconds
json: 'force' json: 'force'
}, (err, res, status) => { }, (err, res, status) => {
if (err) {
this.emit('error', err);
return next();
}
next(null, status);
});
};
const handlePublicIps = (err, ips) => {
if (err) { if (err) {
this.emit('error', err); this.emit('error', err);
return cb(); return cb();
} }
VAsync.forEachParallel({ handleStatus(status);
inputs: ips, });
func: fetchStatus
}, handleStatuses);
}; };
this._triton.getMachine(machineId, (err, machine) => { this._triton.getMachine(machineId, (err, machine) => {
@ -216,7 +159,11 @@ module.exports = class ContainerPilotWatcher extends Events {
return cb(); return cb();
} }
this._getPublicIps(machine, handlePublicIps); if (!machine) {
return cb();
}
fetchStatus(machine.primaryIp);
}); });
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "portal-api", "name": "portal-api",
"version": "1.8.9", "version": "1.8.10",
"description": "", "description": "",
"main": "./lib/index.js", "main": "./lib/index.js",
"scripts": { "scripts": {