copyFrom metrics to statsd

This commit is contained in:
Simon Martín 2018-05-22 16:02:14 +02:00
parent 30cb88c3f9
commit 6d73d97ae2

View File

@ -36,7 +36,7 @@ CopyController.prototype.route = function (app) {
timeoutLimitsMiddleware(this.metadataBackend),
validateCopyQuery(),
handleCopyFrom(),
responseCopyFrom(),
responseCopyFrom(this.statsClient),
errorMiddleware()
];
};
@ -149,25 +149,22 @@ function handleCopyFrom () {
};
}
function responseCopyFrom () {
function responseCopyFrom (statsClient) {
return function responseCopyFromMiddleware (req, res, next) {
if (!res.body || !res.body.total_rows) {
return next(new Error("No rows copied"));
}
if (req.profiler) {
const copyFromMetrics = {
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'
};
req.profiler.add({ copyFrom: copyFromMetrics });
res.header('X-SQLAPI-Profiler', req.profiler.toJSONString());
}
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));
res.send(res.body);
};
}
@ -184,7 +181,7 @@ function validateCopyQuery () {
if (!sql.toUpperCase().startsWith("COPY ")) {
next(new Error("SQL must start with COPY"));
}
next();
};
}