copyfrom metrics to kibana
This commit is contained in:
parent
8dd1d5babf
commit
5ba7dca79c
@ -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);
|
||||
};
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user