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

core(config): switch to lantern by default, add presets #5041

Merged
merged 13 commits into from
May 3, 2018
15 changes: 7 additions & 8 deletions lighthouse-cli/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ const getFlags = require('./cli-flags.js').getFlags;
const runLighthouse = require('./run').runLighthouse;

const log = require('lighthouse-logger');
const perfOnlyConfig = require('../lighthouse-core/config/perf-config.js');
const mixedContentConfig = require('../lighthouse-core/config/mixed-content-config.js');
// @ts-ignore
const pkg = require('../package.json');
const Sentry = require('../lighthouse-core/lib/sentry');
Expand Down Expand Up @@ -54,12 +52,13 @@ if (cliFlags.configPath) {
// Resolve the config file path relative to where cli was called.
cliFlags.configPath = path.resolve(process.cwd(), cliFlags.configPath);
config = /** @type {LH.Config.Json} */ (require(cliFlags.configPath));
} else if (cliFlags.perf) {
config = perfOnlyConfig;
} else if (cliFlags.mixedContent) {
config = mixedContentConfig;
// The mixed-content audits require headless Chrome (https://crbug.com/764505).
cliFlags.chromeFlags = `${cliFlags.chromeFlags} --headless`;
} else if (cliFlags.preset) {
if (cliFlags.preset === 'mixed-content') {
// The mixed-content audits require headless Chrome (https://crbug.com/764505).
cliFlags.chromeFlags = `${cliFlags.chromeFlags} --headless`;
}

config = require(`../lighthouse-core/config/${cliFlags.preset}-config.js`);
}

