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): specify lighthouse channel #7312

Merged
merged 17 commits into from
Mar 7, 2019
Merged

Conversation

mattzeunert
Copy link
Contributor

Summary

Determine whether Lighthouse was run through the CLI, npm module, Chrome extension, Chrome DevTools, or Lightrider.

Is settings the right place to put this? Feels like it's similar to locale.

Related Issues/PRs

Part of #4663

@mattzeunert mattzeunert changed the title Specify lighthouse channel core(config): specify lighthouse channel Feb 24, 2019
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

nice! this turned out to be super clean with the bundling refactors! 🎉

I think this all seems good to me! I do worry a bit that someone out there was not treating lighthouseVersion as a complete, parsable semantic version and doing version.split('.') or something but I doubt they cared about the patch version component so we're good? 🤷‍♂️

types/externs.d.ts Outdated Show resolved Hide resolved
Copy link
Member

@exterkamp exterkamp left a comment

Choose a reason for hiding this comment

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

Looks fine, just some minor questions.

lighthouse-core/test/results/sample_v2.json Outdated Show resolved Hide resolved
lighthouse-core/test/results/sample_v2.json Show resolved Hide resolved
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.

so one thing we didn't really talk about in #4663 is what happens as the LHR gets separated from its original source. Based on the conversation there, the primary purpose (for now) is to know where traffic is coming from when clicking links in the report, but what happens when you save an LHR json from DevTools or PSI and open it in viewer? Is it still useful information to know the original source, or should it be utm_medium=viewer at that point? Especially if it's shared with multiple other people...none of them are touching the original source in that case.

types/externs.d.ts Outdated Show resolved Hide resolved
lighthouse-core/index.js Outdated Show resolved Hide resolved
@@ -3172,6 +3172,7 @@
"disableStorageReset": false,
"disableDeviceEmulation": false,
"emulatedFormFactor": "mobile",
"channel": "cli",
Copy link
Member

Choose a reason for hiding this comment

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

should it also be in the top level of the LHR? Maybe inside environment, next to benchmarkIndex, etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a benefit over using lhr.configSettings.channel?

Copy link
Member

Choose a reason for hiding this comment

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

Is there a benefit over using lhr.configSettings.channel?

because it's not really a setting, but now it kind of is, so that's fine

