Skip to content

Commit

Permalink
add forced decision and whitelist decision
Browse files Browse the repository at this point in the history
Signed-off-by: pulak-opti <[email protected]>
  • Loading branch information
pulak-opti committed Oct 24, 2024
1 parent 8d9cfe4 commit 1e7d272
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
26 changes: 23 additions & 3 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,33 @@ func (o *OptimizelyClient) findRegularDecision(decisionContext decision.FeatureD
}

featureDecision := decision.FeatureDecision{}
reasons := decide.NewDecisionReasons(options)
if decisionContext.Feature != nil {
for _, featureExperiment := range decisionContext.Feature.FeatureExperiments {
decisionKey := decision.NewUserDecisionKey(featureExperiment.ID)

if featureExperiment.Variations == nil {
continue
experimentDecisionContext := decision.ExperimentDecisionContext{
ProjectConfig: decisionContext.ProjectConfig,
Experiment: &featureExperiment,
}

expDecision, reasons, err := decision.NewExperimentWhitelistService().GetDecision(experimentDecisionContext, userContext, options)
if err == nil && expDecision.Variation != nil {
featureDecision.Variation = expDecision.Variation
featureDecision.Experiment = featureExperiment
featureDecision.Source = decision.FeatureTest
return featureDecision, reasons, nil
}

if decisionContext.ForcedDecisionService != nil {
forcedDecision, _reasons, err := decisionContext.ForcedDecisionService.FindValidatedForcedDecision(decisionContext.ProjectConfig, decision.OptimizelyDecisionContext{FlagKey: decisionContext.Feature.Key, RuleKey: featureExperiment.Key}, options)
reasons.Append(_reasons)
if err == nil {
return decision.FeatureDecision{
Experiment: featureExperiment,
Variation: forcedDecision,
Source: decision.FeatureTest,
}, reasons, nil
}
}

if savedVariationID, ok := userProfile.ExperimentBucketMap[decisionKey]; ok {
Expand Down
5 changes: 4 additions & 1 deletion pkg/client/optimizely_user_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ func (o *OptimizelyUserContext) DecideAll(options []decide.OptimizelyDecideOptio
func (o *OptimizelyUserContext) DecideForKeys(keys []string, options []decide.OptimizelyDecideOptions) map[string]OptimizelyDecision {
// use a copy of the user context so that any changes to the original context are not reflected inside the decision
userContextCopy := newOptimizelyUserContext(o.GetOptimizely(), o.GetUserID(), o.GetUserAttributes(), o.getForcedDecisionService(), o.GetQualifiedSegments())
return o.optimizely.decideForKeys(userContextCopy, keys, convertDecideOptions(options))
decideOptions := convertDecideOptions(options)
decisionMap := o.optimizely.decideForKeys(userContextCopy, keys, decideOptions)

return filteredDecision(decisionMap, o.optimizely.getAllOptions(decideOptions).EnabledFlagsOnly)
}

// TrackEvent generates a conversion event with the given event key if it exists and queues it up to be sent to the Optimizely
Expand Down

0 comments on commit 1e7d272

Please sign in to comment.