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

fix: Checking variation in flagvariation map instead of checking it only in experiment #729

Merged
merged 5 commits into from
Dec 21, 2021

Conversation

mnoman09
Copy link
Contributor

@mnoman09 mnoman09 commented Dec 14, 2021

Summary

  • Checking variation in flagvariation map for forced decision

Test plan

@coveralls
Copy link

coveralls commented Dec 14, 2021

Coverage Status

Coverage increased (+0.02%) to 97.183% when pulling 6b0e0bb on mnoman/forceddecisionRefac into 1550705 on master.

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

Change looks good. We need a unit test covering the case.

Comment on lines +618 to +619
let variation = null;
variation = experiment.variationKeyMap[variationKey];
Copy link
Contributor

Choose a reason for hiding this comment

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

merge these

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 add unit test to catch the bug?

Copy link
Contributor

@msohailhussain msohailhussain left a comment

Choose a reason for hiding this comment

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

lgtm. please address jae's comments.

Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

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

There is an unusual pattern of passing in config from outside, which was introduced here which will make this findValidatedForcedDecision API unusable from outside. Please see if you can find a better way to do it or let me know, we can try to figure something out together

variationKey = forcedDecision.variationKey;
variation = this.optimizely.getFlagVariationByKey(flagKey, variationKey);
variation = getFlagVariationByKey(config, flagKey, variationKey);
Copy link
Contributor

@zashraf1985 zashraf1985 Dec 15, 2021

Choose a reason for hiding this comment

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

Why did this had to change? this looks like an unusual pattern to pass in config from outside.

* @param {string} flagKey A flagKey.
* @param {ruleKey} ruleKey A ruleKey (optional).
* @return {DecisionResponse<Variation|null>} DecisionResponse object containing valid variation object and decide reasons.
*/
findValidatedForcedDecision(
config: ProjectConfig,
Copy link
Contributor

@zashraf1985 zashraf1985 Dec 15, 2021

Choose a reason for hiding this comment

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

This looks like an unusual pattern. why do we need to pass in config from outside when we have access to optimizely instance.

Copy link
Contributor

Choose a reason for hiding this comment

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

optimizelyInstance.config may have different version if we try to access it from the optimizely instance. That's why the config we capture in the start of any API, we use it across all methods.

Comment on lines -1681 to -1694
getFlagVariationByKey(flagKey: string, variationKey: string): OptimizelyVariation | null {
const configObj = this.projectConfigManager.getConfig();
if (!configObj) {
return null;
}

const variations = configObj.flagVariationsMap[flagKey];
const result = find(variations, item => item.key === variationKey)
if (result) {
return result;
}

return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

why remove this and move to project_config and pass that in separately?

Copy link
Contributor

Choose a reason for hiding this comment

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

As per my understanding, project_config is used for mapping all datafile properties and their k/v mappings. Optimizely class is not for this purpose. I have not seen any single mapping in this class. That's why removed it and add it at proper location where you can see all other getter and setters.

Comment on lines +620 to +622
if (!variation) {
variation = getFlagVariationByKey(configObj, feature.key, variationKey);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As far as i understand, this was the only change needed here. i am unable to understand why were other changes made at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Secondly, optimizely_instance's access is not available in decide_service, that's why moved to project_config

Copy link
Contributor

@zashraf1985 zashraf1985 left a comment

Choose a reason for hiding this comment

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

Based on @msohailhussain 's explanation and based on the fact that we have done the same in other SDKs, i am approving this. But i have serious concerns in general on the cyclic dependencies we are creating in the SDKs. This is definitely going to come back and bite us later. We need to think about redesigning without these cyclic dependencies later.
@jaeopt @dustin-sier @The-inside-man

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

Question about a test case. Can you check?

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

LGTM

@msohailhussain msohailhussain merged commit 7d058bf into master Dec 21, 2021
@msohailhussain msohailhussain deleted the mnoman/forceddecisionRefac branch December 21, 2021 06:29
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.

None yet

6 participants