Skip to content

Commit 2ccc18f

Browse files
authored
1 parent 8411239 commit 2ccc18f

File tree

3 files changed

+38
-22
lines changed

3 files changed

+38
-22
lines changed

evaluator.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type evalResult struct {
3030
ForwardAllExposures bool `json:"forward_all_exposures,omitempty"`
3131
SamplingRate *int `json:"sampling_rate,omitempty"`
3232
ConfigVersion *int `json:"config_version,omitempty"`
33+
HasSeenAnalyticalGates bool `json:"has_seen_analytical_gates,omitempty"`
3334
}
3435

3536
type DerivedDeviceMetadata struct {
@@ -375,6 +376,7 @@ func (e *evaluator) eval(user User, spec configSpec, depth int, context *evalCon
375376
var deviceMetadata *DerivedDeviceMetadata
376377
if spec.Enabled {
377378
for _, rule := range spec.Rules {
379+
context.EvalSamplingRate = rule.SamplingRate
378380
r := e.evalRule(user, rule, depth+1, context)
379381
if r.Unsupported {
380382
r.EvaluationDetails = e.createEvaluationDetails(ReasonUnsupported)
@@ -405,22 +407,24 @@ func (e *evaluator) eval(user User, spec configSpec, depth int, context *evalCon
405407
DerivedDeviceMetadata: deviceMetadata,
406408
SamplingRate: rule.SamplingRate,
407409
ConfigVersion: spec.ConfigVersion,
410+
HasSeenAnalyticalGates: context.EvalHasSeenAnalyticalGates,
408411
}
409412
if rule.IsExperimentGroup != nil {
410413
result.IsExperimentGroup = rule.IsExperimentGroup
411414
}
412415
return result
413416
} else {
414417
return &evalResult{
415-
Value: pass,
416-
RuleID: rule.ID,
417-
IDType: spec.IDType,
418-
GroupName: rule.GroupName,
419-
SecondaryExposures: exposures,
420-
EvaluationDetails: evalDetails,
421-
DerivedDeviceMetadata: deviceMetadata,
422-
SamplingRate: rule.SamplingRate,
423-
ConfigVersion: spec.ConfigVersion,
418+
Value: pass,
419+
RuleID: rule.ID,
420+
IDType: spec.IDType,
421+
GroupName: rule.GroupName,
422+
SecondaryExposures: exposures,
423+
EvaluationDetails: evalDetails,
424+
DerivedDeviceMetadata: deviceMetadata,
425+
SamplingRate: rule.SamplingRate,
426+
ConfigVersion: spec.ConfigVersion,
427+
HasSeenAnalyticalGates: context.EvalHasSeenAnalyticalGates,
424428
}
425429
}
426430
}
@@ -440,10 +444,12 @@ func (e *evaluator) eval(user User, spec configSpec, depth int, context *evalCon
440444
EvaluationDetails: evalDetails,
441445
DerivedDeviceMetadata: deviceMetadata,
442446
ConfigVersion: spec.ConfigVersion,
447+
HasSeenAnalyticalGates: context.EvalHasSeenAnalyticalGates,
443448
}
444449
}
445450
return &evalResult{Value: false, RuleID: defaultRuleID, IDType: spec.IDType,
446-
SecondaryExposures: exposures, DerivedDeviceMetadata: deviceMetadata, ConfigVersion: spec.ConfigVersion}
451+
SecondaryExposures: exposures, DerivedDeviceMetadata: deviceMetadata, ConfigVersion: spec.ConfigVersion, HasSeenAnalyticalGates: context.EvalHasSeenAnalyticalGates,
452+
}
447453
}
448454

449455
func (e *evaluator) evalDelegate(user User, rule configRule, exposures []SecondaryExposure, depth int, context *evalContext) *evalResult {
@@ -539,6 +545,10 @@ func (e *evaluator) evalCondition(user User, cond configCondition, depth int, co
539545
allExposures = append(result.SecondaryExposures, newExposure)
540546
}
541547

548+
if context.EvalSamplingRate == nil && !strings.HasPrefix(dependentGateName, "segment:") {
549+
context.EvalHasSeenAnalyticalGates = true
550+
}
551+
542552
if strings.EqualFold(condType, "pass_gate") {
543553
return &evalResult{Value: result.Value, SecondaryExposures: allExposures, DerivedDeviceMetadata: result.DerivedDeviceMetadata}
544554
} else {

logger.go

+4
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ func (l *logger) determineSampling(entityType EntityType,
403403
return true, nil, nil, samplingMode
404404
}
405405

406+
if result.HasSeenAnalyticalGates {
407+
return true, nil, nil, samplingMode
408+
}
409+
406410
samplingSetKey := fmt.Sprintf("%s_%s", name, result.RuleID)
407411
if !l.samplingKeySet.Contains(samplingSetKey) {
408412
l.samplingKeySet.Add(samplingSetKey)

statsig_context.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ type errorContext struct {
1414
}
1515

1616
type evalContext struct {
17-
Caller string `json:"tag,omitempty"`
18-
ConfigName string `json:"configName,omitempty"`
19-
ClientKey string `json:"clientKey,omitempty"`
20-
Hash string `json:"hash,omitempty"`
21-
TargetAppID string
22-
IncludeLocalOverrides bool
23-
IsManualExposure bool
24-
IsExperiment bool
25-
DisableLogExposures bool
26-
PersistedValues UserPersistedValues
27-
IncludeConfigType bool
28-
ConfigTypesToInclude []ConfigType
17+
Caller string `json:"tag,omitempty"`
18+
ConfigName string `json:"configName,omitempty"`
19+
ClientKey string `json:"clientKey,omitempty"`
20+
Hash string `json:"hash,omitempty"`
21+
TargetAppID string
22+
IncludeLocalOverrides bool
23+
IsManualExposure bool
24+
IsExperiment bool
25+
DisableLogExposures bool
26+
PersistedValues UserPersistedValues
27+
IncludeConfigType bool
28+
ConfigTypesToInclude []ConfigType
29+
EvalSamplingRate *int
30+
EvalHasSeenAnalyticalGates bool
2931
}
3032

3133
type initContext struct {

0 commit comments

Comments
 (0)