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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

鉁⊿tarted a config parser for the amp-experiment 1.0 format #21523

Merged
merged 10 commits into from Apr 1, 2019

Conversation

torch2424
Copy link
Contributor

@torch2424 torch2424 commented Mar 21, 2019

relates to #20225
relates to #21484

This starts the config parser for the 1.0 format (see #20225). Most importantly here, this preserves the analytics, but also passes an object down to applyMutations_() which can then use a mutation service to start ingestion of mutations (later PR).

  • This still requires tests. Want code approved before writing the tests 馃槃

Example

First image had some testing code to show things work

Screen Shot 2019-03-14 at 11 39 18 AM

Screen Shot 2019-03-21 at 2 31 45 PM

Copy link
Contributor

@zhouyx zhouyx left a comment

Choose a reason for hiding this comment

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

Haven't finished review yet. Need to head up early today : ) I'll continue Monday

* @package
* @restricted
*/
init(variants) {
this.variantsDeferred_.resolve(variants);
variants.then(this.variantsDeferred_.resolve);
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe you want to do
variants.then(result => this.viriantsDeferred_.resolve(result)) ?

@@ -119,7 +117,7 @@ export function allocateVariant(ampdoc, experimentName, config) {
// enumeration is implementation (browser) dependent.
const variantNames = Object.keys(config['variants']).sort();
for (let i = 0; i < variantNames.length; i++) {
upperBound += config['variants'][variantNames[i]];
upperBound += config['variants'][variantNames[i]].weight;
Copy link
Contributor

Choose a reason for hiding this comment

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

config is a JsonObject. We will need to use ['weight'] : ) Singlepass~

variantName
);

const percentage = variant.weight;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: variant['weight']

userAssert(
typeof percentage === 'number' && percentage > 0 && percentage < 100,
percentage && percentage > 0 && percentage < 100,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we move the assert to #assertVariant() as well?


// Assert the variant mutations
userAssert(
isArray(variant['mutations']),
Copy link
Contributor

Choose a reason for hiding this comment

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

what will be included in the mutations? Is it still required if it is an empty array?

Copy link
Contributor

Choose a reason for hiding this comment

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

check the length of the array as well


for (const name in experiments) {
if (experiments[name]) {
const variantObject = config[name]['variants'][experiments[name]];
Copy link
Contributor

Choose a reason for hiding this comment

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

sigh.. 馃懣

@torch2424
Copy link
Contributor Author

@zhouyx I have a few questions about the comments you made, so I'll go ahead and wait till Monday, and make all the fixes at once 馃槃 No worries if you are not in the office Monday, as I could ask them later in the review 馃憤

@torch2424
Copy link
Contributor Author

@zhouyx Also, when you finish the review, feel free to mention me here so I get the github notification 馃槀

@torch2424
Copy link
Contributor Author

@zhouyx Made all requested changes, and fixed/added appropriate tests 馃槃

Please give this another review once you get the chance!

@@ -49,18 +50,34 @@ export class AmpExperiment extends AMP.BaseElement {
/** @private @const {!Promise<!Object<string, ?string>>} */
const experimentVariants = Promise.all(variants)
.then(() => results)
.then(this.addToBody_.bind(this));
.then(this.applyExperimentVariants_.bind(this, 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 found this.applyExperimentVariants requires two params? Did I miss anything

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline, this does do two :)

* @return {!Promise<!Object<string, ?string>>} a promise of the original
* param passed in
* @private
*/
addToBody_(experiments) {
applyExperimentVariants_(config, experimentToVariant) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need experimentToVariant? I think config contains all the information.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add comment here on experimentToVariant

throw e;
}
});
}

/** @return {!JsonObject} [description] */
/**
* The experiment config can be represented as:
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!!!

// and apply mutations
// Placehodler to pass linting for code review
// and keep PRs small
body.setAttribute(experimentName, JSON.stringify(variantObject));
Copy link
Contributor

Choose a reason for hiding this comment

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

We were using ATTR_PREFIX, could you let me know why we decide to skid the prefix? It sounds very dangerous as we won't have control of the experiment name.

Copy link
Contributor

Choose a reason for hiding this comment

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

And could you explain a bit why are we setting the value to JSON.stringify(variantObject)? Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline, make a better NOOP.

@@ -143,12 +149,8 @@ describes.realWin('amp-experiment', {
'experiment-2': 'variant-d',
'experiment-3': null,
});
expectBodyHasAttributes({
Copy link
Contributor

Choose a reason for hiding this comment

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

do we still want to test the attributes appended to body?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope we dont, the body thing was just a NOOP for linting

@torch2424
Copy link
Contributor Author

@zhouyx Made requested changes / replied to comments! 馃帀

This is good to go 馃槃

@zhouyx
Copy link
Contributor

zhouyx commented Mar 29, 2019

Look great! Thank you for the change 馃帀

@torch2424
Copy link
Contributor Author

@zhouyx Yay! Thanks for the review! 馃槃 Merging...

@torch2424 torch2424 merged commit 782fffd into ampproject:master Apr 1, 2019
@torch2424 torch2424 deleted the amp-experiment-config-fixed branch April 1, 2019 17:43
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

3 participants