Merge pull request #276 from CartoDB/disable_health_check
Return failed health checks with disabled file
This commit is contained in:
commit
a664a1c550
@ -174,6 +174,7 @@ var config = {
|
|||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
}
|
}
|
||||||
|
,disabled_file: 'pids/disabled'
|
||||||
|
|
||||||
// Use this as a feature flags enabling/disabling mechanism
|
// Use this as a feature flags enabling/disabling mechanism
|
||||||
,enabledFeatures: {
|
,enabledFeatures: {
|
||||||
|
@ -183,6 +183,7 @@ var config = {
|
|||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
}
|
}
|
||||||
|
,disabled_file: 'pids/disabled'
|
||||||
|
|
||||||
// Use this as a feature flags enabling/disabling mechanism
|
// Use this as a feature flags enabling/disabling mechanism
|
||||||
,enabledFeatures: {
|
,enabledFeatures: {
|
||||||
|
@ -183,6 +183,7 @@ var config = {
|
|||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
}
|
}
|
||||||
|
,disabled_file: 'pids/disabled'
|
||||||
|
|
||||||
// Use this as a feature flags enabling/disabling mechanism
|
// Use this as a feature flags enabling/disabling mechanism
|
||||||
,enabledFeatures: {
|
,enabledFeatures: {
|
||||||
|
@ -172,6 +172,7 @@ var config = {
|
|||||||
x: 0,
|
x: 0,
|
||||||
y: 0
|
y: 0
|
||||||
}
|
}
|
||||||
|
,disabled_file: 'pids/disabled'
|
||||||
|
|
||||||
// Use this as a feature flags enabling/disabling mechanism
|
// Use this as a feature flags enabling/disabling mechanism
|
||||||
,enabledFeatures: {
|
,enabledFeatures: {
|
||||||
|
@ -42,7 +42,24 @@ HealthCheck.prototype.check = function(config, callback) {
|
|||||||
var mapnikXmlParams = config;
|
var mapnikXmlParams = config;
|
||||||
|
|
||||||
step(
|
step(
|
||||||
function getDBParams() {
|
function getManualDisable() {
|
||||||
|
fs.readFile(global.environment.disabled_file, this);
|
||||||
|
},
|
||||||
|
function handleDisabledFile(err, data) {
|
||||||
|
var next = this;
|
||||||
|
if (err) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
if (!!data) {
|
||||||
|
err = new Error(data);
|
||||||
|
err.http_status = 503;
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function getDBParams(err) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
startTime = Date.now();
|
startTime = Date.now();
|
||||||
self.metadataBackend.getAllUserDBParams(config.username, this);
|
self.metadataBackend.getAllUserDBParams(config.username, this);
|
||||||
},
|
},
|
||||||
|
@ -5,6 +5,11 @@ var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/cartodb_windshaft
|
|||||||
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options')();
|
var serverOptions = require(__dirname + '/../../lib/cartodb/server_options')();
|
||||||
var server = new CartodbWindshaft(serverOptions);
|
var server = new CartodbWindshaft(serverOptions);
|
||||||
|
|
||||||
|
var metadataBackend = {};
|
||||||
|
var tilelive = {};
|
||||||
|
var HealthCheck = require('../../lib/cartodb/monitoring/health_check');
|
||||||
|
var healthCheck = new HealthCheck(metadataBackend, tilelive);
|
||||||
|
|
||||||
suite('health checks', function () {
|
suite('health checks', function () {
|
||||||
|
|
||||||
function resetHealthConfig() {
|
function resetHealthConfig() {
|
||||||
@ -71,4 +76,44 @@ suite('health checks', function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('error if disabled file exists', function(done) {
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
var readFileFn = fs.readFile
|
||||||
|
fs.readFile = function(filename, callback) {
|
||||||
|
callback(null, "Maintenance");
|
||||||
|
}
|
||||||
|
|
||||||
|
healthCheck.check(null, function(err, result) {
|
||||||
|
assert.equal(err.message, "Maintenance");
|
||||||
|
assert.equal(err.http_status, 503);
|
||||||
|
done();
|
||||||
|
fs.readFile = readFileFn;
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
test('not err if disabled file does not exists', function(done) {
|
||||||
|
resetHealthConfig();
|
||||||
|
|
||||||
|
global.environment.disabled_file = '/tmp/ftreftrgtrccre';
|
||||||
|
|
||||||
|
assert.response(server,
|
||||||
|
healthCheckRequest,
|
||||||
|
{
|
||||||
|
status: 200
|
||||||
|
},
|
||||||
|
function (res, err) {
|
||||||
|
assert.ok(!err);
|
||||||
|
|
||||||
|
var parsed = JSON.parse(res.body);
|
||||||
|
|
||||||
|
assert.equal(parsed.enabled, true);
|
||||||
|
assert.equal(parsed.ok, true);
|
||||||
|
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user