From 0a1f7c6ba5a98ed3fb3485c6a18120d61d07cacd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Tue, 14 Aug 2018 15:14:22 +0200 Subject: [PATCH 1/2] copyto adding gzip to log --- app/controllers/copy_controller.js | 6 +++++- app/services/stream_copy_metrics.js | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/copy_controller.js b/app/controllers/copy_controller.js index f13c3647..da188c50 100644 --- a/app/controllers/copy_controller.js +++ b/app/controllers/copy_controller.js @@ -64,8 +64,12 @@ function handleCopyTo (logger) { const { userDbParams, user } = res.locals; const filename = req.query.filename || 'carto-sql-copyto.dmp'; + // it is not sure, nginx may choose not to compress the body + // but most of the time yes and we want to have it in the metrics + const isGzip = req.get('accept-encoding') && req.get('accept-encoding').includes('gzip'); + const streamCopy = new StreamCopy(sql, userDbParams); - const metrics = new StreamCopyMetrics(logger, 'copyto', sql, user); + const metrics = new StreamCopyMetrics(logger, 'copyto', sql, user, isGzip); res.header("Content-Disposition", `attachment; filename=${encodeURIComponent(filename)}`); res.header("Content-Type", "application/octet-stream"); diff --git a/app/services/stream_copy_metrics.js b/app/services/stream_copy_metrics.js index 77f7ac06..46c9eb33 100644 --- a/app/services/stream_copy_metrics.js +++ b/app/services/stream_copy_metrics.js @@ -1,7 +1,7 @@ const { getFormatFromCopyQuery } = require('../utils/query_info'); module.exports = class StreamCopyMetrics { - constructor(logger, type, sql, user, isGzip = null) { + constructor(logger, type, sql, user, isGzip = false) { this.logger = logger; this.type = type; From 93659862727b3c50d677ff6b325c942dc6ff046e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Tue, 14 Aug 2018 15:30:51 +0200 Subject: [PATCH 2/2] better message --- app/controllers/copy_controller.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/copy_controller.js b/app/controllers/copy_controller.js index da188c50..b691b4bd 100644 --- a/app/controllers/copy_controller.js +++ b/app/controllers/copy_controller.js @@ -65,7 +65,8 @@ function handleCopyTo (logger) { const filename = req.query.filename || 'carto-sql-copyto.dmp'; // it is not sure, nginx may choose not to compress the body - // but most of the time yes and we want to have it in the metrics + // but we want to know it and save it in the metrics + // https://github.com/CartoDB/CartoDB-SQL-API/issues/515 const isGzip = req.get('accept-encoding') && req.get('accept-encoding').includes('gzip'); const streamCopy = new StreamCopy(sql, userDbParams);