Skip to content

Commit

Permalink
add IsEveryoneElseVariation field
Browse files Browse the repository at this point in the history
  • Loading branch information
pulak-opti committed Aug 20, 2024
1 parent e152edb commit 8855f52
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 31 deletions.
4 changes: 3 additions & 1 deletion pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ func (o *OptimizelyClient) decide(userContext OptimizelyUserContext, key string,
}
}

return NewOptimizelyDecision(variationKey, ruleKey, key, flagEnabled, optimizelyJSON, userContext, reasonsToReport)
decision := NewOptimizelyDecision(variationKey, ruleKey, key, flagEnabled, optimizelyJSON, userContext, reasonsToReport)
decision.IsEveryoneElseVariation = featureDecision.Experiment.IsEveryoneElseVariation
return decision
}

func (o *OptimizelyClient) decideForKeys(userContext OptimizelyUserContext, keys []string, options *decide.Options) map[string]OptimizelyDecision {
Expand Down
15 changes: 8 additions & 7 deletions pkg/client/optimizely_decision.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ import (

// OptimizelyDecision defines the decision returned by decide api.
type OptimizelyDecision struct {
VariationKey string `json:"variationKey"`
Enabled bool `json:"enabled"`
Variables *optimizelyjson.OptimizelyJSON `json:"-"`
RuleKey string `json:"ruleKey"`
FlagKey string `json:"flagKey"`
UserContext OptimizelyUserContext `json:"userContext"`
Reasons []string `json:"reasons"`
VariationKey string `json:"variationKey"`
Enabled bool `json:"enabled"`
Variables *optimizelyjson.OptimizelyJSON `json:"-"`
RuleKey string `json:"ruleKey"`
FlagKey string `json:"flagKey"`
UserContext OptimizelyUserContext `json:"userContext"`
Reasons []string `json:"reasons"`
IsEveryoneElseVariation bool `json:"isEveryoneElseVariation"`
}

// NewOptimizelyDecision creates and returns a new instance of OptimizelyDecision
Expand Down
27 changes: 16 additions & 11 deletions pkg/config/datafileprojectconfig/mappers/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package mappers

import (
"strings"

datafileEntities "github.com/optimizely/go-sdk/v2/pkg/config/datafileprojectconfig/entities"
"github.com/optimizely/go-sdk/v2/pkg/entities"
)
Expand Down Expand Up @@ -79,18 +81,21 @@ func mapExperiment(rawExperiment datafileEntities.Experiment) entities.Experimen
func() {}() // cheat the linters
}

_, defaultRolloutsPrefixFound := strings.CutPrefix(rawExperiment.Key, "default-rollout-")

experiment := entities.Experiment{
AudienceIds: rawExperiment.AudienceIds,
AudienceConditions: rawExperiment.AudienceConditions,
ID: rawExperiment.ID,
LayerID: rawExperiment.LayerID,
Key: rawExperiment.Key,
Variations: make(map[string]entities.Variation),
VariationKeyToIDMap: make(map[string]string),
TrafficAllocation: make([]entities.Range, len(rawExperiment.TrafficAllocation)),
AudienceConditionTree: audienceConditionTree,
Whitelist: rawExperiment.ForcedVariations,
IsFeatureExperiment: false,
AudienceIds: rawExperiment.AudienceIds,
AudienceConditions: rawExperiment.AudienceConditions,
ID: rawExperiment.ID,
LayerID: rawExperiment.LayerID,
Key: rawExperiment.Key,
Variations: make(map[string]entities.Variation),
VariationKeyToIDMap: make(map[string]string),
TrafficAllocation: make([]entities.Range, len(rawExperiment.TrafficAllocation)),
AudienceConditionTree: audienceConditionTree,
Whitelist: rawExperiment.ForcedVariations,
IsFeatureExperiment: false,
IsEveryoneElseVariation: rawExperiment.ID == rawExperiment.Key && defaultRolloutsPrefixFound,
}

for _, variation := range rawExperiment.Variations {
Expand Down
25 changes: 13 additions & 12 deletions pkg/entities/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ type Variation struct {

// Experiment represents an experiment
type Experiment struct {
AudienceIds []string
AudienceConditions interface{}
ID string
LayerID string
Key string
Variations map[string]Variation // keyed by variation ID
VariationKeyToIDMap map[string]string
TrafficAllocation []Range
GroupID string
AudienceConditionTree *TreeNode
Whitelist map[string]string
IsFeatureExperiment bool
AudienceIds []string
AudienceConditions interface{}
ID string
LayerID string
Key string
Variations map[string]Variation // keyed by variation ID
VariationKeyToIDMap map[string]string
TrafficAllocation []Range
GroupID string
AudienceConditionTree *TreeNode
Whitelist map[string]string
IsFeatureExperiment bool
IsEveryoneElseVariation bool
}

// Range represents bucketing range that the specify entityID falls into
Expand Down

0 comments on commit 8855f52

Please sign in to comment.