Send template_hash as part of the metrics event

remotes/origin/node-12
Daniel García Aubert 4 years ago
parent c91d78fe51
commit dbc5d65d90

@ -6,8 +6,9 @@ module.exports = function setLayergroupIdHeader (templateMaps, useTemplateHash)
const layergroup = res.body;
if (useTemplateHash) {
var templateHash = templateMaps.fingerPrint(template).substring(0, 8);
const templateHash = templateMaps.fingerPrint(template).substring(0, 8);
layergroup.layergroupid = `${user}@${templateHash}@${layergroup.layergroupid}`;
res.locals.templateHash = templateHash;
}
res.set('X-Layergroup-Id', layergroup.layergroupid);

@ -13,6 +13,10 @@ module.exports = function layergroupToken () {
res.locals.token = layergroupToken.token;
res.locals.cache_buster = layergroupToken.cacheBuster;
if (layergroupToken.templateHash) {
res.locals.templateHash = layergroupToken.templateHash;
}
if (layergroupToken.signer) {
res.locals.signer = layergroupToken.signer;

@ -49,6 +49,7 @@ function getEventData (req, res, tags) {
user_agent: req.get('User-Agent'),
map_id: getLayergroupid({ res }),
cache_buster: getCacheBuster({ res }),
template_hash: getTemplateHash({ res }),
response_code: res.statusCode.toString(),
response_time: getResponseTime(res),
source_domain: req.hostname,
@ -93,6 +94,10 @@ function getCacheBuster ({ res }) {
}
}
function getTemplateHash ({ res }) {
return res.locals.templateHash;
}
// FIXME: 'X-Tiler-Profiler' might not be accurate enough
function getResponseTime (res) {
const profiler = res.get('X-Tiler-Profiler');

@ -316,7 +316,7 @@ describe('metrics middleware', function () {
assert.strictEqual(typeof body.layergroupid, 'string');
const { token, cacheBuster } = LayergroupToken.parse(body.layergroupid);
const { token, cacheBuster, templateHash } = LayergroupToken.parse(body.layergroupid);
assert.ok(this.pubSubMetricsBackendSendMethodCalled);
assert.strictEqual(this.pubSubMetricsBackendSendMethodCalledWith.event, expectedEvent);
@ -327,6 +327,7 @@ describe('metrics middleware', function () {
assert.strictEqual(this.pubSubMetricsBackendSendMethodCalledWith.attributes.map_type, expectedMapType);
assert.strictEqual(this.pubSubMetricsBackendSendMethodCalledWith.attributes.map_id, token);
assert.strictEqual(this.pubSubMetricsBackendSendMethodCalledWith.attributes.cache_buster, cacheBuster);
assert.strictEqual(this.pubSubMetricsBackendSendMethodCalledWith.attributes.template_hash, templateHash);
return done();
});
@ -387,6 +388,8 @@ describe('metrics middleware', function () {
assert.strictEqual(this.pubSubMetricsBackendSendMethodCalledWith.attributes.map_type, expectedMapType);
assert.strictEqual(typeof this.pubSubMetricsBackendSendMethodCalledWith.attributes.map_id, 'string');
assert.strictEqual(typeof this.pubSubMetricsBackendSendMethodCalledWith.attributes.cache_buster, 'string');
// TODO: uncomment this
// assert.strictEqual(typeof this.pubSubMetricsBackendSendMethodCalledWith.attributes.template_hash, 'string');
return done();
});
@ -419,6 +422,7 @@ describe('metrics middleware', function () {
assert.strictEqual(this.pubSubMetricsBackendSendMethodCalledWith.attributes.response_code, expectedResponseCode);
assert.strictEqual(typeof this.pubSubMetricsBackendSendMethodCalledWith.attributes.map_id, 'string');
assert.strictEqual(typeof this.pubSubMetricsBackendSendMethodCalledWith.attributes.cache_buster, 'string');
assert.strictEqual(typeof this.pubSubMetricsBackendSendMethodCalledWith.attributes.template_hash, 'string');
return done();
});
@ -455,6 +459,8 @@ describe('metrics middleware', function () {
assert.strictEqual(this.pubSubMetricsBackendSendMethodCalledWith.attributes.map_type, expectedMapType);
assert.strictEqual(typeof this.pubSubMetricsBackendSendMethodCalledWith.attributes.map_id, 'string');
assert.strictEqual(typeof this.pubSubMetricsBackendSendMethodCalledWith.attributes.cache_buster, 'string');
// TODO: uncomment this
// assert.strictEqual(typeof this.pubSubMetricsBackendSendMethodCalledWith.attributes.template_hash, 'string');
return done();
});
@ -500,6 +506,8 @@ describe('metrics middleware', function () {
assert.strictEqual(this.pubSubMetricsBackendSendMethodCalledWith.attributes.map_type, expectedMapType);
assert.strictEqual(typeof this.pubSubMetricsBackendSendMethodCalledWith.attributes.map_id, 'string');
assert.strictEqual(typeof this.pubSubMetricsBackendSendMethodCalledWith.attributes.cache_buster, 'string');
// TODO: uncomment this
// assert.strictEqual(typeof this.pubSubMetricsBackendSendMethodCalledWith.attributes.template_hash, 'string');
return done();
});

Loading…
Cancel
Save