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): augment settings/passes with defaults #4894

Merged
merged 2 commits into from
Apr 4, 2018

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Mar 30, 2018

WIP, but I'm waiting to fix all the tests and do cleanup until we get some consensus on what this looks like :) updated all the tests!

This PR would move all defaults that can be specified in the config to a config/constants.js file, enforces that all configs implicitly extend default, and changes the defaults specified across various files to be pulled in from constants. This PR also does some promised hygiene on our config files.

Points of discussion with my opinions:

  • Do we like that all configs extend default?
    Yes we can now make more assumptions about the config and most valid use cases for truly custom can be achieved through onlyAudits/onlyCategories/skipAudits/etc
  • Do we like all constants/defaults live in a separate file?
    Yes it will be super convenient for scanning all tunable parameters and it's easy to require the constants file in to all the places we still want to double-default parameters for more convenient testing, etc.
  • ????

cc @benschwarz in case you're doing any custom config magic we might want to know about :)

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

lgtm % nits


module.exports = {
throttling,
defaultSettings: {
Copy link
Member

Choose a reason for hiding this comment

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

might as well extract this obv to a var like the throttling one.
and same with defaultPassConfig.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sg done

@@ -55,8 +54,6 @@ 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} */ (require(cliFlags.configPath));
} else if (cliFlags.perf) {
Copy link
Member

Choose a reason for hiding this comment

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

you're removing --perf ? omg

Copy link
Member

Choose a reason for hiding this comment

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

can we add an alias for --onlyCategories=perf (is that it?)

Copy link
Collaborator Author

@patrickhulce patrickhulce Mar 30, 2018

Choose a reason for hiding this comment

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

yeah added back the flag as an alias for --only-categories=performance for now, but IMO we should get rid of it for v3 :)

@patrickhulce
Copy link
Collaborator Author

@brendankenny this overall direction look good enough to you for me to change all tests?

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

Added some general comments on the current version. Overall, though, I really like just using all the settings from the default config.

Copying over the the default passes and audits seems a lot more complicated, though, at least with our current overriding semantics. It seems easy to express "add these additional things", but much harder to say "I want to run only these new things", unless I'm missing how it works :)

As a result, the onlyCategories: ['mixedContent'], in mixed-content-config.js ends up being a pretty subtle line for such non-trivial effects (again, if I'm reading this correctly :)

cpuSlowdownMultiplier: emulation.CPU_THROTTLE_METRICS.rate,
},
},
settings: constants.defaultSettings,
Copy link
Member

Choose a reason for hiding this comment

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

maybe this is still better broken out as an object where the properties are set to individual constants? It would be nice if the shape of default-config.js was still readable in place, even if the actual numeric values require a lookup

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd be against that since it feels like a small when at the cost of manual/error-prone work to copy properties from one file to the other and muddies the source of truth, the shape of settings is a cmd+click away still :)

Maybe it's just me, @paulirish WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

at first i was like "yah" but now i'm like "nah"

having the keynames present would be nice, but mostly a tease if the actual values aren't there. might as well be clear that the source of truth is not this file.

so i'm +1 on keeping it as is in the PR

docs/readme.md Outdated

```js
const perfConfig: any = require('lighthouse/lighthouse-core/config/perf.json');
const perfConfig = {settings: {onlyCategories: ['performance']}};
Copy link
Member

Choose a reason for hiding this comment

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

this is a nice example though is it possible do we want to get rid of perf-config.js? There are more potential tweaks that could be made there beyond just onlyCategories

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 just brought it back since you and paul are both against

// ...
launchChromeAndRunLighthouse(url, flags, perfConfig).then( // ...
```

