Enforce same naming for summary messages.

Either .pageSummary or .summary, depending on if it's for one url or not.
This commit is contained in:
Tobias Lidskog 2016-03-22 23:18:38 +01:00
parent e1af0db0bb
commit ab0bf26ce2
17 changed files with 66 additions and 50 deletions

View File

@ -24,22 +24,38 @@ const messageTypeDepths = {};
* @param message the message to check
*/
function validateMessageFormat(message) {
const typeParts = message.type.split('.'),
baseType = typeParts[0],
typeDepth = typeParts.length;
function validateTypeStructure(message) {
const typeParts = message.type.split('.'),
baseType = typeParts[0],
typeDepth = typeParts.length;
if (typeDepth > 2)
throw new Error('Message type has too many dot separated sections: ' + message.type);
if (typeDepth > 2)
throw new Error('Message type has too many dot separated sections: ' + message.type);
const previousDepth = messageTypeDepths[baseType];
const previousDepth = messageTypeDepths[baseType];
if (previousDepth && previousDepth !== typeDepth) {
throw new Error(util.format('All messages of type %s must have the same structure. ' +
'%s has %d part(s), but earlier messages had %d part(s).',
baseType, message.type, typeDepth, previousDepth));
if (previousDepth && previousDepth !== typeDepth) {
throw new Error(util.format('All messages of type %s must have the same structure. ' +
'%s has %d part(s), but earlier messages had %d part(s).',
baseType, message.type, typeDepth, previousDepth));
}
messageTypeDepths[baseType] = typeDepth;
}
messageTypeDepths[baseType] = typeDepth;
function validateSummaryMessages(message) {
const type = message.type;
if (type.endsWith('.summary') && message.url) {
throw new Error(util.format('Summary message (%s) shouldn\'t be url specific, use .pageSummary instead.', type));
}
if (type.endsWith('.pageSummary') && !message.url) {
throw new Error(util.format('Page summary message (%s) failed to specify a url', type));
}
}
validateTypeStructure(message);
validateSummaryMessages(message);
}
class QueueHandler {

View File

@ -105,7 +105,7 @@ module.exports = {
results.browsertimeData.forEach((run, runIndex) => {
queue.postMessage(make('browsertime.run', run, {url, runIndex}));
});
queue.postMessage(make('browsertime.summary', results, {url}));
queue.postMessage(make('browsertime.page', results, {url}));
})
.tap((results) => {
if (results.har) {

View File

@ -15,7 +15,7 @@ module.exports = {
return path.basename(__dirname);
},
open() {
filterRegistry.registerFilterForType(DEFAULT_METRICS, 'coach.stats');
filterRegistry.registerFilterForType(DEFAULT_METRICS, 'coach.summary');
},
processMessage(message, queue) {
switch (message.type) {
@ -32,7 +32,7 @@ module.exports = {
includeAssets: false
});
queue.postMessage(make('snufkin.summary', pageSummary, {url}));
queue.postMessage(make('snufkin.pageSummary', pageSummary, {url}));
pageSummary.forEach((run, runIndex) => {
queue.postMessage(make('snufkin.run', run, {url, runIndex}));
@ -44,7 +44,7 @@ module.exports = {
{
let summary = aggregator.summarize();
if (summary && Object.keys(summary).length > 0) {
queue.postMessage(make('coach.stats', summary));
queue.postMessage(make('coach.summary', summary));
}
break;
}

View File

@ -10,7 +10,7 @@ const make = messageMaker('domains').make;
module.exports = {
name() { return path.basename(__dirname); },
open() {
filterRegistry.registerFilterForType([''], 'domains.stats');
filterRegistry.registerFilterForType([''], 'domains.summary');
},
processMessage(message, queue) {
switch (message.type) {
@ -24,7 +24,7 @@ module.exports = {
{
const summary = aggregator.summarize();
if (summary && Object.keys(summary).length > 0) {
queue.postMessage(make('domains.stats', summary));
queue.postMessage(make('domains.summary', summary));
}
break;
}

View File

@ -30,13 +30,13 @@ module.exports = {
case 'gpsi.data':
return Promise.all([
aggregator.speedAggregator.addToAggregate(message.data),
aggregator.pageStatsAggregator.addToAggregate(message.data)
aggregator.pageSummaryAggregator.addToAggregate(message.data)
]);
case 'summarize':
{
queue.postMessage(make('gpsi.speed', aggregator.speedAggregator.summarize()));
queue.postMessage(make('gpsi.pageStats', aggregator.pageStatsAggregator.summarize()));
queue.postMessage(make('gpsi.pageSummary', aggregator.pageSummaryAggregator.summarize()));
}
}
}

View File

@ -30,11 +30,11 @@ module.exports = {
},
processMessage(message) {
switch (message.type) {
case 'browsertime.stats':
case 'webpagetest.data':
case 'gpsi.pageStats':
case 'domains.stats':
case 'coach.stats':
case 'browsertime.pageSummary':
case 'webpagetest.pageSummary':
case 'gpsi.pageSummary':
case 'domains.summary':
case 'coach.summary':
{
message = filterRegistry.filterMessage(message);
if (isEmpty(message.data))

View File

@ -25,12 +25,12 @@ module.exports = {
}
case 'browsertime.run':
case 'browsertime.summary':
case 'browsertime.page':
case 'browsertime.har':
case 'webpagetest.run':
case 'webpagetest.data':
case 'webpagetest.pageSummary':
case 'gpsi.data':
case 'snufkin.summary':
case 'snufkin.pageSummary':
case 'snufkin.run':
case 'coach.run': {
return this.HTMLBuilder.addDataForUrl(message.url, message.type, message.data, message.runIndex);
@ -44,7 +44,7 @@ module.exports = {
return this.HTMLBuilder.renderSummaryPage('assets', {assets: topAssets});
}
case 'domains.stats':
case 'domains.summary':
{
return this.HTMLBuilder.renderSummaryPage('domains', {domainStats: message.data});
}

View File

@ -1,7 +1,7 @@
h3 Timings
a#timings
- const browsertime = pageInfo.data.browsertime.run || pageInfo.data.browsertime.summary[0].browsertimeData[0]
- const browsertime = pageInfo.data.browsertime.run || pageInfo.data.browsertime.page[0].browsertimeData[0]
- const timings = browsertime.timings;
- const visualMetrics = timings.visualMetrics;

View File

@ -15,10 +15,10 @@ block content
if pageInfo.data.coach.stats
li: a(href='#coach') Coach
if pageInfo.data.browsertime
if pageInfo.data.browsertime.summary
if pageInfo.data.browsertime.page
li: a(href='#timings') Timings
if pageInfo.data.snufkin
if pageInfo.data.snufkin.summary
if pageInfo.data.snufkin.pageSummary
li: a(href='#info') Info
if pageInfo.data.webpagetest
li: a(href='#webpagetest') WebPageTest
@ -28,11 +28,11 @@ block content
include ./coach/index.jade
if pageInfo.data.browsertime
if pageInfo.data.browsertime.summary
if pageInfo.data.browsertime.page
include ./browsertime/index.jade
if pageInfo.data.snufkin
if pageInfo.data.snufkin.summary
if pageInfo.data.snufkin.pageSummary
include ./snufkin/index.jade
if pageInfo.data.webpagetest

View File

@ -1,7 +1,7 @@
h2 Page summary
a#snufkin
- const snufkin = pageInfo.data.snufkin.run || pageInfo.data.snufkin.summary[0];
- const snufkin = pageInfo.data.snufkin.run || pageInfo.data.snufkin.pageSummary[0];
p HTTP version: #{snufkin.httpVersion}

View File

@ -2,7 +2,7 @@
h2 WebPageTest
a#webpagetest
- const data = pageInfo.data.webpagetest.data[0].data
- const data = pageInfo.data.webpagetest.pageSummary[0].data
- const medianRun = data.median
a(href='#{data.summary}') WebPageTest

View File

@ -30,11 +30,11 @@ module.exports = {
},
processMessage(message) {
switch (message.type) {
case 'browsertime.stats':
case 'webpagetest.data':
case 'gpsi.pageStats':
case 'domains.stats':
case 'coach.stats':
case 'browsertime.pageSummary':
case 'webpagetest.pageSummary':
case 'gpsi.pageSummary':
case 'domains.summary':
case 'coach.summary':
{
message = filterRegistry.filterMessage(message);
if (isEmpty(message.data))

View File

@ -24,9 +24,9 @@ module.exports = {
switch (message.type) {
case 'browsertime.har':
case 'browsertime.run':
case 'domains.stats':
case 'domains.summary':
case 'gpsi.data':
case 'webpagetest.data':
case 'webpagetest.pageSummary':
replacerFunc = this.verbose > 1 ? null : shortenData;
break;

View File

@ -37,7 +37,7 @@ module.exports = {
this.options = options;
filterRegistry.registerFilterForType(DEFAULT_METRICS, 'webpagetest.data');
filterRegistry.registerFilterForType(DEFAULT_METRICS, 'webpagetest.pageSummary');
},
processMessage(message, queue) {
switch (message.type) {
@ -55,7 +55,7 @@ module.exports = {
}))
);
queue.postMessage(make('webpagetest.data', result.data, {url}));
queue.postMessage(make('webpagetest.pageSummary', result.data, {url}));
aggregator.addToAggregate(result);
})
.catch((err) => {
@ -67,7 +67,7 @@ module.exports = {
{
let summary = aggregator.summarize();
if (summary && Object.keys(summary).length > 0) {
queue.postMessage(make('webpagetest.stats', summary));
queue.postMessage(make('webpagetest.summary', summary));
}
}
}

View File

@ -33,7 +33,7 @@ module.exports = {
{
let summary = aggregator.summarize();
if (summary && Object.keys(summary).length > 0) {
queue.postMessage(make('yslow.stats', summary));
queue.postMessage(make('yslow.summary', summary));
}
}
}

View File

@ -5,9 +5,9 @@ const DataGenerator = require('../lib/plugins/graphite/data-generator'),
describe('graphite', function() {
describe('dataGenerator', function() {
it('should generate data for gpsi.pageStats', function() {
it('should generate data for gpsi.pageSummary', function() {
const message = {
"type": "gpsi.pageStats",
"type": "gpsi.pageSummary",
"timestamp": "2016-01-08T12:59:06+01:00",
"source": "gpsi",
"data": {

View File

@ -5,9 +5,9 @@ const DataGenerator = require('../lib/plugins/influxdb/data-generator'),
describe('influxdb', function() {
describe('dataGenerator', function() {
it('should generate data for gpsi.pageStats', function() {
it('should generate data for gpsi.pageSummary', function() {
const message = {
"type": "gpsi.pageStats",
"type": "gpsi.pageSummary",
"timestamp": "2016-01-08T12:59:06+01:00",
"source": "gpsi",
"data": {