1
0
mirror of https://github.com/yldio/copilot.git synced 2024-11-28 06:00:06 +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
#############################################################################
api:
image: joyent/copilot-api:1.8.9
image: joyent/copilot-api:1.8.10
mem_limit: 1g
expose:
- 3000

View File

@ -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"
}

View File

@ -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

View File

@ -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,30 +139,18 @@ 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();
}
next(null, status);
});
};
const handlePublicIps = (err, ips) => {
if (err) {
this.emit('error', err);
return cb();
}
VAsync.forEachParallel({
inputs: ips,
func: fetchStatus
}, handleStatuses);
handleStatus(status);
});
};
this._triton.getMachine(machineId, (err, machine) => {
@ -216,7 +159,11 @@ module.exports = class ContainerPilotWatcher extends Events {
return cb();
}
this._getPublicIps(machine, handlePublicIps);
if (!machine) {
return cb();
}
fetchStatus(machine.primaryIp);
});
}

View File

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