Skip to content

Commit

Permalink
Merge branch 'master' into yasir/fix-null-bubbling
Browse files Browse the repository at this point in the history
  • Loading branch information
yasirfolio3 committed Nov 15, 2019
2 parents c01cc45 + 14b8686 commit d097353
Show file tree
Hide file tree
Showing 19 changed files with 437 additions and 118 deletions.
15 changes: 13 additions & 2 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
Changes that have landed but are not yet released. Changes that have landed but are not yet released.

## [1.0.0-beta6] - November 8th, 2019
## [1.0.0-beta7] - November 14th, 2019

## New Features
- feat: Method for removing forced variations [#176](https://github.com/optimizely/go-sdk/pull/176)

### Bug Fixes
- fix: Update built-in map-based ExperimentOverrideStore implementation to be concurrently usable [#171](https://github.com/optimizely/go-sdk/pull/171)
- fix: Add a public constructor for MapExperimentOverridesStore [#174](https://github.com/optimizely/go-sdk/pull/174)
- fix: don't return error when there is a good projectConfig in polling manager [#179](https://github.com/optimizely/go-sdk/pull/179)
- fix(decision): Logs produced by the various decision services. [#180](https://github.com/optimizely/go-sdk/pull/180)
- fix(exists-condition) Fixed exists comparison for leaf condition. [#185](https://github.com/optimizely/go-sdk/pull/185)

## [1.0.0-beta6] - November 8th, 2019

## New Features
- Experiment override service - implement groups
[#164](https://github.com/optimizely/go-sdk/pull/164)
- Add User profile service
- Add User profile service
[#163](https://github.com/optimizely/go-sdk/pull/163)

### Bug Fixes
Expand Down
25 changes: 16 additions & 9 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (o *OptimizelyClient) IsFeatureEnabled(featureKey string, userContext entit
}
}()

decisionContext, featureDecision, err := o.getFeatureDecision(featureKey, userContext)
decisionContext, featureDecision, err := o.getFeatureDecision(featureKey, "", userContext)
if err != nil {
logger.Error("received an error while computing feature decision", err)
return result, err
Expand Down Expand Up @@ -214,15 +214,12 @@ func (o *OptimizelyClient) GetFeatureVariableString(featureKey, variableKey stri
// GetFeatureVariable returns feature as a string along with it's associated type
func (o *OptimizelyClient) GetFeatureVariable(featureKey, variableKey string, userContext entities.UserContext) (value string, valueType entities.VariableType, err error) {

decisionContext, featureDecision, err := o.getFeatureDecision(featureKey, userContext)
featureDecisionContext, featureDecision, err := o.getFeatureDecision(featureKey, variableKey, userContext)
if err != nil {
return "", "", err
}

variable, err := decisionContext.ProjectConfig.GetVariableByKey(featureKey, variableKey)
if err != nil {
return "", "", err
}
variable := featureDecisionContext.Variable

if featureDecision.Variation != nil {
if v, ok := featureDecision.Variation.Variables[variable.ID]; ok && featureDecision.Variation.FeatureEnabled {
Expand All @@ -237,7 +234,7 @@ func (o *OptimizelyClient) GetFeatureVariable(featureKey, variableKey string, us
func (o *OptimizelyClient) GetAllFeatureVariables(featureKey string, userContext entities.UserContext) (enabled bool, variableMap map[string]string, err error) {

variableMap = make(map[string]string)
decisionContext, featureDecision, err := o.getFeatureDecision(featureKey, userContext)
decisionContext, featureDecision, err := o.getFeatureDecision(featureKey, "", userContext)
if err != nil {
logger.Error("Optimizely SDK tracking error", err)
return enabled, variableMap, err
Expand Down Expand Up @@ -335,7 +332,7 @@ func (o *OptimizelyClient) Track(eventKey string, userContext entities.UserConte
return nil
}

func (o *OptimizelyClient) getFeatureDecision(featureKey string, userContext entities.UserContext) (decisionContext decision.FeatureDecisionContext, featureDecision decision.FeatureDecision, err error) {
func (o *OptimizelyClient) getFeatureDecision(featureKey, variableKey string, userContext entities.UserContext) (decisionContext decision.FeatureDecisionContext, featureDecision decision.FeatureDecision, err error) {

defer func() {
if r := recover(); r != nil {
Expand Down Expand Up @@ -368,9 +365,19 @@ func (o *OptimizelyClient) getFeatureDecision(featureKey string, userContext ent
return decisionContext, featureDecision, nil
}

variable := entities.Variable{}
if variableKey != "" {
variable, err = projectConfig.GetVariableByKey(feature.Key, variableKey)
if err != nil {
logger.Warning(fmt.Sprintf(`Could not get variable for key "%s": %s`, variableKey, err))
return decisionContext, featureDecision, nil
}
}

decisionContext = decision.FeatureDecisionContext{
Feature: &feature,
ProjectConfig: projectConfig,
Variable: variable,
}

featureDecision, err = o.DecisionService.GetFeatureDecision(decisionContext, userContext)
Expand Down Expand Up @@ -414,7 +421,7 @@ func (o *OptimizelyClient) getExperimentDecision(experimentKey string, userConte
result := experimentDecision.Variation.Key
logger.Info(fmt.Sprintf(`User "%s" is bucketed into variation "%s" of experiment "%s".`, userContext.ID, result, experimentKey))
} else {
logger.Info(fmt.Sprintf(`User "%s" is not bucketed into any variation for experiment "%s".`, userContext.ID, experimentKey))
logger.Info(fmt.Sprintf(`User "%s" is not bucketed into any variation for experiment "%s": %s.`, userContext.ID, experimentKey, experimentDecision.Reason))
}

return decisionContext, experimentDecision, err
Expand Down

0 comments on commit d097353

Please sign in to comment.