From c25678cc28462204a3c4de479406c7621879cd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Sat, 4 Apr 2020 17:42:26 +0200 Subject: [PATCH] Remove `/version` endpoint and bootstrapFonts at process startup (now done in windshaft) --- lib/server-info-controller.js | 4 +- lib/server.js | 61 +-------------------- test/acceptance/cache/cache-headers-test.js | 9 --- test/acceptance/ported/server-test.js | 23 -------- test/acceptance/server-test.js | 17 ------ 5 files changed, 2 insertions(+), 112 deletions(-) diff --git a/lib/server-info-controller.js b/lib/server-info-controller.js index 5913c09e..a871a059 100644 --- a/lib/server-info-controller.js +++ b/lib/server-info-controller.js @@ -5,10 +5,9 @@ var HealthCheck = require('./monitoring/health-check'); var WELCOME_MSG = 'This is the CartoDB Maps API, ' + 'see the documentation at http://docs.cartodb.com/cartodb-platform/maps-api.html'; -function ServerInfoController (versions) { +function ServerInfoController () { this.healthConfig = global.environment.health || {}; this.healthCheck = new HealthCheck(global.environment.disabled_file); - this.versions = versions || {}; } module.exports = ServerInfoController; @@ -16,7 +15,6 @@ module.exports = ServerInfoController; ServerInfoController.prototype.route = function (monitorRouter) { monitorRouter.get('/health', this.health.bind(this)); monitorRouter.get('/', this.welcome.bind(this)); - monitorRouter.get('/version', this.version.bind(this)); }; ServerInfoController.prototype.welcome = function (req, res) { diff --git a/lib/server.js b/lib/server.js index a39b1cb5..d0ac22f5 100644 --- a/lib/server.js +++ b/lib/server.js @@ -21,10 +21,6 @@ module.exports = function createServer (serverOptions) { // Make stats client globally accessible global.statsClient = StatsClient.getInstance(serverOptions.statsd); - serverOptions.grainstore.mapnik_version = mapnikVersion(serverOptions); - - bootstrapFonts(serverOptions); - const app = express(); app.enable('jsonp callback'); @@ -41,63 +37,8 @@ module.exports = function createServer (serverOptions) { apiRouter.route(app, serverOptions.routes.api); - const versions = getAndValidateVersions(serverOptions); - - const serverInfoController = new ServerInfoController(versions); + const serverInfoController = new ServerInfoController(); serverInfoController.route(app); return app; }; - -function bootstrapFonts (opts) { - // Set carto renderer configuration for MMLStore - opts.grainstore.carto_env = opts.grainstore.carto_env || {}; - var cenv = opts.grainstore.carto_env; - cenv.validation_data = cenv.validation_data || {}; - if (!cenv.validation_data.fonts) { - mapnik.register_system_fonts(); - mapnik.register_default_fonts(); - cenv.validation_data.fonts = _.keys(mapnik.fontFiles()); - } -} - -function mapnikVersion (opts) { - return opts.grainstore.mapnik_version || mapnik.versions.mapnik; -} - -function getAndValidateVersions (options) { - var warn = console.warn.bind(console); // jshint ignore:line - - var packageDefinition = require('../package.json'); - - var declaredDependencies = packageDefinition.dependencies || {}; - var installedDependenciesVersions = { - camshaft: require('camshaft').version, - grainstore: windshaft.grainstore.version(), - mapnik: windshaft.mapnik.versions.mapnik, - node_mapnik: windshaft.mapnik.version, - 'turbo-carto': require('turbo-carto').version, - windshaft: windshaft.version, - windshaft_cartodb: packageDefinition.version - }; - - if (process.env.NODE_ENV !== 'test') { - var dependenciesToValidate = ['camshaft', 'turbo-carto', 'windshaft']; - dependenciesToValidate.forEach(function (depName) { - var declaredDependencyVersion = declaredDependencies[depName]; - var installedDependencyVersion = installedDependenciesVersions[depName]; - if (!semver.satisfies(installedDependencyVersion, declaredDependencyVersion)) { - warn(`Dependency="${depName}" installed version="${installedDependencyVersion}" does ` + - `not match declared version="${declaredDependencyVersion}". Check your installation.`); - } - }); - - // Be nice and warn if configured mapnik version is != installed mapnik version - if (windshaft.mapnik.versions.mapnik !== options.grainstore.mapnik_version) { - warn('WARNING: detected mapnik version (' + windshaft.mapnik.versions.mapnik + ')' + - ' != configured mapnik version (' + options.grainstore.mapnik_version + ')'); - } - } - - return installedDependenciesVersions; -} diff --git a/test/acceptance/cache/cache-headers-test.js b/test/acceptance/cache/cache-headers-test.js index c77a3b50..d96bada7 100644 --- a/test/acceptance/cache/cache-headers-test.js +++ b/test/acceptance/cache/cache-headers-test.js @@ -302,15 +302,6 @@ describe('get requests with cache headers', function () { ); }); - it('/version', function (done) { - assert.response( - server, - getRequest('/version'), - statusOkResponse, - noCacheHeaders(done) - ); - }); - it('/health', function (done) { assert.response( server, diff --git a/test/acceptance/ported/server-test.js b/test/acceptance/ported/server-test.js index 31c25101..be0a0944 100644 --- a/test/acceptance/ported/server-test.js +++ b/test/acceptance/ported/server-test.js @@ -35,29 +35,6 @@ describe('server', function () { }, function () { done(); }); }); - /// ///////////////////////////////////////////////////////////////// - // - // GET VERSION - // - /// ///////////////////////////////////////////////////////////////// - - it('get /version returns versions', function (done) { - assert.response(server, { - url: '/version', - method: 'GET' - }, { - status: 200 - }, function (res) { - var parsed = JSON.parse(res.body); - assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'windshaft'), "No 'windshaft' version in " + parsed); - assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'grainstore'), "No 'grainstore' version in " + parsed); - assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'node_mapnik'), "No 'node_mapnik' version in " + parsed); - assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'mapnik'), "No 'mapnik' version in " + parsed); - // TODO: check actual versions ? - done(); - }); - }); - /// ///////////////////////////////////////////////////////////////// // // GET GRID diff --git a/test/acceptance/server-test.js b/test/acceptance/server-test.js index aa010b56..7fb16e4d 100644 --- a/test/acceptance/server-test.js +++ b/test/acceptance/server-test.js @@ -39,23 +39,6 @@ describe('server', function () { } ); }); - - it('get call to server returns 200', function (done) { - assert.response(server, { - url: '/version', - method: 'GET' - }, { - status: 200 - }, function (res) { - var parsed = JSON.parse(res.body); - assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'windshaft_cartodb'), "No 'windshaft_cartodb' version in " + parsed); - assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'windshaft'), "No 'windshaft' version in " + parsed); - assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'grainstore'), "No 'grainstore' version in " + parsed); - assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'node_mapnik'), "No 'node_mapnik' version in " + parsed); - assert.ok(Object.prototype.hasOwnProperty.call(parsed, 'mapnik'), "No 'mapnik' version in " + parsed); - done(); - }); - }); }); describe('server old_api', function () {