jenkins-bot has submitted this change and it was merged. Change subject: Add a new config option for an API proxy endpoint ......................................................................
Add a new config option for an API proxy endpoint Create a new configuration directive, to be passed through as the "proxy" option to the requests module on calls that hit the API endpoints. This can be used to provide either a forward proxy (e.g. for some weird isolated environment scenario) or, in Wikimedia's case, to provide the service IP for the API application servers, as to be able to connect directly to them, rather than going through the multiple caching layers in front of them. Hence, remove the "?random=<pid>" hacks that have been introduced with Ie9554f8ea7f19b3271857bdc10e7ea6fa808dec to help with internal load-balancing between caching layers, as they shouldn't be needed anymore. While at it, rename requests' "url" option to "uri", as this is the documented and preferred way; the code internally maps "url" to "uri", as it's a common mistake, but we shouldn't make it. Bug: 51273 Change-Id: I76c7a133d05f432d692fb82df196c4a1051e2e43 --- M js/api/localsettings.js.example M js/lib/mediawiki.ApiRequest.js 2 files changed, 24 insertions(+), 19 deletions(-) Approvals: Subramanya Sastry: Looks good to me, approved jenkins-bot: Verified diff --git a/js/api/localsettings.js.example b/js/api/localsettings.js.example index c9bf938..2e0567f 100644 --- a/js/api/localsettings.js.example +++ b/js/api/localsettings.js.example @@ -10,6 +10,9 @@ // The URL here is supposed to be your MediaWiki API endpoint parsoidConfig.setInterwiki( 'localhost', 'http://localhost/w/api.php' ); + // a proxy to connect to the API endpoints + // parsoidConfig.apiProxyURI = 'http://proxy.example.org:8080/'; + // Enable debug mode (prints extra debugging messages) // parsoidConfig.debug = true; diff --git a/js/lib/mediawiki.ApiRequest.js b/js/lib/mediawiki.ApiRequest.js index 665356f..c49da4f 100644 --- a/js/lib/mediawiki.ApiRequest.js +++ b/js/lib/mediawiki.ApiRequest.js @@ -150,7 +150,7 @@ this._handleBody( null, body ); } else { if (response.statusCode === 412) { - console.warn('Cache MISS:', this.url); + console.warn('Cache MISS:', this.uri); } else { console.warn( 'non-200 response: ' + response.statusCode ); console.log( body ); @@ -231,15 +231,16 @@ apiargs.revids = oldid; delete apiargs.titles; } - var url = env.conf.wiki.apiURI + '?' + + var uri = env.conf.wiki.apiURI + '?' + qs.stringify( apiargs ); //'?format=json&action=query&prop=revisions&rvprop=content&titles=' + title; this.requestOptions = { method: 'GET', followRedirect: true, - url: url, + uri: uri, timeout: 40 * 1000, // 40 seconds + proxy: env.conf.parsoid.apiProxyURI, headers: { 'User-Agent': userAgent, 'Cookie': env.cookie, @@ -360,8 +361,7 @@ title: title, text: text }; - // Randomize the POST url so that we hit different Squids - var url = env.conf.wiki.apiURI + '?random=' + process.pid; + var uri = env.conf.wiki.apiURI; this.requestOptions = { // Use POST since we are passing a bit of source, and GET has a very @@ -370,8 +370,9 @@ method: 'POST', form: apiargs, // The API arguments followRedirect: true, - url: url, + uri: uri, timeout: 16 * 1000, // 16 seconds + proxy: env.conf.parsoid.apiProxyURI, headers: { 'User-Agent': userAgent, 'Cookie': env.cookie, @@ -459,10 +460,7 @@ text: text, disablepp: 'true' }; - // Randomize the POST url so that we hit different Squids - // TODO: cut out squids completely. See - // https://bugzilla.wikimedia.org/show_bug.cgi?id=51273 - var url = env.conf.wiki.apiURI + '?random=' + process.pid; + var uri = env.conf.wiki.apiURI; this.requestOptions = { // Use POST since we are passing a bit of source, and GET has a very @@ -471,8 +469,9 @@ method: 'POST', form: apiargs, // The API arguments followRedirect: true, - url: url, + uri: uri, timeout: 16 * 1000, // 16 seconds + proxy: env.conf.parsoid.apiProxyURI, headers: { 'User-Agent': userAgent, 'Cookie': env.cookie, @@ -544,12 +543,12 @@ var apiargs = { oldid: oldid }; - var url = env.conf.parsoid.parsoidCacheURI + + var uri = env.conf.parsoid.parsoidCacheURI + env.conf.wiki.iwp + '/' + encodeURIComponent(title.replace(/ /g, '_')) + '?' + qs.stringify( apiargs ); - this.url = url; + this.uri = uri; - //console.warn('Cache request:', url); + //console.warn('Cache request:', uri); this.retries = 0; @@ -557,8 +556,9 @@ // Use GET so that our request is cacheable method: 'GET', followRedirect: false, - url: url, + uri: uri, timeout: 60 * 1000, // 60 seconds: less than 100s VE timeout so we still finish + proxy: env.conf.parsoid.apiProxyURI, headers: { 'User-Agent': userAgent, 'Connection': 'close', @@ -641,8 +641,9 @@ this.requestOptions = { method: 'GET', followRedirect: true, - url: apiURI + '?' + qs.stringify( apiargs ), + uri: apiURI + '?' + qs.stringify( apiargs ), timeout: 40 * 1000, + proxy: env.conf.parsoid.apiProxyURI, headers: { 'User-Agent': userAgent, 'Cookie': env.cookie, @@ -695,7 +696,7 @@ var ix, conf = env.conf.wiki, - url = conf.apiURI + '?', + uri = conf.apiURI + '?', filenames = [ filename ], imgnsid = conf.canonicalNamespaces.image, imgns = conf.namespaceNames[imgnsid], @@ -727,13 +728,14 @@ } } - url += qs.stringify( apiArgs ); + uri += qs.stringify( apiArgs ); this.requestOptions = { method: 'GET', followRedirect: true, - url: url, + uri: uri, timeout: 40 * 1000, + proxy: env.conf.parsoid.apiProxyURI, headers: { 'User-Agent': userAgent, 'Cookie': env.cookie, -- To view, visit https://gerrit.wikimedia.org/r/99666 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I76c7a133d05f432d692fb82df196c4a1051e2e43 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/Parsoid Gerrit-Branch: master Gerrit-Owner: Faidon Liambotis <fai...@wikimedia.org> Gerrit-Reviewer: Faidon Liambotis <fai...@wikimedia.org> Gerrit-Reviewer: GWicke <gwi...@wikimedia.org> Gerrit-Reviewer: Subramanya Sastry <ssas...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits