Add response time to pubsub events (#1155)

This commit is contained in:
Esther Lozano 2020-03-10 11:40:01 +01:00 committed by GitHub
parent 28c4e89ab5
commit 7b8cc0a8b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,6 +41,12 @@ function getEventData (req, res) {
attributes.event_group_id = eventGroupId;
}
const responseTime = getResponseTime(res);
if (responseTime) {
attributes.response_time = responseTime.toString();
}
return { event, attributes };
}
@ -52,4 +58,17 @@ function normalizedField (field) {
return field.toString().trim().substr(0, MAX_LENGTH);
}
function getResponseTime (res) {
const profiler = res.get('X-Tiler-Profiler');
let stats;
try {
stats = JSON.parse(profiler);
} catch (e) {
return undefined;
}
return stats.total;
}
module.exports = pubSubMetrics;