mirror of
https://github.com/yldio/copilot.git
synced 2024-11-14 15:20:06 +02:00
feat(portal-api): use primaryIp for health checks
This commit is contained in:
parent
1b5a2bfa9a
commit
c390a05076
@ -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
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "portal-api",
|
||||
"version": "1.8.9",
|
||||
"version": "1.8.10",
|
||||
"description": "",
|
||||
"main": "./lib/index.js",
|
||||
"scripts": {
|
||||
|
Loading…
Reference in New Issue
Block a user