From 7c389a8010da23ff9064e0bfb7b0e226a83c5d78 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Wed, 5 Nov 2014 15:06:01 +0100 Subject: [PATCH 1/7] Health check endpoint --- NEWS.md | 5 +- lib/cartodb/cartodb_windshaft.js | 26 +++++ lib/cartodb/monitoring/health_check.js | 130 +++++++++++++++++++++++++ lib/cartodb/monitoring/map-config.xml | 45 +++++++++ lib/cartodb/server_options.js | 3 +- npm-shrinkwrap.json | 4 +- package.json | 2 +- 7 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 lib/cartodb/monitoring/health_check.js create mode 100644 lib/cartodb/monitoring/map-config.xml diff --git a/NEWS.md b/NEWS.md index 69257515..e49eab41 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,12 @@ -1.21.1 -- 2014-mm-dd +1.22.0 -- 2014-mm-dd -------------------- Announcements: - Upgrades windshaft to 0.32.0 +New features: + - Health check endpoint + 1.21.0 -- 2014-10-24 -------------------- diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 216d8682..c5934428 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -5,6 +5,7 @@ var _ = require('underscore') , TemplateMaps = require('./template_maps.js') , Cache = require('./cache_validator') , os = require('os') + , HealthCheck = require('./monitoring/health_check') ; if ( ! process.env['PGAPPNAME'] ) @@ -665,6 +666,31 @@ var CartodbWindshaft = function(serverOptions) { // ---- Template maps interface ends @} + var healthCheck = new HealthCheck(cartoData, serverOptions.queryTablesApi, Windshaft.tilelive); + ws.get('/health', function(req, res) { + var healthConfig = global.environment.health || {}; + + if (!!healthConfig.enabled) { + var startTime = Date.now(); + healthCheck.check(healthConfig, function(err, result) { + var ok = !err; + var response = { + enabled: true, + ok: ok, + elapsed: Date.now() - startTime, + result: result + }; + if (err) { + response.err = err.message; + } + res.send(response, ok ? 200 : 503); + + }); + } else { + res.send({enabled: false, ok: true}, 200); + } + }); + return ws; }; diff --git a/lib/cartodb/monitoring/health_check.js b/lib/cartodb/monitoring/health_check.js new file mode 100644 index 00000000..2facc846 --- /dev/null +++ b/lib/cartodb/monitoring/health_check.js @@ -0,0 +1,130 @@ +var _ = require('underscore'), + dot = require('dot'), + fs = require('fs'), + path = require('path'), + Step = require('step'); + +function HealthCheck(metadataBackend, queryTablesApi, tilelive) { + this.metadataBackend = metadataBackend; + this.queryTablesApi = queryTablesApi; + this.tilelive = tilelive; +} + +module.exports = HealthCheck; + + +var mapnikOptions = { + query: { + metatile: 1, + poolSize: 4, + bufferSize: 64 + }, + protocol: 'mapnik:', + slashes: true, + xml: null +}; + +var xmlTemplate = dot.template(fs.readFileSync(path.resolve(__dirname, 'map-config.xml'), 'utf-8')); + +HealthCheck.prototype.check = function(config, callback) { + + var self = this, + startTime, + result = { + redis: { + ok: false + }, + postgresql: { + ok: false + }, + mapnik: { + ok: false + }, + tile: { + ok: false + } + }, + mapnikXmlParams = _.extend({ + dbport: global.environment.postgres.port + }, config); + + Step( + function getDBParams() { + startTime = Date.now(); + self.metadataBackend.getAllUserDBParams(config.username, this); + }, + function runQuery(err, dbParams) { + if (err) { + throw err; + } + + result.redis = { + ok: !err, + elapsed: Date.now() - startTime, + size: Object.keys(dbParams).length + }; + + dbParams.dbuser = _.template(global.environment.postgres_auth_user, {user_id: dbParams.dbuser}); + + mapnikXmlParams = _.extend(mapnikXmlParams, dbParams); + + startTime = Date.now(); + self.queryTablesApi.getAffectedTablesInQuery(config.username, { + user: dbParams.dbuser, + pass: dbParams.dbpass, + host: dbParams.dbhost, + port: global.environment.postgres.port, + dbname: dbParams.dbname, + api_key: dbParams.apikey + }, config.query, this); + }, + function handleAffectedTablesQuery(err, affectedTables) { + if (err) { + throw err; + } + + result.postgresql = { + ok: !err, + elapsed: Date.now() - startTime, + size: affectedTables.length + }; + + this(); + }, + function loadMapnik(err) { + if (err) { + throw err; + } + mapnikOptions.xml = xmlTemplate(mapnikXmlParams); + + console.log(mapnikOptions.xml); + startTime = Date.now(); + self.tilelive.load(mapnikOptions, this); + }, + function getTile(err, source) { + if (err) { + throw err; + } + + result.mapnik = { + ok: !err, + elapsed: Date.now() - startTime + }; + + startTime = Date.now(); + source.getTile(config.z, config.x, config.y, this); + }, + function handleTile(err, tile) { + result.tile = { + ok: !err + }; + + if (tile) { + result.tile.elapsed = Date.now() - startTime; + result.tile.size = tile.length; + } + + callback(err, result); + } + ); +}; \ No newline at end of file diff --git a/lib/cartodb/monitoring/map-config.xml b/lib/cartodb/monitoring/map-config.xml new file mode 100644 index 00000000..e81cb17a --- /dev/null +++ b/lib/cartodb/monitoring/map-config.xml @@ -0,0 +1,45 @@ + + + + + + png8:m=h + layer0 + interactivity_id + + + + + + + layer0 + layer0-labels + + + + + + + + + + + + + + + + + + + + diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index adea9a3c..d67ccd0e 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -71,7 +71,8 @@ module.exports = function(redisPool) { varnish_secret: global.environment.varnish.secret, cache_enabled: global.environment.cache_enabled, log_format: global.environment.log_format, - useProfiler: global.environment.useProfiler + useProfiler: global.environment.useProfiler, + queryTablesApi: queryTablesApi }; // Do not send unwatch on release diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index f3656c7b..453036e4 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "windshaft-cartodb", - "version": "1.21.1", + "version": "1.22.0", "dependencies": { "cartodb-psql": { "version": "0.4.0", @@ -1528,7 +1528,7 @@ }, "sphericalmercator": { "version": "1.0.2", - "from": "sphericalmercator@~1.0.2" + "from": "sphericalmercator@~1.0.1" } } }, diff --git a/package.json b/package.json index ecd7190f..d9a30a19 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "windshaft-cartodb", - "version": "1.21.1", + "version": "1.22.0", "description": "A map tile server for CartoDB", "keywords": [ "cartodb" From 97c55c11876544ae904f9656b1a411bf070babed Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Wed, 5 Nov 2014 15:42:16 +0100 Subject: [PATCH 2/7] Removes console.log --- lib/cartodb/monitoring/health_check.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/cartodb/monitoring/health_check.js b/lib/cartodb/monitoring/health_check.js index 2facc846..3845122c 100644 --- a/lib/cartodb/monitoring/health_check.js +++ b/lib/cartodb/monitoring/health_check.js @@ -97,7 +97,6 @@ HealthCheck.prototype.check = function(config, callback) { } mapnikOptions.xml = xmlTemplate(mapnikXmlParams); - console.log(mapnikOptions.xml); startTime = Date.now(); self.tilelive.load(mapnikOptions, this); }, From 6c4bb59f068f4e5c5ba3d741f7f367da30d4e6d0 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Wed, 5 Nov 2014 15:42:28 +0100 Subject: [PATCH 3/7] First tests, not all ready. WIP --- test/acceptance/health_check.js | 141 ++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 test/acceptance/health_check.js diff --git a/test/acceptance/health_check.js b/test/acceptance/health_check.js new file mode 100644 index 00000000..b5cc44e6 --- /dev/null +++ b/test/acceptance/health_check.js @@ -0,0 +1,141 @@ +var helper = require(__dirname + '/../support/test_helper'); + +var assert = require('../support/assert'); +var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/cartodb_windshaft'); +var serverOptions = require(__dirname + '/../../lib/cartodb/server_options')(); +var server = new CartodbWindshaft(serverOptions); + +var SQLAPIEmu = require(__dirname + '/../support/SQLAPIEmu.js'); + + +[true, false].forEach(function(cdbQueryTablesFromPostgresEnabledValue) { + + global.environment.enabledFeatures = {cdbQueryTablesFromPostgres: cdbQueryTablesFromPostgresEnabledValue}; + + suite('health checks - postgres=' + cdbQueryTablesFromPostgresEnabledValue, function () { + + beforeEach(function (done) { + global.environment.health = { + enabled: true, + username: 'localhost', + query: "SELECT 1::int as interactivity_id, '0101000020110F0000EE866678CE876D41466F35C2EC1150C1'::geometry as geom, 'Lorem ipsum dolor sit amet' as label", + srid: 3857, + geometry_field: 'geom', + z: 0, + x: 0, + y: 0 + }; + done(); + }); + + if (!cdbQueryTablesFromPostgresEnabledValue) { + var sqlApiServer; + + before(function (done) { + sqlApiServer = new SQLAPIEmu(global.environment.sqlapi.port, done); + }); + + after(function (done) { + sqlApiServer.close(done); + }); + } + + var healthCheckRequest = { + url: '/health', + method: 'GET', + headers: { + host: 'localhost' + } + }; + + test('returns 200 and ok=true with disabled configuration', function (done) { + global.environment.health.enabled = false; + + assert.response(server, + healthCheckRequest, + { + status: 200 + }, + function (res, err) { + assert.ok(!err); + + var parsed = JSON.parse(res.body); + + assert.equal(parsed.enabled, false); + assert.ok(parsed.ok); + + done(); + } + ); + }); + + test('returns 200 and ok=true with enabled configuration', function (done) { + assert.response(server, + healthCheckRequest, + { + status: 200 + }, + function (res, err) { + assert.ok(!err); + + var parsed = JSON.parse(res.body); + + assert.ok(parsed.enabled); + assert.ok(parsed.ok); + + done(); + } + ); + }); + + test('fails for invalid user because it is not in redis', function (done) { + global.environment.health.username = 'invalid'; + + assert.response(server, + healthCheckRequest, + { + status: 503 + }, + function (res, err) { + assert.ok(!err); + + var parsed = JSON.parse(res.body); + + assert.equal(parsed.enabled, true); + assert.equal(parsed.ok, false); + + assert.equal(parsed.result.redis.ok, false); + + done(); + } + ); + }); + + test.skip('fails for wrong query', function (done) { + global.environment.health.query = 'select wadus query'; + + assert.response(server, + healthCheckRequest, + { + status: 503 + }, + function (res, err) { + assert.ok(!err); + + var parsed = JSON.parse(res.body); + + assert.equal(parsed.enabled, true); + assert.equal(parsed.ok, false); + + assert.ok(parsed.result.redis.ok); + + assert.equal(parsed.result.postgresql.ok, false); + + done(); + } + ); + }); + + }); + +}); \ No newline at end of file From db9d350cae5f3b1e2bd125030c8148484568cdeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Mart=C3=ADnez?= Date: Mon, 12 Jan 2015 16:00:39 +0100 Subject: [PATCH 4/7] Add healthcheck configuration examples --- config/environments/development.js.example | 11 +++++++++++ config/environments/production.js.example | 11 +++++++++++ config/environments/staging.js.example | 11 +++++++++++ config/environments/test.js.example | 11 +++++++++++ 4 files changed, 44 insertions(+) diff --git a/config/environments/development.js.example b/config/environments/development.js.example index d684cd7f..9627c905 100644 --- a/config/environments/development.js.example +++ b/config/environments/development.js.example @@ -150,6 +150,17 @@ var config = { // X-Tiler-Profile header containing elapsed timing for various // steps taken for producing the response. ,useProfiler:true + // Settings for the health check available at /health + ,health: { + enabled: false, + username: 'localhost', + query: "SELECT 1::int as interactivity_id, '0101000020110F0000EE866678CE876D41466F35C2EC1150C1'::geometry as geom, 'Lorem ipsum dolor sit amet' as label", + srid: 3857, + geometry_field: 'geom', + z: 0, + x: 0, + y: 0 + } }; module.exports = config; diff --git a/config/environments/production.js.example b/config/environments/production.js.example index 54b85364..2fc6b0bd 100644 --- a/config/environments/production.js.example +++ b/config/environments/production.js.example @@ -159,6 +159,17 @@ var config = { handler: 'inline' } } + // Settings for the health check available at /health + ,health: { + enabled: true, + username: 'localhost', + query: "SELECT 1::int as interactivity_id, '0101000020110F0000EE866678CE876D41466F35C2EC1150C1'::geometry as geom, 'Lorem ipsum dolor sit amet' as label", + srid: 3857, + geometry_field: 'geom', + z: 0, + x: 0, + y: 0 + } }; module.exports = config; diff --git a/config/environments/staging.js.example b/config/environments/staging.js.example index 23baf426..dd2a5bb3 100644 --- a/config/environments/staging.js.example +++ b/config/environments/staging.js.example @@ -159,6 +159,17 @@ var config = { handler: 'inline' } } + // Settings for the health check available at /health + ,health: { + enabled: false, + username: 'localhost', + query: "SELECT 1::int as interactivity_id, '0101000020110F0000EE866678CE876D41466F35C2EC1150C1'::geometry as geom, 'Lorem ipsum dolor sit amet' as label", + srid: 3857, + geometry_field: 'geom', + z: 0, + x: 0, + y: 0 + } }; module.exports = config; diff --git a/config/environments/test.js.example b/config/environments/test.js.example index db807c85..1af3c978 100644 --- a/config/environments/test.js.example +++ b/config/environments/test.js.example @@ -146,6 +146,17 @@ var config = { // X-Tiler-Profile header containing elapsed timing for various // steps taken for producing the response. ,useProfiler:true + // Settings for the health check available at /health + ,health: { + enabled: false, + username: 'localhost', + query: "SELECT 1::int as interactivity_id, '0101000020110F0000EE866678CE876D41466F35C2EC1150C1'::geometry as geom, 'Lorem ipsum dolor sit amet' as label", + srid: 3857, + geometry_field: 'geom', + z: 0, + x: 0, + y: 0 + } }; module.exports = config; From 96bcd14bb848b6f19765d2eabb7974aa9d20f3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Mart=C3=ADnez?= Date: Tue, 13 Jan 2015 11:29:19 +0100 Subject: [PATCH 5/7] Remove PostgreSQL from health checks This way the health checks will only check for Redis and Mapnik initialization. An empty tile without layers or datasources is generated. --- config/environments/development.js.example | 3 - config/environments/production.js.example | 3 - config/environments/staging.js.example | 3 - config/environments/test.js.example | 3 - lib/cartodb/monitoring/health_check.js | 46 ++------------ lib/cartodb/monitoring/map-config.xml | 47 +------------- test/acceptance/health_check.js | 71 +--------------------- 7 files changed, 10 insertions(+), 166 deletions(-) diff --git a/config/environments/development.js.example b/config/environments/development.js.example index 9627c905..73c3fd6a 100644 --- a/config/environments/development.js.example +++ b/config/environments/development.js.example @@ -154,9 +154,6 @@ var config = { ,health: { enabled: false, username: 'localhost', - query: "SELECT 1::int as interactivity_id, '0101000020110F0000EE866678CE876D41466F35C2EC1150C1'::geometry as geom, 'Lorem ipsum dolor sit amet' as label", - srid: 3857, - geometry_field: 'geom', z: 0, x: 0, y: 0 diff --git a/config/environments/production.js.example b/config/environments/production.js.example index 2fc6b0bd..7e472c8f 100644 --- a/config/environments/production.js.example +++ b/config/environments/production.js.example @@ -163,9 +163,6 @@ var config = { ,health: { enabled: true, username: 'localhost', - query: "SELECT 1::int as interactivity_id, '0101000020110F0000EE866678CE876D41466F35C2EC1150C1'::geometry as geom, 'Lorem ipsum dolor sit amet' as label", - srid: 3857, - geometry_field: 'geom', z: 0, x: 0, y: 0 diff --git a/config/environments/staging.js.example b/config/environments/staging.js.example index dd2a5bb3..e1e04717 100644 --- a/config/environments/staging.js.example +++ b/config/environments/staging.js.example @@ -163,9 +163,6 @@ var config = { ,health: { enabled: false, username: 'localhost', - query: "SELECT 1::int as interactivity_id, '0101000020110F0000EE866678CE876D41466F35C2EC1150C1'::geometry as geom, 'Lorem ipsum dolor sit amet' as label", - srid: 3857, - geometry_field: 'geom', z: 0, x: 0, y: 0 diff --git a/config/environments/test.js.example b/config/environments/test.js.example index 1af3c978..d38e0e6e 100644 --- a/config/environments/test.js.example +++ b/config/environments/test.js.example @@ -150,9 +150,6 @@ var config = { ,health: { enabled: false, username: 'localhost', - query: "SELECT 1::int as interactivity_id, '0101000020110F0000EE866678CE876D41466F35C2EC1150C1'::geometry as geom, 'Lorem ipsum dolor sit amet' as label", - srid: 3857, - geometry_field: 'geom', z: 0, x: 0, y: 0 diff --git a/lib/cartodb/monitoring/health_check.js b/lib/cartodb/monitoring/health_check.js index 3845122c..069a5e81 100644 --- a/lib/cartodb/monitoring/health_check.js +++ b/lib/cartodb/monitoring/health_check.js @@ -34,67 +34,29 @@ HealthCheck.prototype.check = function(config, callback) { redis: { ok: false }, - postgresql: { - ok: false - }, mapnik: { ok: false }, tile: { ok: false } - }, - mapnikXmlParams = _.extend({ - dbport: global.environment.postgres.port - }, config); + }; + mapnikXmlParams = config; Step( function getDBParams() { startTime = Date.now(); self.metadataBackend.getAllUserDBParams(config.username, this); }, - function runQuery(err, dbParams) { + function loadMapnik(err, dbParams) { if (err) { throw err; } - result.redis = { ok: !err, elapsed: Date.now() - startTime, size: Object.keys(dbParams).length }; - - dbParams.dbuser = _.template(global.environment.postgres_auth_user, {user_id: dbParams.dbuser}); - - mapnikXmlParams = _.extend(mapnikXmlParams, dbParams); - - startTime = Date.now(); - self.queryTablesApi.getAffectedTablesInQuery(config.username, { - user: dbParams.dbuser, - pass: dbParams.dbpass, - host: dbParams.dbhost, - port: global.environment.postgres.port, - dbname: dbParams.dbname, - api_key: dbParams.apikey - }, config.query, this); - }, - function handleAffectedTablesQuery(err, affectedTables) { - if (err) { - throw err; - } - - result.postgresql = { - ok: !err, - elapsed: Date.now() - startTime, - size: affectedTables.length - }; - - this(); - }, - function loadMapnik(err) { - if (err) { - throw err; - } mapnikOptions.xml = xmlTemplate(mapnikXmlParams); startTime = Date.now(); @@ -126,4 +88,4 @@ HealthCheck.prototype.check = function(config, callback) { callback(err, result); } ); -}; \ No newline at end of file +}; diff --git a/lib/cartodb/monitoring/map-config.xml b/lib/cartodb/monitoring/map-config.xml index e81cb17a..91a271e1 100644 --- a/lib/cartodb/monitoring/map-config.xml +++ b/lib/cartodb/monitoring/map-config.xml @@ -1,45 +1,4 @@ - - - - - - png8:m=h - layer0 - interactivity_id - - - - - - - layer0 - layer0-labels - - - - - - - - - - - - - - - - - - - + diff --git a/test/acceptance/health_check.js b/test/acceptance/health_check.js index b5cc44e6..7044f504 100644 --- a/test/acceptance/health_check.js +++ b/test/acceptance/health_check.js @@ -8,19 +8,12 @@ var server = new CartodbWindshaft(serverOptions); var SQLAPIEmu = require(__dirname + '/../support/SQLAPIEmu.js'); -[true, false].forEach(function(cdbQueryTablesFromPostgresEnabledValue) { - - global.environment.enabledFeatures = {cdbQueryTablesFromPostgres: cdbQueryTablesFromPostgresEnabledValue}; - - suite('health checks - postgres=' + cdbQueryTablesFromPostgresEnabledValue, function () { + suite('health checks', function () { beforeEach(function (done) { global.environment.health = { enabled: true, username: 'localhost', - query: "SELECT 1::int as interactivity_id, '0101000020110F0000EE866678CE876D41466F35C2EC1150C1'::geometry as geom, 'Lorem ipsum dolor sit amet' as label", - srid: 3857, - geometry_field: 'geom', z: 0, x: 0, y: 0 @@ -28,18 +21,6 @@ var SQLAPIEmu = require(__dirname + '/../support/SQLAPIEmu.js'); done(); }); - if (!cdbQueryTablesFromPostgresEnabledValue) { - var sqlApiServer; - - before(function (done) { - sqlApiServer = new SQLAPIEmu(global.environment.sqlapi.port, done); - }); - - after(function (done) { - sqlApiServer.close(done); - }); - } - var healthCheckRequest = { url: '/health', method: 'GET', @@ -48,27 +29,6 @@ var SQLAPIEmu = require(__dirname + '/../support/SQLAPIEmu.js'); } }; - test('returns 200 and ok=true with disabled configuration', function (done) { - global.environment.health.enabled = false; - - assert.response(server, - healthCheckRequest, - { - status: 200 - }, - function (res, err) { - assert.ok(!err); - - var parsed = JSON.parse(res.body); - - assert.equal(parsed.enabled, false); - assert.ok(parsed.ok); - - done(); - } - ); - }); - test('returns 200 and ok=true with enabled configuration', function (done) { assert.response(server, healthCheckRequest, @@ -76,6 +36,7 @@ var SQLAPIEmu = require(__dirname + '/../support/SQLAPIEmu.js'); status: 200 }, function (res, err) { + console.log(res.body); assert.ok(!err); var parsed = JSON.parse(res.body); @@ -111,31 +72,5 @@ var SQLAPIEmu = require(__dirname + '/../support/SQLAPIEmu.js'); ); }); - test.skip('fails for wrong query', function (done) { - global.environment.health.query = 'select wadus query'; - assert.response(server, - healthCheckRequest, - { - status: 503 - }, - function (res, err) { - assert.ok(!err); - - var parsed = JSON.parse(res.body); - - assert.equal(parsed.enabled, true); - assert.equal(parsed.ok, false); - - assert.ok(parsed.result.redis.ok); - - assert.equal(parsed.result.postgresql.ok, false); - - done(); - } - ); - }); - - }); - -}); \ No newline at end of file +}); From aad2a1e0987a1f56a5897a604f69d635b5ed183a Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Tue, 13 Jan 2015 12:01:34 +0100 Subject: [PATCH 6/7] Regenerate npm-shrinkwrap.json --- npm-shrinkwrap.json | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 5a1e1a1e..760a1f96 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "windshaft-cartodb", - "version": "1.22.0", + "version": "1.21.3", "dependencies": { "cartodb-psql": { "version": "0.4.0", @@ -96,7 +96,7 @@ }, "inherits": { "version": "2.0.1", - "from": "inherits@2" + "from": "inherits@~2.0.1" } } } @@ -149,6 +149,7 @@ "rollbar": { "version": "0.3.13", "from": "rollbar@~0.3.13", + "resolved": "https://registry.npmjs.org/rollbar/-/rollbar-0.3.13.tgz", "dependencies": { "node-uuid": { "version": "1.4.2", @@ -302,21 +303,23 @@ "from": "tunnel-agent@~0.3.0" }, "http-signature": { - "version": "0.10.0", + "version": "0.10.1", "from": "http-signature@~0.10.0", + "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-0.10.1.tgz", "dependencies": { "assert-plus": { - "version": "0.1.2", - "from": "assert-plus@0.1.2" + "version": "0.1.5", + "from": "assert-plus@^0.1.5", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-0.1.5.tgz" }, "asn1": { "version": "0.1.11", "from": "asn1@0.1.11" }, "ctype": { - "version": "0.5.2", - "from": "ctype@0.5.2", - "resolved": "https://registry.npmjs.org/ctype/-/ctype-0.5.2.tgz" + "version": "0.5.3", + "from": "ctype@0.5.3", + "resolved": "https://registry.npmjs.org/ctype/-/ctype-0.5.3.tgz" } } }, @@ -1615,9 +1618,9 @@ "resolved": "https://registry.npmjs.org/connect/-/connect-1.9.2.tgz", "dependencies": { "formidable": { - "version": "1.0.15", + "version": "1.0.16", "from": "formidable@1.0.x", - "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.0.15.tgz" + "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.0.16.tgz" } } }, @@ -1659,14 +1662,9 @@ } }, "sphericalmercator": { -<<<<<<< HEAD - "version": "1.0.2", - "from": "sphericalmercator@~1.0.1" -======= "version": "1.0.3", "from": "sphericalmercator@~1.0.1", "resolved": "https://registry.npmjs.org/sphericalmercator/-/sphericalmercator-1.0.3.tgz" ->>>>>>> origin/master } } }, @@ -1686,7 +1684,7 @@ }, "sphericalmercator": { "version": "1.0.3", - "from": "sphericalmercator@~1.0.1", + "from": "sphericalmercator@~1.0.2", "resolved": "https://registry.npmjs.org/sphericalmercator/-/sphericalmercator-1.0.3.tgz" } } From 3f1aa9955b34b656af36863f32e95d371b8cf46a Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Tue, 13 Jan 2015 12:09:02 +0100 Subject: [PATCH 7/7] Remove query tables api dependency from health check --- lib/cartodb/cartodb_windshaft.js | 2 +- lib/cartodb/monitoring/health_check.js | 3 +- lib/cartodb/server_options.js | 3 +- test/acceptance/health_check.js | 104 ++++++++++++------------- 4 files changed, 53 insertions(+), 59 deletions(-) diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index c5934428..63dc4081 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -666,7 +666,7 @@ var CartodbWindshaft = function(serverOptions) { // ---- Template maps interface ends @} - var healthCheck = new HealthCheck(cartoData, serverOptions.queryTablesApi, Windshaft.tilelive); + var healthCheck = new HealthCheck(cartoData, Windshaft.tilelive); ws.get('/health', function(req, res) { var healthConfig = global.environment.health || {}; diff --git a/lib/cartodb/monitoring/health_check.js b/lib/cartodb/monitoring/health_check.js index 069a5e81..873cd19d 100644 --- a/lib/cartodb/monitoring/health_check.js +++ b/lib/cartodb/monitoring/health_check.js @@ -4,9 +4,8 @@ var _ = require('underscore'), path = require('path'), Step = require('step'); -function HealthCheck(metadataBackend, queryTablesApi, tilelive) { +function HealthCheck(metadataBackend, tilelive) { this.metadataBackend = metadataBackend; - this.queryTablesApi = queryTablesApi; this.tilelive = tilelive; } diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index d67ccd0e..adea9a3c 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -71,8 +71,7 @@ module.exports = function(redisPool) { varnish_secret: global.environment.varnish.secret, cache_enabled: global.environment.cache_enabled, log_format: global.environment.log_format, - useProfiler: global.environment.useProfiler, - queryTablesApi: queryTablesApi + useProfiler: global.environment.useProfiler }; // Do not send unwatch on release diff --git a/test/acceptance/health_check.js b/test/acceptance/health_check.js index 7044f504..af8c361e 100644 --- a/test/acceptance/health_check.js +++ b/test/acceptance/health_check.js @@ -5,72 +5,68 @@ var CartodbWindshaft = require(__dirname + '/../../lib/cartodb/cartodb_windshaft var serverOptions = require(__dirname + '/../../lib/cartodb/server_options')(); var server = new CartodbWindshaft(serverOptions); -var SQLAPIEmu = require(__dirname + '/../support/SQLAPIEmu.js'); +suite('health checks', function () { - - - suite('health checks', function () { - beforeEach(function (done) { - global.environment.health = { - enabled: true, - username: 'localhost', - z: 0, - x: 0, - y: 0 - }; - done(); - }); - - var healthCheckRequest = { - url: '/health', - method: 'GET', - headers: { - host: 'localhost' - } + beforeEach(function (done) { + global.environment.health = { + enabled: true, + username: 'localhost', + z: 0, + x: 0, + y: 0 }; + done(); + }); - test('returns 200 and ok=true with enabled configuration', function (done) { - assert.response(server, - healthCheckRequest, - { - status: 200 - }, - function (res, err) { - console.log(res.body); - assert.ok(!err); + var healthCheckRequest = { + url: '/health', + method: 'GET', + headers: { + host: 'localhost' + } + }; - var parsed = JSON.parse(res.body); + test('returns 200 and ok=true with enabled configuration', function (done) { + assert.response(server, + healthCheckRequest, + { + status: 200 + }, + function (res, err) { + console.log(res.body); + assert.ok(!err); - assert.ok(parsed.enabled); - assert.ok(parsed.ok); + var parsed = JSON.parse(res.body); - done(); - } - ); - }); + assert.ok(parsed.enabled); + assert.ok(parsed.ok); - test('fails for invalid user because it is not in redis', function (done) { - global.environment.health.username = 'invalid'; + done(); + } + ); + }); - assert.response(server, - healthCheckRequest, - { - status: 503 - }, - function (res, err) { - assert.ok(!err); + test('fails for invalid user because it is not in redis', function (done) { + global.environment.health.username = 'invalid'; - var parsed = JSON.parse(res.body); + assert.response(server, + healthCheckRequest, + { + status: 503 + }, + function (res, err) { + assert.ok(!err); - assert.equal(parsed.enabled, true); - assert.equal(parsed.ok, false); + var parsed = JSON.parse(res.body); - assert.equal(parsed.result.redis.ok, false); + assert.equal(parsed.enabled, true); + assert.equal(parsed.ok, false); - done(); - } - ); - }); + assert.equal(parsed.result.redis.ok, false); + done(); + } + ); + }); });