add to log anonymous maps instantiations that use overviews tables

Added to tiler profiler object:

overviewsAddedToMapconfig: true
mapType: 'anonymous'
This commit is contained in:
Eneko Lakasta 2018-09-04 15:13:17 +02:00
parent 95d179835c
commit 7df0fb456b
4 changed files with 32 additions and 12 deletions

View File

@ -152,8 +152,10 @@ function prepareAdapterMapConfig (mapConfigAdapter) {
}
};
mapConfigAdapter.getMapConfig(user, requestMapConfig, params, context, (err, requestMapConfig) => {
mapConfigAdapter.getMapConfig(user, requestMapConfig, params, context, (err, requestMapConfig, stats = { overviewsUsed : false}) => {
req.profiler.done('anonymous.getMapConfig');
req.profiler.add(stats);
if (err) {
return next(err);
}

View File

@ -11,16 +11,21 @@ MapConfigAdapter.prototype.getMapConfig = function(user, requestMapConfig, param
var i = 0;
var tasksLeft = this.adapters.length;
function next(err, _requestMapConfig) {
let mapConfigStats = {};
function next(err, _requestMapConfig, adapterStats = {}) {
if (err) {
return callback(err);
}
mapConfigStats = Object.assign(mapConfigStats, adapterStats);
if (tasksLeft-- === 0) {
return callback(null, _requestMapConfig);
return callback(null, _requestMapConfig, mapConfigStats);
}
var nextAdapter = self.adapters[i++];
nextAdapter.getMapConfig(user, _requestMapConfig, params, context, next);
}
next(null, requestMapConfig);
next(null, requestMapConfig, mapConfigStats);
};

View File

@ -20,50 +20,62 @@ MapConfigOverviewsAdapter.prototype.getMapConfig = function (user, requestMapCon
layers.forEach(layer => augmentLayersQueue.defer(this._augmentLayer.bind(this), user, layer, analysesResults));
augmentLayersQueue.awaitAll(function layersAugmentQueueFinish (err, layers) {
augmentLayersQueue.awaitAll(function layersAugmentQueueFinish (err, results) {
if (err) {
return callback(err);
}
const layers = results.map(result => result.layer);
const overviewsAddedToMapconfig = results
.map(result => result.overviewsAddedToMapconfig)
.reduce((overviewsInMapconfig,overviewsInLayer)=>overviewsInMapconfig||overviewsInLayer,
false);
if (!layers || layers.length === 0) {
return callback(new Error('Missing layers array from layergroup config'));
}
requestMapConfig.layers = layers;
return callback(null, requestMapConfig);
const stats = { overviewsAddedToMapconfig,
mapType: 'anonymous' };
return callback(null, requestMapConfig, stats);
});
};
MapConfigOverviewsAdapter.prototype._augmentLayer = function (user, layer, analysesResults, callback) {
let overviewsAddedToMapconfig = false;
if (layer.type !== 'mapnik' && layer.type !== 'cartodb') {
return callback(null, layer);
return callback(null, { layer, overviewsAddedToMapconfig });
}
this.overviewsMetadataBackend.getOverviewsMetadata(user, layer.options.sql, (err, metadata) => {
if (err) {
return callback(err, layer);
return callback(err, { layer, overviewsAddedToMapconfig });
}
if (_.isEmpty(metadata)) {
return callback(null, layer);
return callback(null, { layer, overviewsAddedToMapconfig });
}
var filters = getFilters(analysesResults, layer);
overviewsAddedToMapconfig = true;
if (!filters) {
layer.options = Object.assign({}, layer.options, getQueryRewriteData(layer, analysesResults, {
overviews: metadata
}));
return callback(null, layer);
return callback(null, { layer, overviewsAddedToMapconfig });
}
var unfilteredQuery = getUnfilteredQuery(analysesResults, layer);
this.filterStatsBackend.getFilterStats(user, unfilteredQuery, filters, function (err, stats) {
if (err) {
return callback(null, layer);
return callback(null, { layer, overviewsAddedToMapconfig });
}
layer.options = Object.assign({}, layer.options, getQueryRewriteData(layer, analysesResults, {
@ -71,7 +83,7 @@ MapConfigOverviewsAdapter.prototype._augmentLayer = function (user, layer, analy
filter_stats: stats
}));
return callback(null, layer);
return callback(null, { layer, overviewsAddedToMapconfig });
});
});
};

View File

@ -72,6 +72,7 @@ describe('overviews metadata', function() {
data: JSON.stringify(layergroup)
}, {}, function(res) {
assert.equal(res.statusCode, 200, res.body);
assert.ok(JSON.parse(res.headers['x-tiler-profiler']).overviewsAddedToMapconfig);
var parsedBody = JSON.parse(res.body);
assert.equal(res.headers['x-layergroup-id'], parsedBody.layergroupid);
expected_token = parsedBody.layergroupid;