From c8a042abdd3836cec966a128ee96d07907dee0cc Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 19 Feb 2014 18:10:33 +0100 Subject: [PATCH] Expand "addCacheChannel" stats --- NEWS.md | 1 + lib/cartodb/cartodb_windshaft.js | 1 - lib/cartodb/server_options.js | 11 ++++++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 71c4daf0..03971323 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ Enhancements: * Allow using ":host" as part of statsd.prefix (#153) + * Expand "addCacheChannel" stats Bug fixes: diff --git a/lib/cartodb/cartodb_windshaft.js b/lib/cartodb/cartodb_windshaft.js index 8f76ab71..b3209458 100644 --- a/lib/cartodb/cartodb_windshaft.js +++ b/lib/cartodb/cartodb_windshaft.js @@ -82,7 +82,6 @@ var CartodbWindshaft = function(serverOptions) { serverOptions.addCacheChannel(that, req, this); }, function sendResponse(err, added) { - if (added && req.profiler) req.profiler.done('addCacheChannel'); ws_sendResponse.apply(that, thatArgs); } ); diff --git a/lib/cartodb/server_options.js b/lib/cartodb/server_options.js index 15f17e87..359fd6f5 100644 --- a/lib/cartodb/server_options.js +++ b/lib/cartodb/server_options.js @@ -199,10 +199,8 @@ module.exports = function(){ me.generateCacheChannel = function(app, req, callback){ - // use key to call sql api with sql request if present, else - // just return dbname and table name base key + // Build channelCache key var dbName = req.params.dbname; - var cacheKey = [ dbName ]; if ( req.params.token ) cacheKey.push(req.params.token); else if ( req.params.sql ) cacheKey.push( me.generateMD5(req.params.sql) ); @@ -236,6 +234,7 @@ module.exports = function(){ mapStore.load(req.params.token, this); }, function getSQL(err, mapConfig) { + if (req.profiler) req.profiler.done('mapStore_load'); if ( err ) throw err; var sql = []; _.each(mapConfig.obj().layers, function(lyr) { @@ -276,6 +275,9 @@ module.exports = function(){ }, function buildCacheChannel(err, tableNames) { if ( err ) throw err; + if (req.profiler && ! req.params.table ) { + req.profiler.done('affectedTables'); + } var dbName = req.params.dbname; var cacheChannel = me.buildCacheChannel(dbName,tableNames); @@ -304,6 +306,7 @@ module.exports = function(){ me.addCacheChannel = function(app, req, cb) { // skip non-GET requests, or requests for which there's no response if ( req.method != 'GET' || ! req.res ) { cb(null, null); return; } + if (req.profiler) req.profiler.start('addCacheChannel'); var res = req.res; var cache_policy = req.query.cache_policy; if ( req.params.token ) cache_policy = 'persist'; @@ -326,6 +329,8 @@ module.exports = function(){ res.header('Last-Modified', lastUpdated.toUTCString()); me.generateCacheChannel(app, req, function(err, channel){ + if (req.profiler) req.profiler.done('generateCacheChannel'); + if (req.profiler) req.profiler.end(); if ( ! err ) { res.header('X-Cache-Channel', channel); cb(null, channel);