You can also craft your own config (e.g. [plots-config.js](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/plots-config.js)) for completely custom runs. Also see the [basic custom audit recipe](https://github.com/GoogleChrome/lighthouse/tree/master/docs/recipes/custom-audit).
You can also craft your own config (e.g. [mixed-content-config.js](https://github.com/GoogleChrome/lighthouse/blob/master/lighthouse-core/config/mixed-content-config.js)) for custom runs. Also see the [basic custom audit recipe](https://github.com/GoogleChrome/lighthouse/tree/master/docs/recipes/custom-audit).
Copy link
Member

Choose a reason for hiding this comment

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

recipes/custom-audit

does this still work? we should probably have a test for that...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

heh, yeah I updated the recipe to nuke the extends property

@@ -56,7 +55,7 @@ if (cliFlags.configPath) {
cliFlags.configPath = path.resolve(process.cwd(), cliFlags.configPath);
config = /** @type {!LH.Config} */ (require(cliFlags.configPath));
} else if (cliFlags.perf) {
config = /** @type {!LH.Config} */ (perfOnlyConfig);
cliFlags.onlyCategories = ['performance'];
Copy link
Member

Choose a reason for hiding this comment

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

does this get weird if they supply a config and specify --perf? The old overwriting config completely seems more predictable

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 just brought it back since you and paul are both against

@@ -3,8 +3,8 @@
node lighthouse-cli/test/fixtures/static-server.js &

sleep 0.5s

config="lighthouse-core/config/perf.json"
# TODO: replace this with a smoketest for --only-categories performance and nuke the perf-config
Copy link
Member

Choose a reason for hiding this comment

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

pull out into a tracking issue (or add to breaking changes umbrella)? Bigger change than just dropping the smoke test :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nuked since we'll keep the config around

@@ -13,7 +13,7 @@

const Audit = require('./audit');
const URL = require('../lib/url-shim');
const Emulation = require('../lib/emulation');
const mobile3G = require('../config/constants').throttling.mobile3G;
Copy link
Member

Choose a reason for hiding this comment

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

nit: to keep the more descriptive name, maybe const targetLatencyMs = require('../config/constants').throttling.mobile3G.rttMs?

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


const isEqual = require('lodash.isequal');
Copy link
Member

Choose a reason for hiding this comment

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

this is no problem for longtime lodash users, I'm sure, but any chance of calling the local deepEqual? :)

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

@patrickhulce
Copy link
Collaborator Author

but much harder to say "I want to run only these new things", unless I'm missing how it works :)
As a result, the onlyCategories: ['mixedContent'], in mixed-content-config.js ends up being a pretty subtle line for such non-trivial effects (again, if I'm reading this correctly :)

I'm not sure if it's harder to say I want to run only these things since it's still just 1 prop you stick in the config, but I agree the "everything extends default" makes things more confusing as to what will be run. It'd be great to know how anyone not on the Lighthouse team feels about these changes and if the ergonomic win is worth it, @benschwarz @denar90 any reactions to always extend default config?

My sneaking suspicion is that onlyCategories: ['mixedContent'] is subtle to those who know too much about how config.js works, from the user's perspective if onlyCategories/onlyAudits always just gives you those categories/audits in the most efficient way then what's the problem? :)

@patrickhulce patrickhulce changed the title [WIP] core(config): all configs must extend default core(config): all configs must extend default Apr 2, 2018
@patrickhulce
Copy link
Collaborator Author

ok updated all the tests, it actually wasn't that bad. 2 major consequences:

  • we now support filtering of the config in conjunction with plugin injection (the only way to run just the a few custom programmatic audits)
  • we no longer throw on a few previously invalid cases because we'll default the passes/config so that it looks good

@brendankenny
Copy link
Member

brendankenny commented Apr 3, 2018

A solution in the middle could be to pull over settings from the default config and not passes/audits/categories (or, equivalently, have a base audit with empty passes/audits/categories). I'm not sure how that would work with individual pass settings, though (back to default constants instead of from a base config?)

Some of the tests aren't unreasonable cases, like "only run these gatherers, not audits or categories" (and other gatherers?), and having to use onlyCategories or -G to not run the audits and categories added by default seems like a step back.

This does seem to be trading mental complexity for a nice model of config defaults...

@@ -6,20 +6,13 @@
'use strict';

module.exports = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we don't need our own config anymore 💃
https://github.com/paulirish/pwmetrics/blob/v3.2.0/lib/lh-config.ts

@patrickhulce patrickhulce changed the title core(config): all configs must extend default core(config): augment settings/passes with defaults Apr 3, 2018
Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

Nice! Really like the simplifications in config.js

@@ -15,8 +15,9 @@ const runLighthouse = require('./run').runLighthouse;

const log = require('lighthouse-logger');
// @ts-ignore
const perfOnlyConfig = require('../lighthouse-core/config/perf.json');
const mixedContentConfig = require('../lighthouse-core/config/mixed-content.js');
const perfOnlyConfig = require('../lighthouse-core/config/perf-config.js');
Copy link
Member

Choose a reason for hiding this comment

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

does this still need to be @ts-ignore? I think that was because it always has an error on trying to require a json file, so it shouldn't be an issue with a js file. OTOH it might be any or hopelessly typed :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nope, totally unnecessary now good call 👍

@patrickhulce patrickhulce merged commit be055b1 into master Apr 4, 2018
@patrickhulce patrickhulce deleted the config_defaults branch April 4, 2018 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants