Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEMP] Parsoid: Log all VE requests #1192

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 56 additions & 3 deletions sys/parsoid.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const mwUtil = require('../lib/mwUtil');

const spec = HyperSwitch.utils.loadSpec(`${__dirname}/parsoid.yaml`);

const veRE = /^VisualEditor-MediaWiki/;

// Temporary work-around for Parsoid issue
// https://phabricator.wikimedia.org/T93715
function normalizeHtml(html) {
Expand Down Expand Up @@ -110,8 +112,8 @@ class ParsoidService {
// Set up operations
this.operations = {
// Revision retrieval per format
getHtml: this.getFormat.bind(this, 'html'),
getDataParsoid: this.getFormat.bind(this, 'data-parsoid'),
getHtml: this.getFormatAndLog.bind(this, 'html'),
getDataParsoid: this.getFormatAndLog.bind(this, 'data-parsoid'),
getLintErrors: this.getLintErrors.bind(this),
// Transforms
transformHtmlToHtml: this.makeTransform('html', 'html'),
Expand Down Expand Up @@ -447,6 +449,40 @@ class ParsoidService {
return true;
}

_logVE(hyper, what) {
if (!veRE.test(hyper._rootReq.headers['user-agent']) &&
!veRE.test(hyper._rootReq.headers['api-user-agent'])) {
return;
}
let log;
if (!what) {
log = { msg: 'Empty log entry' };
} else if (what.constructor === Object) {
if (!what.message || !what.msg) {
log = {
msg: 'Response object',
response: Object.assign({}, what)
};
if (log.response.body) {
log.response.body = 'Body truncated';
} else {
log.response.body = 'No body returned';
}
} else {
log = what;
}
} else {
log = what;
}
hyper.logger.log('debug/request/visualeditor', log);
}

getFormatAndLog(format, hyper, req) {
return this.getFormat(format, hyper, req)
.tapCatch((e) => this._logVE(hyper, e))
.tap((res) => this._logVE(hyper, res));
}

getFormat(format, hyper, req) {
const rp = req.params;
const generateContent = (storageRes) => {
Expand Down Expand Up @@ -692,7 +728,7 @@ class ParsoidService {
}

makeTransform(from, to) {
return (hyper, req) => {
const func = (hyper, req) => {
const rp = req.params;
if ((!req.body && req.body !== '') ||
// The html/to/html endpoint is a bit different so the `html`
Expand Down Expand Up @@ -765,6 +801,11 @@ class ParsoidService {
return res;
});
};
return (hyper, req) => {
return func(hyper, req)
.tapCatch((e) => this._logVE(hyper, e))
.tap((res) => this._logVE(hyper, res));
};
}

// Get / check the revision metadata for a request
Expand All @@ -789,6 +830,18 @@ class ParsoidService {
_getOriginalContent(hyper, req, revision, tid) {
const rp = req.params;
return this._getContentWithFallback(hyper, rp.domain, rp.title, revision, tid)
.tapCatch((e) => {
this._logVE(hyper, {
message: 'Could not find original content',
params: {
domain: rp.domain,
title: rp.title,
revision,
tid
},
error: e
});
})
.then((res) => {
res = res.body;
res.revid = revision;
Expand Down