// set logging preferences
Expand Down
9 changes: 4 additions & 5 deletions lighthouse-cli/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function getFlags(manualArgv) {
.group(
[
'save-assets', 'list-all-audits', 'list-trace-categories', 'additional-trace-categories',
'config-path', 'chrome-flags', 'perf', 'mixed-content', 'port', 'hostname',
'config-path', 'preset', 'chrome-flags', 'port', 'hostname',
'max-wait-for-load', 'enable-error-reporting', 'gather-mode', 'audit-mode',
'only-audits', 'only-categories', 'skip-audits',
],
Expand Down Expand Up @@ -86,11 +86,10 @@ function getFlags(manualArgv) {
'additional-trace-categories':
'Additional categories to capture with the trace (comma-delimited).',
'config-path': 'The path to the config JSON.',
'mixed-content': 'Use the mixed-content auditing configuration.',
'preset': 'Use a built-in configuration.',
'chrome-flags':
`Custom flags to pass to Chrome (space-delimited). For a full list of flags, see http://bit.ly/chrome-flags
Additionally, use the CHROME_PATH environment variable to use a specific Chrome binary. Requires Chromium version 54.0 or later. If omitted, any detected Chrome Canary or Chrome stable will be used.`,
'perf': 'Use a performance-test-only configuration',
'hostname': 'The hostname to use for the debugging protocol.',
'port': 'The port to use for the debugging protocol. Use 0 for a random port',
'max-wait-for-load':
Expand All @@ -117,11 +116,11 @@ function getFlags(manualArgv) {
// boolean values
.boolean([
'disable-storage-reset', 'disable-device-emulation', 'save-assets', 'list-all-audits',
'list-trace-categories', 'perf', 'view', 'verbose', 'quiet', 'help',
'mixed-content',
'list-trace-categories', 'view', 'verbose', 'quiet', 'help',
])
.choices('output', printer.getValidOutputOptions())
.choices('throttling-method', ['devtools', 'provided', 'simulate'])
.choices('preset', ['full', 'perf', 'mixed-content'])
// force as an array
// note MUST use camelcase versions or only the kebab-case version will be forced
.array('blockedUrlPatterns')
Expand Down
5 changes: 4 additions & 1 deletion lighthouse-cli/test/smokehouse/byte-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

/**
* Config file for running PWA smokehouse audits.
* Config file for running byte efficiency smokehouse audits.
*/
module.exports = {
extends: 'lighthouse:full',
Expand All @@ -22,5 +22,8 @@ module.exports = {
'unused-css-rules',
'unused-javascript',
],

// TODO(phulce): re-write testers to work with faster lantern loading
throttlingMethod: 'devtools',
},
};
2 changes: 1 addition & 1 deletion lighthouse-cli/test/smokehouse/perf/expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

/**
* Expected Lighthouse audit values for --perf tests
* Expected Lighthouse audit values for --preset=perf tests
*/
module.exports = [
{
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-cli/test/smokehouse/run-smoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const SMOKETESTS = [{
}, {
id: 'tti',
expectations: 'tricky-tti/expectations.js',
config: 'lighthouse-core/config/default-config.js',
config: 'lighthouse-core/config/perf-config.js',
batch: 'parallel-second',
}];

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-cli/test/smokehouse/tricky-tti/expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'use strict';

/**
* Expected Lighthouse audit values for --perf tests
* Expected Lighthouse audit values for tricky TTI tests
*/
module.exports = [
{
Expand Down
24 changes: 23 additions & 1 deletion lighthouse-core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function deepClone(json) {
// injection of plugins.
if (Array.isArray(json.passes)) {
cloned.passes.forEach((pass, i) => {
pass.gatherers = cloneArrayWithPluginSafety(json.passes[i].gatherers);
pass.gatherers = cloneArrayWithPluginSafety(json.passes[i].gatherers || []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happened here? Don't we require at least an empty array in the passes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well IMO, we shouldn't and the new defaults for passes make sure it's at least an empty array, but that doesn't work with the cloning, I can revert if you feel strongly all passes should declare empty gatherers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I think that makes sense in the extending case, if I'm reading your response correctly. Can you make gatherers optional in the LH.Config.PassJson side of things, then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 👍

});
}

Expand Down Expand Up @@ -249,6 +249,8 @@ class Config {
skipAuditIds);
}

Config.adjustDefaultPassForThrottling(configJSON);

// Store the directory of the config path, if one was provided.
this._configDir = configPath ? path.dirname(configPath) : undefined;

Expand Down Expand Up @@ -381,6 +383,26 @@ class Config {
return mergedItems;
}

/**
* Observed throttling methods (devtools/provided) require at least 5s of quiet for the metrics to
* be computed. This method adjusts the quiet thresholds to the required minimums if necessary.
*
* @param {LH.Config.Json} config
*/
static adjustDefaultPassForThrottling(config) {
if (config.settings.throttlingMethod !== 'devtools' &&
config.settings.throttlingMethod !== 'provided') {
return;
}

const defaultPass = config.passes.find(pass => pass.passName === 'defaultPass');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hopefully in the future we can make a way to tell if it's a metric-measuring pass (similar to gather-runner's hacky isPerfRun) rather than just the default pass, but not sure how to solve the problem if you want to do metric-measuring and have your own thresholds here that are less than the defaults...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that makes sense, I suppose we could do it on all useThrottling passes as a proxy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed offline, it's an impl detail of TTI that we need 5s+ which is hardcoded to defaultPass so we're sticking to defaultPass for now 👍

if (!defaultPass) return;

defaultPass.pauseAfterLoadMs = Math.max(5250, defaultPass.pauseAfterLoadMs);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feels like this 5250 magic number should be defined in constants.js

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call done

defaultPass.cpuQuietThresholdMs = Math.max(5250, defaultPass.cpuQuietThresholdMs);
defaultPass.networkQuietThresholdMs = Math.max(5250, defaultPass.networkQuietThresholdMs);
}

/**
* Filter out any unrequested items from the config, based on requested top-level categories.
* @param {!Object} oldConfig Lighthouse config object
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/config/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const throttling = {
const defaultSettings = {
output: 'json',
maxWaitForLoad: 45 * 1000,
throttlingMethod: 'devtools',
throttlingMethod: 'simulate',
throttling: throttling.mobile3G,
auditMode: false,
gatherMode: false,
Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ module.exports = {
passName: 'defaultPass',
recordTrace: true,
useThrottling: true,
pauseAfterLoadMs: 5250,
networkQuietThresholdMs: 5250,
cpuQuietThresholdMs: 5250,
pauseAfterLoadMs: 1000,
networkQuietThresholdMs: 1000,
cpuQuietThresholdMs: 1000,
gatherers: [
'url',
'scripts',
Expand Down
48 changes: 0 additions & 48 deletions lighthouse-core/config/fast-config.js

This file was deleted.

4 changes: 0 additions & 4 deletions lighthouse-core/config/mixed-content-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ module.exports = {
// (2) Re-load page but attempt to upgrade each request to HTTPS.
passes: [{
passName: 'defaultPass',
// overwrite the throttling and load wait parameters to regular pass defaults
pauseAfterLoadMs: 0,
networkQuietThresholdMs: 0,
cpuQuietThresholdMs: 0,
gatherers: ['url'],
}, {
passName: 'mixedContentPass',
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/config/perf-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
module.exports = {
extends: 'lighthouse:default',
settings: {
throttlingMethod: 'devtools',
onlyCategories: ['performance'],
},
};
3 changes: 2 additions & 1 deletion lighthouse-core/scripts/assert-golden-lhr-unchanged.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ trap teardown EXIT

colorText "Generating a fresh LHR..." "$purple"
set -x
node "$lhroot_path/lighthouse-cli" -A="$lhroot_path/lighthouse-core/test/results/artifacts" --quiet --output=json --output-path="$freshLHRPath" http://localhost/dobetterweb/dbw_tester.html
# TODO(phulce): add a lantern LHR-differ
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should do this soon

node "$lhroot_path/lighthouse-cli" -A="$lhroot_path/lighthouse-core/test/results/artifacts" --throttling-method=devtools --quiet --output=json --output-path="$freshLHRPath" http://localhost/dobetterweb/dbw_tester.html
set +x

# remove timing from both
Expand Down
37 changes: 37 additions & 0 deletions lighthouse-core/test/config/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,43 @@ describe('Config', () => {
assert.ok(auditNames.has('first-meaningful-paint'), 'did not include default audits');
});

it('ensures quiet thresholds are sufficient when using devtools', () => {
const config = new Config({
extends: 'lighthouse:default',
settings: {
throttlingMethod: 'devtools',
onlyCategories: ['performance'],
},
});

assert.equal(config.settings.throttlingMethod, 'devtools');
assert.ok(config.passes[0].pauseAfterLoadMs >= 5000, 'did not adjust load quiet ms');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add assertion that this is defaultPass? And maybe a test (or modify this test) with more categories so it can check other passes aren't affected

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assert.ok(config.passes[0].cpuQuietThresholdMs >= 5000, 'did not adjust cpu quiet ms');
assert.ok(config.passes[0].networkQuietThresholdMs >= 5000, 'did not adjust network quiet ms');
});

it('does nothing when thresholds for devtools are already sufficient', () => {
const config = new Config({
extends: 'lighthouse:default',
settings: {
throttlingMethod: 'devtools',
onlyCategories: ['performance'],
},
passes: [
{
pauseAfterLoadMs: 10001,
cpuQuietThresholdMs: 10002,
networkQuietThresholdMs: 10003,
},
],
});

assert.equal(config.settings.throttlingMethod, 'devtools');
assert.equal(config.passes[0].pauseAfterLoadMs, 10001);
assert.equal(config.passes[0].cpuQuietThresholdMs, 10002);
assert.equal(config.passes[0].networkQuietThresholdMs, 10003);
});

it('merges settings with correct priority', () => {
const config = new Config(
{
Expand Down
3 changes: 1 addition & 2 deletions lighthouse-extension/app/src/lighthouse-background.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const RawProtocol = require('../../../lighthouse-core/gather/connections/raw');
const Runner = require('../../../lighthouse-core/runner');
const Config = require('../../../lighthouse-core/config/config');
const defaultConfig = require('../../../lighthouse-core/config/default-config.js');
const fastConfig = require('../../../lighthouse-core/config/fast-config.js');
const log = require('lighthouse-logger');

/**
Expand All @@ -22,7 +21,7 @@ const log = require('lighthouse-logger');
window.runLighthouseForConnection = function(
connection, url, options, categoryIDs,
updateBadgeFn = function() { }) {
const config = options && options.fastMode ? new Config(fastConfig, options.flags) : new Config({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where was this set before? I can't find it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's just set by lightrider, all runs for them will be simulated now anyway

const config = new Config({
extends: 'lighthouse:default',
settings: {onlyCategories: categoryIDs},
}, options.flags);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"changelog": "conventional-changelog --config ./build/changelog-generator/index.js --infile changelog.md --same-file",
"type-check": "tsc -p .",
"update:sample-artifacts": "node lighthouse-core/scripts/update-report-fixtures.js -G",
"update:sample-json": "node ./lighthouse-cli -A=./lighthouse-core/test/results/artifacts --output=json --output-path=./lighthouse-core/test/results/sample_v2.json http://localhost/dobetterweb/dbw_tester.html && node lighthouse-core/scripts/cleanup-LHR-for-diff.js ./lighthouse-core/test/results/sample_v2.json --only-remove-timing",
"update:sample-json": "node ./lighthouse-cli -A=./lighthouse-core/test/results/artifacts --throttling-method=devtools --output=json --output-path=./lighthouse-core/test/results/sample_v2.json http://localhost/dobetterweb/dbw_tester.html && node lighthouse-core/scripts/cleanup-LHR-for-diff.js ./lighthouse-core/test/results/sample_v2.json --only-remove-timing",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing this to avoid the mixed settings error, right?
next run of update-report-fixtures will be throttling-method: 'simulate', right?

so a followup PR to update both makes sense to me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but speaking of. perhaps we should also have 1 golden LHR for simulate and 1 for throttled. Feels like we have a blind spot otherwise.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also left the golden LHR diffing on observed for now to reduce the noise, seems like we'll want to be checking both in our tests anyhow once there's 100% parity?

totally agree ;)

"diff:sample-json": "bash lighthouse-core/scripts/assert-golden-lhr-unchanged.sh",
"update:crdp-typings": "node lighthouse-core/scripts/extract-crdp-mapping.js",
"mixed-content": "./lighthouse-cli/index.js --chrome-flags='--headless' --config-path=./lighthouse-core/config/mixed-content.js"
Expand Down
1 change: 0 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ Configuration:
CHROME_PATH: Explicit path of intended Chrome binary. If set must point to an executable of a build of
Chromium version 54.0 or later. By default, any detected Chrome Canary or Chrome (stable) will be launched.
[default: ""]
--perf Use a performance-test-only configuration [boolean]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need presets and other new changes here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

--port The port to use for the debugging protocol. Use 0 for a random port [default: 0]
--hostname The hostname to use for the debugging protocol. [default: "localhost"]
--max-wait-for-load The timeout (in milliseconds) to wait before the page is considered done loading and the run should continue.
Expand Down
1 change: 1 addition & 0 deletions typings/externs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ declare global {
listAllAudits: boolean;
listTraceCategories: boolean;
configPath?: string;
preset?: 'full'|'mixed-content'|'perf';
perf: boolean;
mixedContent: boolean;
verbose: boolean;
Expand Down