Feed plugins with filterRegistry (#1761)
This commit is contained in:
parent
d1b376e2ca
commit
a12e4016af
|
|
@ -1,7 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const isEmpty = require('lodash.isempty');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
const aggregator = require('./aggregator');
|
||||
const DEFAULT_METRICS_LARGEST_ASSETS = ['image.0.transferSize'];
|
||||
|
||||
|
|
@ -10,14 +9,20 @@ module.exports = {
|
|||
this.make = context.messageMaker('assets').make;
|
||||
this.options = options;
|
||||
this.resultUrls = context.resultUrls;
|
||||
filterRegistry.registerFilterForType(
|
||||
context.filterRegistry.registerFilterForType(
|
||||
DEFAULT_METRICS_LARGEST_ASSETS,
|
||||
'largestassets.summary'
|
||||
);
|
||||
filterRegistry.registerFilterForType([], 'slowestassets.summary');
|
||||
filterRegistry.registerFilterForType([], 'aggregateassets.summary');
|
||||
filterRegistry.registerFilterForType([], 'slowestthirdpartyassets.summary');
|
||||
filterRegistry.registerFilterForType([], 'largestthirdpartyassets.summary');
|
||||
context.filterRegistry.registerFilterForType([], 'slowestassets.summary');
|
||||
context.filterRegistry.registerFilterForType([], 'aggregateassets.summary');
|
||||
context.filterRegistry.registerFilterForType(
|
||||
[],
|
||||
'slowestthirdpartyassets.summary'
|
||||
);
|
||||
context.filterRegistry.registerFilterForType(
|
||||
[],
|
||||
'largestthirdpartyassets.summary'
|
||||
);
|
||||
},
|
||||
processMessage(message, queue) {
|
||||
const make = this.make;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
const browsertime = require('browsertime');
|
||||
const Promise = require('bluebird');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
const aggregator = require('./aggregator');
|
||||
const api = require('webcoach');
|
||||
const forEach = require('lodash.foreach');
|
||||
|
|
@ -95,11 +94,11 @@ module.exports = {
|
|||
this.options.viewPort = undefined;
|
||||
}
|
||||
|
||||
filterRegistry.registerFilterForType(
|
||||
context.filterRegistry.registerFilterForType(
|
||||
DEFAULT_METRICS_PAGE_SUMMARY,
|
||||
'browsertime.pageSummary'
|
||||
);
|
||||
filterRegistry.registerFilterForType(
|
||||
context.filterRegistry.registerFilterForType(
|
||||
DEFAULT_METRICS_SUMMARY,
|
||||
'browsertime.summary'
|
||||
);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
const aggregator = require('./aggregator');
|
||||
const pagexrayAggregator = require('./pagexrayAggregator');
|
||||
const pagexray = require('pagexray');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
|
||||
const DEFAULT_METRICS_SUMMARY = [
|
||||
'score.*',
|
||||
|
|
@ -54,19 +53,19 @@ module.exports = {
|
|||
this.options = options;
|
||||
this.make = context.messageMaker('coach').make;
|
||||
|
||||
filterRegistry.registerFilterForType(
|
||||
context.filterRegistry.registerFilterForType(
|
||||
DEFAULT_METRICS_SUMMARY,
|
||||
'coach.summary'
|
||||
);
|
||||
filterRegistry.registerFilterForType(
|
||||
context.filterRegistry.registerFilterForType(
|
||||
DEFAULT_METRICS_PAGESUMMARY,
|
||||
'coach.pageSummary'
|
||||
);
|
||||
filterRegistry.registerFilterForType(
|
||||
context.filterRegistry.registerFilterForType(
|
||||
DEFAULT_PAGEXRAY_PAGESUMMARY_METRICS,
|
||||
'pagexray.pageSummary'
|
||||
);
|
||||
filterRegistry.registerFilterForType(
|
||||
context.filterRegistry.registerFilterForType(
|
||||
DEFAULT_PAGEXRAY_SUMMARY_METRICS,
|
||||
'pagexray.summary'
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
'use strict';
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
const isEmpty = require('lodash.isempty');
|
||||
const aggregator = require('./aggregator');
|
||||
|
||||
|
|
@ -7,7 +6,7 @@ module.exports = {
|
|||
open(context) {
|
||||
this.make = context.messageMaker('domains').make;
|
||||
// '*.requestCounts, 'domains.summary'
|
||||
filterRegistry.registerFilterForType([], 'domains.summary');
|
||||
context.filterRegistry.registerFilterForType([], 'domains.summary');
|
||||
},
|
||||
processMessage(message, queue) {
|
||||
const make = this.make;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
const aggregator = require('./aggregator');
|
||||
const log = require('intel').getLogger('sitespeedio.plugin.gpsi');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
const analyzer = require('./analyzer');
|
||||
|
||||
const DEFAULT_METRICS_PAGESUMMARY = ['ruleGroups.SPEED.score'];
|
||||
|
|
@ -14,7 +13,7 @@ module.exports = {
|
|||
gpsi: options.gpsi,
|
||||
mobile: options.mobile
|
||||
};
|
||||
filterRegistry.registerFilterForType(
|
||||
context.filterRegistry.registerFilterForType(
|
||||
DEFAULT_METRICS_PAGESUMMARY,
|
||||
'gpsi.pageSummary'
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const isEmpty = require('lodash.isempty');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
const Sender = require('./sender');
|
||||
const merge = require('lodash.merge');
|
||||
const log = require('intel').getLogger('sitespeedio.plugin.graphite');
|
||||
|
|
@ -20,6 +19,7 @@ module.exports = {
|
|||
throwIfMissing(options.graphite, ['host'], 'graphite');
|
||||
const opts = merge({}, defaultConfig, options.graphite);
|
||||
this.options = options;
|
||||
this.filterRegistry = context.filterRegistry;
|
||||
this.sender = new Sender(opts.host, opts.port);
|
||||
this.dataGenerator = new DataGenerator(
|
||||
opts.namespace,
|
||||
|
|
@ -36,6 +36,7 @@ module.exports = {
|
|||
this.resultUrls = context.resultUrls;
|
||||
},
|
||||
processMessage(message) {
|
||||
const filterRegistry = this.filterRegistry;
|
||||
if (
|
||||
!(
|
||||
message.type.endsWith('.summary') ||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
const throwIfMissing = require('../../support/util').throwIfMissing;
|
||||
const isEmpty = require('lodash.isempty');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
const log = require('intel').getLogger('sitespeedio.plugin.influxdb');
|
||||
const Sender = require('./sender');
|
||||
const sendAnnotations = require('./send-annotation');
|
||||
|
|
@ -19,6 +18,7 @@ const defaultConfig = {
|
|||
module.exports = {
|
||||
open(context, options) {
|
||||
throwIfMissing(options.influxdb, ['host', 'database'], 'influxdb');
|
||||
this.filterRegistry = context.filterRegistry;
|
||||
log.debug(
|
||||
'Setup InfluxDB host %s and database %s',
|
||||
options.influxdb.host,
|
||||
|
|
@ -33,6 +33,7 @@ module.exports = {
|
|||
this.dataGenerator = new DataGenerator(opts.includeQueryParams, options);
|
||||
},
|
||||
processMessage(message) {
|
||||
const filterRegistry = this.filterRegistry;
|
||||
if (
|
||||
!(
|
||||
message.type.endsWith('.summary') ||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
const flatten = require('../../support/flattenMessage');
|
||||
const merge = require('lodash.merge');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
|
||||
const defaultConfig = {
|
||||
list: false,
|
||||
|
|
@ -14,8 +13,10 @@ module.exports = {
|
|||
this.options = merge({}, defaultConfig, options.metrics);
|
||||
this.metrics = {};
|
||||
this.storageManager = context.storageManager;
|
||||
this.filterRegistry = context.filterRegistry;
|
||||
},
|
||||
processMessage(message) {
|
||||
const filterRegistry = this.filterRegistry;
|
||||
// only dance if we all wants to
|
||||
if (this.options.filter) {
|
||||
if (message.type === 'sitespeedio.setup') {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
const urlParser = require('url');
|
||||
const filterRegistry = require('../../support/filterRegistry');
|
||||
const analyzer = require('./analyzer');
|
||||
const aggregator = require('./aggregator');
|
||||
const forEach = require('lodash.foreach');
|
||||
|
|
@ -34,7 +33,7 @@ const DEFAULT_SUMMARY_METRICS = [
|
|||
'custom.*.custom.*'
|
||||
];
|
||||
|
||||
function addCustomMetric(result) {
|
||||
function addCustomMetric(result, filterRegistry) {
|
||||
const customMetrics = get(result, 'data.median.firstView.custom');
|
||||
if (customMetrics) {
|
||||
for (const customMetric of customMetrics) {
|
||||
|
|
@ -69,22 +68,24 @@ module.exports = {
|
|||
this.make = context.messageMaker('webpagetest').make;
|
||||
this.options = merge({}, defaultConfig, options.webpagetest);
|
||||
this.storageManager = context.storageManager;
|
||||
this.filterRegistry = context.filterRegistry;
|
||||
if (!this.options.key && isPublicWptHost(this.options.host)) {
|
||||
throw new Error(
|
||||
'webpagetest.key needs to be specified when using the public WebPageTest server.'
|
||||
);
|
||||
}
|
||||
|
||||
filterRegistry.registerFilterForType(
|
||||
context.filterRegistry.registerFilterForType(
|
||||
DEFAULT_PAGE_SUMMARY_METRICS,
|
||||
'webpagetest.pageSummary'
|
||||
);
|
||||
filterRegistry.registerFilterForType(
|
||||
context.filterRegistry.registerFilterForType(
|
||||
DEFAULT_SUMMARY_METRICS,
|
||||
'webpagetest.summary'
|
||||
);
|
||||
},
|
||||
processMessage(message, queue) {
|
||||
const filterRegistry = this.filterRegistry;
|
||||
const make = this.make;
|
||||
const wptOptions = this.options;
|
||||
switch (message.type) {
|
||||
|
|
@ -94,7 +95,7 @@ module.exports = {
|
|||
return analyzer
|
||||
.analyzeUrl(url, this.storageManager, wptOptions)
|
||||
.tap(result => {
|
||||
addCustomMetric(result);
|
||||
addCustomMetric(result, filterRegistry);
|
||||
if (result.trace) {
|
||||
forEach(result.trace, (value, key) => {
|
||||
queue.postMessage(
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ const Promise = require('bluebird'),
|
|||
browsertimeConfig = require('./plugins/browsertime').config,
|
||||
webpagetestConfig = require('./plugins/webpagetest').config,
|
||||
messageMaker = require('./support/messageMaker'),
|
||||
filterRegistry = require('./support/filterRegistry'),
|
||||
packageInfo = require('../package');
|
||||
|
||||
const QueueHandler = require('./core/queueHandler'),
|
||||
|
|
@ -147,7 +148,8 @@ module.exports = {
|
|||
budget: budgetResult,
|
||||
name: url,
|
||||
log,
|
||||
messageMaker
|
||||
messageMaker,
|
||||
filterRegistry
|
||||
};
|
||||
return runOptionalFunction(allPlugins, 'open', context, options)
|
||||
.then(() => queueHandler.run(urlSources))
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ const fs = require('fs');
|
|||
const path = require('path');
|
||||
const expect = require('chai').expect;
|
||||
const messageMaker = require('../lib/support/messageMaker');
|
||||
const filterRegistry = require('../lib/support/filterRegistry');
|
||||
|
||||
const wptResultPath = path.resolve(
|
||||
__dirname,
|
||||
|
|
@ -15,24 +16,20 @@ const wptResultPath = path.resolve(
|
|||
const wptResult = JSON.parse(fs.readFileSync(wptResultPath, 'utf8'));
|
||||
|
||||
describe('webpagetest', () => {
|
||||
const context = { messageMaker, filterRegistry };
|
||||
|
||||
describe('plugin', () => {
|
||||
it('should require key for default server', () => {
|
||||
expect(() => plugin.open({ messageMaker }, {})).to.throw();
|
||||
expect(() => plugin.open(context, {})).to.throw();
|
||||
});
|
||||
it('should require key for public server', () => {
|
||||
expect(() =>
|
||||
plugin.open(
|
||||
{ messageMaker },
|
||||
{ webpagetest: { host: 'www.webpagetest.org' } }
|
||||
)
|
||||
plugin.open(context, { webpagetest: { host: 'www.webpagetest.org' } })
|
||||
).to.throw();
|
||||
});
|
||||
it('should not require key for private server', () => {
|
||||
expect(() =>
|
||||
plugin.open(
|
||||
{ messageMaker },
|
||||
{ webpagetest: { host: 'http://myserver.foo' } }
|
||||
)
|
||||
plugin.open(context, { webpagetest: { host: 'http://myserver.foo' } })
|
||||
).to.not.throw();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue