jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/388270 )
Change subject: Bump to [email protected] ...................................................................... Bump to [email protected] * Each compute worker in the new http api architecture needs access to logging and metrics which can't be passed across the process barier. This version of service-runner exposes the configuration for those features so that they can construct their own. * Move the setup from the service entrypoint to ParsoidConfig construction to support that. Change-Id: Icb44e2c144bdd5fc256a79f067ef44682f2e405e --- M lib/config/ParsoidConfig.js M lib/index.js M npm-shrinkwrap.json M package.json 4 files changed, 51 insertions(+), 61 deletions(-) Approvals: Subramanya Sastry: Looks good to me, approved Sbailey: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/lib/config/ParsoidConfig.js b/lib/config/ParsoidConfig.js index 0109ea3..4ff9aa6 100644 --- a/lib/config/ParsoidConfig.js +++ b/lib/config/ParsoidConfig.js @@ -10,6 +10,7 @@ var fs = require('fs'); var path = require('path'); var url = require('url'); +var ServiceRunner = require('service-runner'); var Util = require('../utils/Util.js').Util; var JSUtils = require('../utils/jsutils.js').JSUtils; @@ -105,6 +106,21 @@ }, }); +var prepareLog = function(logData) { + var log = Object.assign({ logType: logData.logType }, logData.locationData); + var flat = logData.flatLogObject(); + Object.keys(flat).forEach(function(k) { + // Be sure we don't have a `type` field here since logstash + // treats that as magical. We created a special `location` + // field above and bunyan will add a `level` field (from the + // contents of our `type` field) when we call the specific + // logger returned by `_getBunyanLogger`. + if (/^(type|location|level)$/.test(k)) { return; } + log[k] = flat[k]; + }); + return log; +}; + /** * @class * @@ -118,6 +134,8 @@ * @param {Object} options Any options we want to set over the defaults. See the class properties for more information. */ function ParsoidConfig(localSettings, options) { + options = options || {}; + this.mwApiMap = new Map(); this.reverseMwApiMap = new Map(); Object.keys(CONFIG_DEFAULTS).forEach(function(k) { @@ -127,8 +145,19 @@ // Don't freak out! // This happily overwrites inherited properties. - if (options) { - Object.assign(this, options); + Object.assign(this, options); + + if (options.parent && (!this.loggerBackend || !this.metrics)) { + var srlogger = ServiceRunner.getLogger(options.parent.logging); + if (!this.loggerBackend) { + this.loggerBackend = function(logData, cb) { + srlogger.log(logData.logType, prepareLog(logData)); + cb(); + }; + } + if (!this.metrics) { + this.metrics = ServiceRunner.getMetrics(options.parent.metrics, srlogger); + } } if (!localSettings && options.localsettings) { diff --git a/lib/index.js b/lib/index.js index d18fa6f..9170bae 100644 --- a/lib/index.js +++ b/lib/index.js @@ -8,21 +8,6 @@ var ParsoidConfig = require('./config/ParsoidConfig.js').ParsoidConfig; var ParsoidService = require('./api/ParsoidService.js'); -var prepareLog = function(logData) { - var log = Object.assign({ logType: logData.logType }, logData.locationData); - var flat = logData.flatLogObject(); - Object.keys(flat).forEach(function(k) { - // Be sure we don't have a `type` field here since logstash - // treats that as magical. We created a special `location` - // field above and bunyan will add a `level` field (from the - // contents of our `type` field) when we call the specific - // logger returned by `_getBunyanLogger`. - if (/^(type|location|level)$/.test(k)) { return; } - log[k] = flat[k]; - }); - return log; -}; - /** * Main entry point for Parsoid's JavaScript API. * @@ -46,18 +31,19 @@ /** * Start an API service worker as part of a service-runner service. + * * @param {Object} options * @return {Promise} a Promise for an `http.Server`. */ Parsoid.apiServiceWorker = function apiServiceWorker(options) { - // By default, set the loggerBackend and metrics to service-runner's. var parsoidOptions = Object.assign({ - loggerBackend: function(logData, cb) { - options.logger.log(logData.logType, prepareLog(logData)); - cb(); + // Pull these out since the name "metrics" conflicts between + // configuration and the instantiated object. + parent: { + logging: options.config.logging, + metrics: options.config.metrics, }, - metrics: options.metrics, - }, options.config); // but it can be overriden here. + }, options.config, { logging: undefined, metrics: undefined }); // For backwards compatibility, and to continue to support non-static // configs for the time being. if (parsoidOptions.localsettings) { diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 0d2a3fc..5eec9f2 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -187,11 +187,6 @@ "from": "readable-stream@^2.0.5", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz" }, - "safe-buffer": { - "version": "5.1.1", - "from": "safe-buffer@~5.1.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz" - }, "string_decoder": { "version": "1.0.3", "from": "string_decoder@~1.0.3", @@ -200,9 +195,9 @@ } }, "bluebird": { - "version": "3.5.0", - "from": "bluebird@>=3.4.7 <4.0.0", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.0.tgz" + "version": "3.5.1", + "from": "bluebird@>=3.5.0 <4.0.0", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz" }, "body-parser": { "version": "1.18.2", @@ -1266,9 +1261,9 @@ "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.5.0.tgz" }, "hot-shots": { - "version": "4.7.0", + "version": "4.8.0", "from": "hot-shots@>=4.4.0 <5.0.0", - "resolved": "https://registry.npmjs.org/hot-shots/-/hot-shots-4.7.0.tgz" + "resolved": "https://registry.npmjs.org/hot-shots/-/hot-shots-4.8.0.tgz" }, "htmlparser2": { "version": "3.8.3", @@ -1500,7 +1495,7 @@ }, "js-yaml": { "version": "3.8.3", - "from": "js-yaml@>=3.8.1 <4.0.0", + "from": "[email protected]", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.8.3.tgz" }, "jshint": { @@ -1580,11 +1575,6 @@ "from": "readable-stream@^2.0.4", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz" }, - "safe-buffer": { - "version": "5.1.1", - "from": "safe-buffer@>=5.1.1 <5.2.0", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz" - }, "string_decoder": { "version": "1.0.3", "from": "string_decoder@>=1.0.3 <1.1.0", @@ -1611,11 +1601,6 @@ "version": "2.3.3", "from": "readable-stream@^2.0.5", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz" - }, - "safe-buffer": { - "version": "5.1.1", - "from": "safe-buffer@~5.1.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz" }, "string_decoder": { "version": "1.0.3", @@ -1655,11 +1640,6 @@ "version": "2.3.3", "from": "readable-stream@>=2.0.5 <3.0.0", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz" - }, - "safe-buffer": { - "version": "5.1.1", - "from": "safe-buffer@~5.1.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz" }, "string_decoder": { "version": "1.0.3", @@ -1820,9 +1800,9 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.2.tgz" }, "msgpack5": { - "version": "3.5.1", + "version": "3.6.0", "from": "msgpack5@>=3.3.0 <4.0.0", - "resolved": "https://registry.npmjs.org/msgpack5/-/msgpack5-3.5.1.tgz", + "resolved": "https://registry.npmjs.org/msgpack5/-/msgpack5-3.6.0.tgz", "dependencies": { "isarray": { "version": "1.0.0", @@ -1833,11 +1813,6 @@ "version": "2.3.3", "from": "readable-stream@^2.3.3", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz" - }, - "safe-buffer": { - "version": "5.1.1", - "from": "safe-buffer@^5.1.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz" }, "string_decoder": { "version": "1.0.3", @@ -2528,9 +2503,9 @@ "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.12.6.tgz" }, "service-runner": { - "version": "2.3.0", - "from": "[email protected]", - "resolved": "https://registry.npmjs.org/service-runner/-/service-runner-2.3.0.tgz" + "version": "2.4.0", + "from": "[email protected]", + "resolved": "https://registry.npmjs.org/service-runner/-/service-runner-2.4.0.tgz" }, "set-blocking": { "version": "2.0.0", diff --git a/package.json b/package.json index 95f9bcd..638e62a 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "express": "^4.15.5", "express-handlebars": "^3.0.0", "finalhandler": "^1.0.6", - "js-yaml": "^3.8.1", + "js-yaml": "^3.8.3", "mediawiki-title": "^0.6.4", "negotiator": "git+https://github.com/arlolra/negotiator#full-parse-access", "pegjs": "git+https://github.com/tstarling/pegjs#fork", @@ -25,7 +25,7 @@ "request": "^2.83.0", "semver": "^5.3.0", "serve-favicon": "^2.4.5", - "service-runner": "^2.3.0", + "service-runner": "^2.4.0", "simplediff": "^0.1.1", "uuid": "^3.1.0", "yargs": "^7.1.0" -- To view, visit https://gerrit.wikimedia.org/r/388270 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Icb44e2c144bdd5fc256a79f067ef44682f2e405e Gerrit-PatchSet: 8 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: Arlolra <[email protected]> Gerrit-Reviewer: Arlolra <[email protected]> Gerrit-Reviewer: C. Scott Ananian <[email protected]> Gerrit-Reviewer: Sbailey <[email protected]> Gerrit-Reviewer: Subramanya Sastry <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
