From 5ba7dca79c36f6e99bbeedc553cd0f0ab24f7f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Wed, 23 May 2018 10:30:37 +0200 Subject: [PATCH] copyfrom metrics to kibana --- app/controllers/copy_controller.js | 23 +++++++++++++---------- test/acceptance/copy-endpoints.js | 22 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/app/controllers/copy_controller.js b/app/controllers/copy_controller.js index ce3296b0..22ff2c39 100644 --- a/app/controllers/copy_controller.js +++ b/app/controllers/copy_controller.js @@ -36,7 +36,7 @@ CopyController.prototype.route = function (app) { timeoutLimitsMiddleware(this.metadataBackend), validateCopyQuery(), handleCopyFrom(), - responseCopyFrom(this.statsClient), + responseCopyFrom(), errorMiddleware() ]; }; @@ -150,21 +150,24 @@ function handleCopyFrom () { }; } -function responseCopyFrom (statsClient) { +function responseCopyFrom () { return function responseCopyFromMiddleware (req, res, next) { if (!res.body || !res.body.total_rows) { return next(new Error("No rows copied")); } - const metrics = { - size: res.locals.copyFromSize, //bytes - format: getFormatFromCopyQuery(req.query.q), - time: res.body.time, //seconds - total_rows: res.body.total_rows, - gzip: req.get('content-encoding') === 'gzip' - }; + if (req.profiler) { + const metrics = { + size: res.locals.copyFromSize, //bytes + format: getFormatFromCopyQuery(req.query.q), + time: res.body.time, //seconds + total_rows: res.body.total_rows, + gzip: req.get('content-encoding') === 'gzip' + }; - statsClient.set('copyFrom', JSON.stringify(metrics)); + req.profiler.add({ copyFrom: metrics }); + res.header('X-SQLAPI-Profiler', req.profiler.toJSONString()); + } res.send(res.body); }; diff --git a/test/acceptance/copy-endpoints.js b/test/acceptance/copy-endpoints.js index eceab8c1..3108e867 100644 --- a/test/acceptance/copy-endpoints.js +++ b/test/acceptance/copy-endpoints.js @@ -32,6 +32,16 @@ describe('copy-endpoints', function() { assert.equal(!!response.time, true); assert.strictEqual(response.total_rows, 6); + assert.ok(res.headers['x-sqlapi-profiler']); + const headers = JSON.parse(res.headers['x-sqlapi-profiler']); + assert.ok(headers.copyFrom); + const metrics = headers.copyFrom; + assert.equal(metrics.size, 57); + assert.equal(metrics.format, 'CSV'); + assert.equal(metrics.time, response.time); + assert.equal(metrics.total_rows, response.total_rows); + assert.equal(metrics.gzip, false); + done(); }); }); @@ -150,7 +160,17 @@ describe('copy-endpoints', function() { const response = JSON.parse(res.body); assert.equal(!!response.time, true); assert.strictEqual(response.total_rows, 6); - + + assert.ok(res.headers['x-sqlapi-profiler']); + const headers = JSON.parse(res.headers['x-sqlapi-profiler']); + assert.ok(headers.copyFrom); + const metrics = headers.copyFrom; + assert.equal(metrics.size, 57); + assert.equal(metrics.format, 'CSV'); + assert.equal(metrics.time, response.time); + assert.equal(metrics.total_rows, response.total_rows); + assert.equal(metrics.gzip, true); + done(); }); });