-
Notifications
You must be signed in to change notification settings - Fork 83
fix: Checking variation in flagvariation map instead of checking it only in experiment #729
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
Changes from all commits
3791c16
d7b2a9e
61a7969
3b87b7d
6b0e0bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ import { | |
getExperimentAudienceConditions, | ||
getExperimentFromId, | ||
getExperimentFromKey, | ||
getFlagVariationByKey, | ||
getTrafficAllocation, | ||
getVariationIdFromExperimentAndVariationKey, | ||
getVariationFromId, | ||
|
@@ -614,7 +615,11 @@ export class DecisionService { | |
decideReasons.push(...decisionVariation.reasons); | ||
variationKey = decisionVariation.result; | ||
if (variationKey) { | ||
const variation = experiment.variationKeyMap[variationKey]; | ||
let variation = null; | ||
variation = experiment.variationKeyMap[variationKey]; | ||
if (!variation) { | ||
variation = getFlagVariationByKey(configObj, feature.key, variationKey); | ||
} | ||
Comment on lines
+620
to
+622
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Secondly, |
||
variationForFeatureExperiment = { | ||
experiment: experiment, | ||
variation: variation, | ||
|
@@ -1016,7 +1021,7 @@ export class DecisionService { | |
const decideReasons: (string | number)[][] = []; | ||
|
||
// check forced decision first | ||
const forcedDecisionResponse = user.findValidatedForcedDecision(flagKey, rule.key); | ||
const forcedDecisionResponse = user.findValidatedForcedDecision(configObj, flagKey, rule.key); | ||
decideReasons.push(...forcedDecisionResponse.reasons); | ||
|
||
const forcedVariaton = forcedDecisionResponse.result; | ||
|
@@ -1048,7 +1053,7 @@ export class DecisionService { | |
|
||
// check forced decision first | ||
const rule = rules[ruleIndex]; | ||
const forcedDecisionResponse = user.findValidatedForcedDecision(flagKey, rule.key); | ||
const forcedDecisionResponse = user.findValidatedForcedDecision(configObj, flagKey, rule.key); | ||
decideReasons.push(...forcedDecisionResponse.reasons); | ||
|
||
const forcedVariaton = forcedDecisionResponse.result; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1481,7 +1481,7 @@ export default class Optimizely { | |
|
||
const allDecideOptions = this.getAllDecideOptions(options); | ||
|
||
const forcedDecisionResponse = user.findValidatedForcedDecision(key); | ||
const forcedDecisionResponse = user.findValidatedForcedDecision(configObj, key); | ||
reasons.push(...forcedDecisionResponse.reasons); | ||
const variation = forcedDecisionResponse.result; | ||
if (variation) { | ||
|
@@ -1672,24 +1672,4 @@ export default class Optimizely { | |
return this.decideForKeys(user, allFlagKeys, options); | ||
} | ||
|
||
/** | ||
* Returns flag variation for specified flagKey and variationKey | ||
* @param {flagKey} string | ||
* @param {variationKey} string | ||
* @return {OptimizelyVariation|null} | ||
*/ | ||
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; | ||
} | ||
Comment on lines
-1681
to
-1694
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why remove this and move to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per my understanding, |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,10 @@ import { | |
UserAttributes, | ||
Variation | ||
} from '../../lib/shared_types'; | ||
import { | ||
getFlagVariationByKey, | ||
ProjectConfig, | ||
} from '../core/project_config'; | ||
import { LOG_MESSAGES, CONTROL_ATTRIBUTES } from '../utils/enums'; | ||
|
||
const logger = getLogger(); | ||
|
@@ -211,22 +215,24 @@ export default class OptimizelyUserContext { | |
|
||
/** | ||
* Finds a validated forced decision for specific flagKey and optional ruleKey. | ||
* @param {ProjectConfig}config A projectConfig. | ||
* @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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
flagKey: string, | ||
ruleKey?: string | ||
ruleKey?: string, | ||
): DecisionResponse<Variation | null> { | ||
|
||
const decideReasons: (string | number)[][] = []; | ||
const forcedDecision = this.findForcedDecision({ flagKey, ruleKey }); | ||
let variation = null; | ||
let variationKey; | ||
if (forcedDecision) { | ||
if (config && forcedDecision) { | ||
variationKey = forcedDecision.variationKey; | ||
variation = this.optimizely.getFlagVariationByKey(flagKey, variationKey); | ||
variation = getFlagVariationByKey(config, flagKey, variationKey); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
if (variation) { | ||
if (ruleKey) { | ||
logger.info( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge these
There was a problem hiding this comment.
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?