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

Extract runtime parameters #736

Merged
merged 5 commits into from
May 4, 2020
Merged

Extract runtime parameters #736

merged 5 commits into from
May 4, 2020

Conversation

sebastianbenz
Copy link
Collaborator

This PR extracts fetching and configuration of runtime parameters into a
separate function outside the transformers. This externalizes and
centralizes runtime parameter handling enabling, removing the
responsibility of handling runtime configuration inside transformers
(with the potential for duplication) and enabling future optimizations
of file system based caching of runtime artifacts (see #650).

This PR has a breaking change for the experimental RTV runtime URL re-writing as it now needs to be enabled explicitly via rtv: true.

@sebastianbenz
Copy link
Collaborator Author

@mdmower would be great if you could take a look. You probably know most about how runtime version parameters need to be handled. Thanks!

This PR extracts fetching and configuration of runtime parameters into a
separate function outside the transformers. This externalizes and
centralizes runtime parameter handling enabling, removing the
responsibility of handling runtime configuration inside transformers
(with the potential for duplication) and enabling future optimizations
of file system based caching of runtime artifacts (see #650).
Copy link
Contributor

@mdmower mdmower left a comment

Choose a reason for hiding this comment

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

I ran this through my own little optimize script (tests ampproject cdn and self hosting, with and without rtv) with the few necessary changes and it works as expected.

Consolidating the read and manipulation of runtime parameters into fetchRuntimeParameters was a good idea, thanks for working on it!

Only a few suggestions to consider, nothing blocking.

*
* @param {Object} config - the AMP Optimizer config
* @param {Object} customRuntimeParameters - user defined runtime parameters
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

You might consider adding a @returns to quickly identify the parameters that are typically returned. It's a bit difficult to identify them all by reading through the code. Similarly, in the description, you might mention which parameters are simply validated, which parameters are fetched and verified via network, and the rest pass-through untouched.

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

@@ -145,13 +144,13 @@ class DomTransformer {
* @param {Array.<Transformer>} config.transformations - a list of transformers to be applied.
*/
setConfig(config) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I might opt for this.config = this.setConfig(config); in the constructor so that it's easier to identify that DomTransformer has property config available without digging into a function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This duplicates initializing the field in the constructor and in the setter. Imo setX implies that there's a field (my Java roots might be showing trough here...)

@@ -1,3 +1,9 @@
<!--
{
"ampRuntimeVersion": "0123456789",
Copy link
Contributor

Choose a reason for hiding this comment

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

Since AMP has decided RTVs must be 15-digits, we might want to get in the habit of using valid versions in examples and tests.

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 point - done

Copy link
Collaborator Author

@sebastianbenz sebastianbenz left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the review! Addressed the comments.

@@ -1,3 +1,9 @@
<!--
{
"ampRuntimeVersion": "0123456789",
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 point - done

@sebastianbenz sebastianbenz merged commit bb242b6 into master May 4, 2020
@sebastianbenz sebastianbenz deleted the fetch branch May 4, 2020 20:04
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.

3 participants