From 9329249bc997e09392f1685635cd132fe4d63805 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Thu, 14 May 2015 16:14:24 +0100 Subject: [PATCH] Revert "reduce memory capture in http logger" This reverts commit fc2e043b20204e04f240814d4efc05762db7df96. Had to revert this because req.route.path is not set until a matching route has been hit, so it was always null inside res.end meaning statsd data was never sent over. This commit did not actually stop the memory leak so reverting it has not short term repocusion --- libraries/metrics/http.coffee | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/libraries/metrics/http.coffee b/libraries/metrics/http.coffee index fa8fcdaa62..c175f26a14 100644 --- a/libraries/metrics/http.coffee +++ b/libraries/metrics/http.coffee @@ -4,35 +4,23 @@ module.exports.monitor = (logger) -> return (req, res, next) -> Metrics = require("./metrics") startTime = new Date() - - # only capture the properties of 'req' that we need, to avoid - # leaking the whole req object for responses that never call - # res.end() - url = req.originalUrl || req.url - method = req.method - referrer = req.headers['referer'] || req.headers['referrer'] - remoteAddr = req.ip || req.socket?.socket?.remoteAddress || req.socket?.remoteAddress - userAgent = req.headers["user-agent"] - contentLength = req.headers["content-length"] - path = req.route?.path - end = res.end res.end = () -> end.apply(this, arguments) responseTime = new Date() - startTime - if path? - routePath = path.toString().replace(/\//g, '_').replace(/\:/g, '').slice(1) - key = "http-requests.#{routePath}.#{method}.#{res.statusCode}" + if req.route?.path? + routePath = req.route.path.toString().replace(/\//g, '_').replace(/\:/g, '').slice(1) + key = "http-requests.#{routePath}.#{req.method}.#{res.statusCode}" Metrics.timing(key, responseTime) logger.log req: - url: url - method: method - referrer: referrer - "remote-addr": remoteAddr - "user-agent": userAgent - "content-length": contentLength + url: req.originalUrl || req.url + method: req.method + referrer: req.headers['referer'] || req.headers['referrer'] + "remote-addr": req.ip || req.socket?.socket?.remoteAddress || req.socket?.remoteAddress + "user-agent": req.headers["user-agent"] + "content-length": req.headers["content-length"] res: "content-length": res._headers?["content-length"] statusCode: res.statusCode