Skip to content

Commit 37de97c

Browse files
Merge pull request #106 from optimizely/ali/feat_test
Moving experiment evaluation from CompositeFeatureService to FeatureExperimentService
2 parents fb212ce + 8df0a47 commit 37de97c

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

optimizely/decision/composite_feature_service.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ var cfLogger = logging.GetLogger("CompositeFeatureService")
2828

2929
// CompositeFeatureService is the default out-of-the-box feature decision service
3030
type CompositeFeatureService struct {
31-
experimentDecisionService ExperimentService
32-
rolloutDecisionService FeatureService
31+
featureExperimentService ExperimentService
32+
rolloutDecisionService FeatureService
3333
}
3434

3535
// NewCompositeFeatureService returns a new instance of the CompositeFeatureService
3636
func NewCompositeFeatureService() *CompositeFeatureService {
3737
return &CompositeFeatureService{
38-
experimentDecisionService: NewCompositeExperimentService(),
39-
rolloutDecisionService: NewRolloutService(),
38+
featureExperimentService: NewFeatureExperimentService(),
39+
rolloutDecisionService: NewRolloutService(),
4040
}
4141
}
4242

@@ -45,15 +45,15 @@ func (f CompositeFeatureService) GetDecision(decisionContext FeatureDecisionCont
4545
feature := decisionContext.Feature
4646

4747
// Check if user is bucketed in feature experiment
48-
if f.experimentDecisionService != nil && len(feature.FeatureExperiments) > 0 {
48+
if f.featureExperimentService != nil && len(feature.FeatureExperiments) > 0 {
4949
// @TODO: add in a feature decision service that takes into account multiple experiments (via group mutex)
5050
experiment := feature.FeatureExperiments[0]
5151
experimentDecisionContext := ExperimentDecisionContext{
5252
Experiment: &experiment,
5353
ProjectConfig: decisionContext.ProjectConfig,
5454
}
5555

56-
experimentDecision, err := f.experimentDecisionService.GetDecision(experimentDecisionContext, userContext)
56+
experimentDecision, err := f.featureExperimentService.GetDecision(experimentDecisionContext, userContext)
5757
// Variation not nil means we got a decision and should return it
5858
if experimentDecision.Variation != nil {
5959
featureDecision := FeatureDecision{
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/****************************************************************************
2+
* Copyright 2019, Optimizely, Inc. and contributors *
3+
* *
4+
* Licensed under the Apache License, Version 2.0 (the "License"); *
5+
* you may not use this file except in compliance with the License. *
6+
* You may obtain a copy of the License at *
7+
* *
8+
* http://www.apache.org/licenses/LICENSE-2.0 *
9+
* *
10+
* Unless required by applicable law or agreed to in writing, software *
11+
* distributed under the License is distributed on an "AS IS" BASIS, *
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13+
* See the License for the specific language governing permissions and *
14+
* limitations under the License. *
15+
***************************************************************************/
16+
17+
// Package decision //
18+
package decision
19+
20+
import (
21+
"github.com/optimizely/go-sdk/optimizely/entities"
22+
)
23+
24+
// FeatureExperimentService helps evaluate feature test associated with the feature
25+
type FeatureExperimentService struct {
26+
featureExperimentService ExperimentService
27+
}
28+
29+
// NewFeatureExperimentService returns a new instance of the FeatureExperimentService
30+
func NewFeatureExperimentService() *CompositeExperimentService {
31+
return NewCompositeExperimentService()
32+
}
33+
34+
// GetDecision returns a decision for the given feature test and user context
35+
func (f FeatureExperimentService) GetDecision(decisionContext ExperimentDecisionContext, userContext entities.UserContext) (ExperimentDecision, error) {
36+
return f.featureExperimentService.GetDecision(decisionContext, userContext)
37+
}

0 commit comments

Comments
 (0)