Skip to content

Commit

Permalink
add empty secondary exposures to GCIR with local override (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenny-statsig authored May 22, 2024
1 parent 8285fec commit 5c91260
Showing 1 changed file with 30 additions and 36 deletions.
66 changes: 30 additions & 36 deletions evaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,8 @@ func (e *evaluator) evalGate(user User, gateName string) *evalResult {
}

func (e *evaluator) evalGateImpl(user User, gateName string, depth int) *evalResult {
if gateOverride, hasOverride := e.getGateOverride(gateName); hasOverride {
evalDetails := e.createEvaluationDetails(reasonLocalOverride)
return &evalResult{
Value: gateOverride,
RuleID: "override",
EvaluationDetails: evalDetails,
SecondaryExposures: make([]map[string]string, 0),
}
if gateOverrideEval, hasOverride := e.getGateOverrideEval(gateName); hasOverride {
return gateOverrideEval
}
if gate, hasGate := e.store.getGate(gateName); hasGate {
return e.eval(user, gate, depth)
Expand All @@ -150,15 +144,8 @@ func (e *evaluator) evalConfig(user User, configName string, persistedValues Use
}

func (e *evaluator) evalConfigImpl(user User, configName string, persistedValues UserPersistedValues, depth int) *evalResult {
if configOverride, hasOverride := e.getConfigOverride(configName); hasOverride {
evalDetails := e.createEvaluationDetails(reasonLocalOverride)
return &evalResult{
Value: true,
JsonValue: configOverride,
RuleID: "override",
EvaluationDetails: evalDetails,
SecondaryExposures: make([]map[string]string, 0),
}
if configOverrideEval, hasOverride := e.getConfigOverrideEval(configName); hasOverride {
return configOverrideEval
}
config, hasConfig := e.store.getDynamicConfig(configName)
if !hasConfig {
Expand All @@ -185,15 +172,8 @@ func (e *evaluator) evalLayer(user User, name string, persistedValues UserPersis
}

func (e *evaluator) evalLayerImpl(user User, name string, persistedValues UserPersistedValues, depth int) *evalResult {
if layerOverride, hasOverride := e.getLayerOverride(name); hasOverride {
evalDetails := e.createEvaluationDetails(reasonLocalOverride)
return &evalResult{
Value: true,
JsonValue: layerOverride,
RuleID: "override",
EvaluationDetails: evalDetails,
SecondaryExposures: make([]map[string]string, 0),
}
if layerOverrideEval, hasOverride := e.getLayerOverrideEval(name); hasOverride {
return layerOverrideEval
}
config, hasConfig := e.store.getLayerConfig(name)
if !hasConfig {
Expand Down Expand Up @@ -253,14 +233,13 @@ func (e *evaluator) getGateOverride(name string) (bool, bool) {
}

func (e *evaluator) getGateOverrideEval(name string) (*evalResult, bool) {
e.mu.RLock()
defer e.mu.RUnlock()
if gateOverride, hasOverride := e.getGateOverride(name); hasOverride {
evalDetails := e.createEvaluationDetails(reasonLocalOverride)
return &evalResult{
Value: gateOverride,
RuleID: "override",
EvaluationDetails: evalDetails,
Value: gateOverride,
RuleID: "override",
EvaluationDetails: evalDetails,
SecondaryExposures: make([]map[string]string, 0),
}, true
}

Expand All @@ -275,14 +254,14 @@ func (e *evaluator) getConfigOverride(name string) (map[string]interface{}, bool
}

func (e *evaluator) getConfigOverrideEval(name string) (*evalResult, bool) {
e.mu.RLock()
defer e.mu.RUnlock()
if configOverride, hasOverride := e.getConfigOverride(name); hasOverride {
evalDetails := e.createEvaluationDetails(reasonLocalOverride)
return &evalResult{
JsonValue: configOverride,
RuleID: "override",
EvaluationDetails: evalDetails,
Value: true,
JsonValue: configOverride,
RuleID: "override",
EvaluationDetails: evalDetails,
SecondaryExposures: make([]map[string]string, 0),
}, true
}

Expand All @@ -296,6 +275,21 @@ func (e *evaluator) getLayerOverride(name string) (map[string]interface{}, bool)
return layer, ok
}

func (e *evaluator) getLayerOverrideEval(name string) (*evalResult, bool) {
if layerOverride, hasOverride := e.getLayerOverride(name); hasOverride {
evalDetails := e.createEvaluationDetails(reasonLocalOverride)
return &evalResult{
Value: true,
JsonValue: layerOverride,
RuleID: "override",
EvaluationDetails: evalDetails,
SecondaryExposures: make([]map[string]string, 0),
}, true
}

return &evalResult{}, false
}

// Override the value of a Feature Gate for the given user
func (e *evaluator) OverrideGate(gate string, val bool) {
e.mu.Lock()
Expand Down

0 comments on commit 5c91260

Please sign in to comment.