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(driver): warn about remaining inflight requests urls #14963

Merged
merged 1 commit into from
May 4, 2023

Conversation

doteric
Copy link
Contributor

@doteric doteric commented Apr 12, 2023

Summary

Add extra warning to show inflight requests if the load timeout is reached.

The reason of this small and simple change is to give the user a better logging experience to know what's wrong.

@doteric doteric requested a review from a team as a code owner April 12, 2023 12:37
@doteric doteric requested review from adamraine and removed request for a team April 12, 2023 12:37
@google-cla
Copy link

google-cla bot commented Apr 12, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@@ -487,6 +487,18 @@ async function waitForFullyLoaded(session, networkMonitor, options) {
throw new LighthouseError(LighthouseError.errors.PAGE_HUNG);
}

// Log remaining inflight requests if any.
const inflightRequestsUrl = networkMonitor
Copy link
Collaborator

Choose a reason for hiding this comment

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

inflightRequestUrls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

if (inflightRequestsUrl.length > 0) {
log.warn(
"waitFor",
"Remaining inflight requests URLs",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"Remaining inflight requests URLs",
"Remaining inflight requests",

Copy link
Member

Choose a reason for hiding this comment

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

This line could be really long if there are multiple requests, maybe we should have each request on its own line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @connorjclark and @adamraine
Thanks for the feedback 💪

From my point of view as long as it's an array that common console/terminal formatters can handle then it should be fine. But maybe you'd like me to add something along the lines of show first 5 requests and after that ...and X more requests for example? That way it should be pretty neat in case of a lot of remaining inflight requests🤔

Copy link
Collaborator

@connorjclark connorjclark Apr 18, 2023

Choose a reason for hiding this comment

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

The debug module is going to format the object given using the inspect interface (same as if you console logged it). For arrays, that elides the elements.

image

My preference is to join the urls using , , and keeping it to a single warn message.

Copy link
Contributor Author

@doteric doteric Apr 18, 2023

Choose a reason for hiding this comment

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

@connorjclark Thanks for checking this 💪

My preference is to join the urls using , , and keeping it to a single warn message.

Do you mean like you posted on your screenshot or inflightRequestsUrl.join(',')? I would prefer the first option so the way you posted it on your screenshot 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

inflightRequestsUrl.join(', '). There shouldn't be on the order of hundreds (or even dozens...) of in flight requests, so I don't think we'd ever even see this log message being elided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you'd prefer that then sure, but what do you think about just keeping inflightRequestsUrl and let the terminals (or wherever the logs are) to handle the formatting? Seems more safe than joining with , 🤔
But if you'd heavily prefer inflightRequestsUrl.join(', ') then just let me know and I'll change it to that and we can proceed 😁
Thank you for the review btw 💪

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bump
@adamraine & @connorjclark let me know please :D

@@ -63,7 +63,7 @@ describe('waitForFullyLoaded()', () => {

beforeEach(() => {
session = {sendCommand: fnAny().mockResolvedValue(), setNextProtocolTimeout: fnAny()};
networkMonitor = {};
networkMonitor = {getInflightRequests: fnAny().mockReturnValue([])};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the recommended approach to mocking log to test if it has been called correctly? I found importMock, but it doesn't seem to support mocking external modules.

Copy link
Member

@brendankenny brendankenny Apr 19, 2023

Choose a reason for hiding this comment

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

log.events will emit events when something is logged (edit, well, log.warned, at least), so you can collect those events and assert those without mocking. One example:

/** @type {Array<unknown>} */
const warnings = [];
/** @param {unknown} evt */
const saveWarning = evt => warnings.push(evt);
log.events.on('warning', saveWarning);
const filtered = filters.filterConfigByExplicitFilters(resolvedConfig, {
onlyAudits: null,
onlyCategories: ['timespan', 'thisIsNotACategory'],
skipAudits: null,
});
log.events.off('warning', saveWarning);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know if the test is fine or you would like something more and I'll add it :D
codecov seems to be complaining for some reason though as if it didn't catch the test :/

@connorjclark connorjclark merged commit 60117f8 into GoogleChrome:main May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants