Don't create a new metric for each request, use the same label to send to statsd

This commit is contained in:
Daniel García Aubert 2020-06-10 17:21:35 +02:00
parent 18525a60cd
commit e49ecda321

View File

@ -2,13 +2,13 @@
const Profiler = require('../../stats/profiler-proxy');
const debug = require('debug')('windshaft:cartodb:stats');
const { name: prefix } = require('../../../package.json');
module.exports = function profiler (options) {
const { enabled = true, statsClient } = options;
return function profilerMiddleware (req, res, next) {
const { logger } = res.locals;
const { id } = logger.bindings();
// TODO: stop using profiler and log stats instead of adding them to the profiler
req.profiler = new Profiler({
@ -16,7 +16,7 @@ module.exports = function profiler (options) {
profile: enabled
});
req.profiler.start(id);
req.profiler.start(prefix);
res.on('finish', () => {
req.profiler.done('response');