log query and job endpoints

This commit is contained in:
Simon Martín 2019-02-27 09:02:31 +01:00
parent 2c1ce33e34
commit 2066115002
2 changed files with 12 additions and 0 deletions

View File

@ -11,6 +11,7 @@ const errorMiddleware = require('../middlewares/error');
const rateLimitsMiddleware = require('../middlewares/rate-limit');
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimitsMiddleware;
const handleQueryMiddleware = require('../middlewares/handle-query');
const logMiddleware = require('../middlewares/log');
function JobController(metadataBackend, userDatabaseService, jobService, statsdClient, userLimitsService) {
this.metadataBackend = metadataBackend;
@ -44,6 +45,7 @@ JobController.prototype.route = function (app) {
bodyParserMiddleware(),
checkBodyPayloadSize(),
handleQueryMiddleware(true),
logMiddleware(),
jobMiddlewares('create', createJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_CREATE)
);
app.get(

View File

@ -21,6 +21,7 @@ const { initializeProfilerMiddleware } = require('../middlewares/profiler');
const rateLimitsMiddleware = require('../middlewares/rate-limit');
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimitsMiddleware;
const handleQueryMiddleware = require('../middlewares/handle-query');
const logMiddleware = require('../middlewares/log');
var ONE_YEAR_IN_SECONDS = 31536000; // 1 year time to live by default
@ -46,6 +47,7 @@ QueryController.prototype.route = function (app) {
connectionParamsMiddleware(this.userDatabaseService),
timeoutLimitsMiddleware(this.metadataBackend),
handleQueryMiddleware(),
logMiddleware(),
this.handleQuery.bind(this),
errorMiddleware()
];
@ -241,6 +243,14 @@ QueryController.prototype.handleQuery = function (req, res, next) {
if (dbopts.host) {
res.header('X-Served-By-DB-Host', dbopts.host);
}
const logObj = {
request: {
sql: res.locals.sql
}
}
res.set('X-SQLAPI-Log', JSON.stringify(logObj));
formatter.sendResponse(opts, this);
},
function errorHandle(err){