@@ -36,6 +36,7 @@ function getDefaultConfigForCategories(categoryIDs) {
function runLighthouseInWorker(port, url, flags, categoryIDs) {
// Default to 'info' logging level.
flags.logLevel = flags.logLevel || 'info';
flags.channel = 'cdt';
Copy link
Member

Choose a reason for hiding this comment

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

do we have a good place to test any/all of these? It's going to be difficult to notice if something is accidentally falling back to the node default, but I don't know if we have a good place to check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test case for the Chrome extension.

@patrickhulce
Copy link
Collaborator

Is it still useful information to know the original source, or should it be utm_medium=viewer at that point? Especially if it's shared with multiple other people...none of them are touching the original source in that case.

I think the original source is far more important for environment info than where they are currently looking at it. Maybe not the correct thing from utm medium perspective, but I think viewer is the only real case where there will be a mismatch and maybe viewer just overrides that with UI features or something?

@mattzeunert
Copy link
Contributor Author

Any more feedback on this?

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@exterkamp exterkamp left a comment

Choose a reason for hiding this comment

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

I don't really think I'm satisfied with the field just being freeform string, I'd prefer a enumerated type on ts and on the proto. I like the longer names, but personally I want them enumerated.

@mattzeunert
Copy link
Contributor Author

I don't really think I'm satisfied with the field just being freeform string, I'd prefer a enumerated type on ts and on the proto. I like the longer names, but personally I want them enumerated.

@exterkamp We allow CLI and node module consumers to pass in their own channel values. Does it still make sense to enumerate the possible values, since I think we need string anyway?

I feel it's similar on the Lightrider/proto side, but maybe we can put psi and webdotdev in the enum?

@exterkamp
Copy link
Member

Hm, I might have missed this discussion (I don't see it in this PR?), but why do they get to pass their own channel? Wouldn't their channel be "cli" or "node-module"? Since that is the channel they were on? What's the use case for sending a custom run channel that we don't know about beforehand and have enumerated?

@brendankenny
Copy link
Member

brendankenny commented Mar 4, 2019

I think it comes down to what the purpose of the field is.

As helpful debug info after the fact, it makes sense to stick to just our "clients" (cli/node/devtools/extension/lr). That's the programmatic entry point, great.

However, #4663 was about getting a sense of what lead users to our docs. In that case it makes some sense to have it open so we can distinguish between e.g. the cli and PSI and WPT, which are all very different user experience entry points.

@exterkamp
Copy link
Member

I've been convinced irl. sgtm!

@mattzeunert
Copy link
Contributor Author

@exterkamp Should be good to merge now 🙂

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.

ok, inspired by your extension test, left some suggestions for the other channels (except devtools)

@@ -176,4 +179,8 @@ describe('Lighthouse chrome extension', function() {
// this audit has regressed in the extension twice, so make sure it passes
assert.ok(await extensionPage.$('#is-crawlable.lh-audit--pass'), 'did not pass is-crawlable');
});

it('should specify the channel as extension', async () => {
assert.equal(lhr.configSettings.channel, 'extension');
Copy link
Member

@brendankenny brendankenny Mar 5, 2019

Choose a reason for hiding this comment

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

👍 👍

@@ -34,6 +34,7 @@ async function runLighthouseInLR(connection, url, flags, {lrDevice, categoryIDs,
// disableStorageReset because it causes render server hang
flags.disableStorageReset = true;
flags.logLevel = flags.logLevel || 'info';
flags.channel = 'lr';
Copy link
Member

Choose a reason for hiding this comment

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

can assert this in lightrider-entry-test.js

@@ -146,6 +147,7 @@ function getFlags(manualArgv) {
.default('port', 0)
.default('hostname', 'localhost')
.default('enable-error-reporting', undefined) // Undefined so prompted by default
.default('channel', 'cli')
Copy link
Member

Choose a reason for hiding this comment

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

can assert this in 'runLighthouse completes a LH round trip' in run-test.js

@@ -51,6 +51,7 @@ const defaultSettings = {
disableStorageReset: false,
disableDeviceEmulation: false,
emulatedFormFactor: 'mobile',
channel: 'node',
Copy link
Member

Choose a reason for hiding this comment

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

and can assert this in lighthouse-core/test/index-test.js (basically just copy 'should return formatted LHR when given no categories' and delete most of it :)

@@ -3172,6 +3172,7 @@
"disableStorageReset": false,
"disableDeviceEmulation": false,
"emulatedFormFactor": "mobile",
"channel": "cli",
Copy link
Member

Choose a reason for hiding this comment

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

Is there a benefit over using lhr.configSettings.channel?

because it's not really a setting, but now it kind of is, so that's fine

@mattzeunert
Copy link
Contributor Author

@brendankenny Thanks for those suggestions, added them now!

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.

ok, last thing (jest over sinon), sorry, but otherwise LGTM!

@@ -56,5 +58,18 @@ describe('lightrider-entry', () => {
assert.strictEqual(parsedResult.runtimeError.code, LHError.UNKNOWN_ERROR);
assert.ok(parsedResult.runtimeError.message.includes(errorMsg));
});

it('specifies the channel as lr', async () => {
const runStub = sinon.stub(Runner, 'run');
Copy link
Member

Choose a reason for hiding this comment

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

can you use jest mocks for this? I'm hoping we can drop sinon since we currently only use it in one place

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh +1 to using jest please :)

const runStub = Runner.run = jest.fn()
...
const config = runStub.mock.calls[0][1].config

I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, somehow I felt I needed to use sinon in mocha tests 🙂

@@ -132,6 +132,31 @@ describe('Module Tests', function() {
});
});

it('should specify the channel as node by default', function() {
Copy link
Member

Choose a reason for hiding this comment

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

not a big deal, but if making one last commit, could you make these async/await? no need to stick to the style of the file for that :)

@brendankenny
Copy link
Member

thanks!

@brendankenny brendankenny merged commit d7c013f into master Mar 7, 2019
@brendankenny brendankenny deleted the lighthouse-channel branch March 7, 2019 19:32
@rviscomi
Copy link
Member

After this feature is released we'll also need to update the PSI and web.dev clients to specify their channel configs. @paulirish is there somewhere we can file an issue to do this?

@paulirish
Copy link
Member

@rviscomi interesting... :) right now PSI webapp, PSI API clients, and web.dev will be tagged as 'lr'.

We don't have a straightforward way to distinguish between different PSI API consumers easily.

How do you want to make use of this channel data?

@rviscomi
Copy link
Member

The web apps should include their channel in a UTM param appended to their learn more links so we can see where documentation visitors are coming from.

@brendankenny
Copy link
Member

brendankenny commented Mar 22, 2019

The web front ends could change the setting in the lhr before generating the report. Pretty gross, though :/

web.dev and the PSI web interface do have their own analytics (I assume), which would allow teasing out those sources, at least.

@rviscomi
Copy link
Member

Yeah I assume we do have analytics on the tools themselves, this is just for the documentation on d.g.co to easily identify the LH channel that brought the user to the docs.

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.

7 participants