Skip to content

Commit e6d50d6

Browse files
committed
Introducing mutex support
1 parent 90b15a6 commit e6d50d6

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

optimizely/decision/bucketer/experiment_bucketer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func (b MurmurhashBucketer) Bucket(bucketingID string, experiment entities.Exper
5656
bucketKey := bucketingID + group.ID
5757
bucketedExperimentID := b.bucketToEntity(bucketKey, group.TrafficAllocation)
5858
if bucketedExperimentID == "" || bucketedExperimentID != experiment.ID {
59-
// User is not bucketed into an experiment in the exclusion group, return nil variation
60-
return nil, reasons.NotInGroup, nil
59+
// User is not bucketed into provided experiment in mutex group
60+
return nil, reasons.NotBucketedIntoVariation, nil
6161
}
6262
}
6363

optimizely/decision/composite_feature_service.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,30 +46,32 @@ func (f CompositeFeatureService) GetDecision(decisionContext FeatureDecisionCont
4646

4747
// Check if user is bucketed in feature experiment
4848
if f.featureExperimentService != nil && len(feature.FeatureExperiments) > 0 {
49-
// @TODO: add in a feature decision service that takes into account multiple experiments (via group mutex)
50-
experiment := feature.FeatureExperiments[0]
51-
experimentDecisionContext := ExperimentDecisionContext{
52-
Experiment: &experiment,
53-
ProjectConfig: decisionContext.ProjectConfig,
54-
}
55-
56-
experimentDecision, err := f.featureExperimentService.GetDecision(experimentDecisionContext, userContext)
57-
// Variation not nil means we got a decision and should return it
58-
if experimentDecision.Variation != nil {
59-
featureDecision := FeatureDecision{
60-
Experiment: experiment,
61-
Decision: experimentDecision.Decision,
62-
Variation: experimentDecision.Variation,
63-
Source: FeatureTest,
49+
// @TODO this can be improved by getting group ID first and determining experiment ID and then bucketing in experiment ID
50+
for idx := 0; idx < len(feature.FeatureExperiments); idx++ {
51+
experiment := feature.FeatureExperiments[idx]
52+
experimentDecisionContext := ExperimentDecisionContext{
53+
Experiment: &experiment,
54+
ProjectConfig: decisionContext.ProjectConfig,
6455
}
6556

66-
cfLogger.Debug(fmt.Sprintf(
67-
`Decision made for feature test with key "%s" for user "%s" with the following reason: "%s".`,
68-
feature.Key,
69-
userContext.ID,
70-
featureDecision.Reason,
71-
))
72-
return featureDecision, err
57+
experimentDecision, err := f.featureExperimentService.GetDecision(experimentDecisionContext, userContext)
58+
// Variation not nil means we got a decision and should return it
59+
if experimentDecision.Variation != nil {
60+
featureDecision := FeatureDecision{
61+
Experiment: experiment,
62+
Decision: experimentDecision.Decision,
63+
Variation: experimentDecision.Variation,
64+
Source: FeatureTest,
65+
}
66+
67+
cfLogger.Debug(fmt.Sprintf(
68+
`Decision made for feature test with key "%s" for user "%s" with the following reason: "%s".`,
69+
feature.Key,
70+
userContext.ID,
71+
featureDecision.Reason,
72+
))
73+
return featureDecision, err
74+
}
7375
}
7476
}
7577

0 commit comments

Comments
 (0)