[go: nahoru, domu]

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

clients(lightrider): serialize errors in artifacts #9410

Merged
merged 13 commits into from
Jul 24, 2019

Conversation

connorjclark
Copy link
Collaborator

LR specific changes for #9397

return JSON.stringify(preprocessor.processForProto(runnerResult.lhr));
const preprocessedLhr = preprocessor.processForProto(runnerResult.lhr);
// Properly serialize artifact errors for logging.
return JSON.stringify(preprocessedLhr, logAssets ? assetSaver.stringifyReplacer : undefined);
Copy link
Member

Choose a reason for hiding this comment

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

hmm, I don't think we want to structure it this way. assetSaver should be able to change stringifyReplacer at will, which will be a whole lot easier if it's only ever run over artifacts, not a whole LHR as well.

Maybe we should expose a thing on assetSaver to stringifyArtifacts (but not save them to disk like saveArtifacts() does)? My only concern is replacer performance against traces, since it runs against every single trace event (and trace event properties, recursively). That's not an issue in saveArtifacts because traces are removed before stringifying

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm, I don't think we want to structure it this way. assetSaver should be able to change stringifyReplacer at will, which will be a whole lot easier if it's only ever run over artifacts, not a whole LHR as well.

how would the resulting artifacts JSON be put back to the larger LHR json?

My only concern is replacer performance against traces, since it runs against every single trace event (and trace event properties, recursively). That's not an issue in saveArtifacts because traces are removed before stringifying

performance can also be ignored here, as asset logging is only done via the LR demo app (production would never use the replacer).

Copy link
Member

Choose a reason for hiding this comment

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

how would the resulting artifacts JSON be put back to the larger LHR json?

parse again? It's not pretty but I don't think this replacer should be responsible for preserving artifacts and LHRs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

assetSaver should be able to change stringifyReplacer at will, which will be a whole lot easier if it's only ever run over artifacts, not a whole LHR as well.

what changes are you anticipating such that this would break when you pass in an LHR? Maybe we could wait until then?

Copy link
Member

Choose a reason for hiding this comment

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

what changes are you anticipating such that this would break when you pass in an LHR? Maybe we could wait until then?

i18n strings (#9269)? Other kinds of objects? etc etc

It's been a huge help in a few areas to have a definitive single place to save/load artifacts from disk (e.g. recent changes to report-update-fixtures.js), which allowed specialization like saving traces to separate files without worry that they'd be lost when loading them at a later point. If we want to open that to stringifying (without writing to disk), we should apply the same principles and let asset-saver do whatever it has to do internally without dictating an implementation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok, done

@brendankenny
Copy link
Member

(let's move against master)

@brendankenny brendankenny changed the base branch from serializeerrors to master July 20, 2019 00:48
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.

LGTM

// @ts-ignore - piggyback the artifacts on the LHR.
runnerResult.lhr.artifacts = runnerResult.artifacts;
}
// When LR is called with |internal: {keep_raw_response: true, save_lighthouse_assets: true}|,
Copy link
Member

Choose a reason for hiding this comment

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

Move comment to be above if (logAssets) {

...preprocessedLhr,
artifacts: JSON.parse(artifactsJson),
});
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Can't decide if the else is necessary or not. I'm flip flopping on keeping it in/removing it is more readable.

Copy link
Member

Choose a reason for hiding this comment

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

Can't decide if the else is necessary or not. I'm flip flopping on keeping it in/removing it is more readable.

I'd fall on the side of no else, but really up to @connorjclark, it's fine either way

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can you be more specific about what you are suggesting instead

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 returning in both sides of the if/else. You can just remove the else here to always return JSON.stringify(preprocessedLhr).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do you see what i'm doing with artifacts tho.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh i see 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.

can you add a test for this, pls?

...preprocessedLhr,
artifacts: JSON.parse(artifactsJson),
});
} else {
Copy link
Member

Choose a reason for hiding this comment

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

Can't decide if the else is necessary or not. I'm flip flopping on keeping it in/removing it is more readable.

I'd fall on the side of no else, but really up to @connorjclark, it's fine either way

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!

test has been added, landing!

@patrickhulce patrickhulce merged commit 82835eb into master Jul 24, 2019
@patrickhulce patrickhulce deleted the lr-error-serialize branch July 24, 2019 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants