Skip to content

Commit 9a2477a

Browse files
authored
add id type to feature gate (#268)
kong statsig-io/kong#3459
1 parent 5e1b9b9 commit 9a2477a

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ type GetLayerOptions struct {
374374

375375
func (c *Client) checkGateImpl(user User, name string, context *evalContext) FeatureGate {
376376
if !c.verifyUser(user) {
377-
return *NewGate(name, false, "", "", nil)
377+
return *NewGate(name, false, "", "", "", nil)
378378
}
379379
user = normalizeUser(user, *c.options)
380380
res := c.evaluator.evalGate(user, name, context)
@@ -395,7 +395,7 @@ func (c *Client) checkGateImpl(user User, name string, context *evalContext) Fea
395395
c.options.EvaluationCallbacks.ExposureCallback(name, nil)
396396
}
397397
}
398-
return *NewGate(name, res.Value, res.RuleID, res.GroupName, res.EvaluationDetails)
398+
return *NewGate(name, res.Value, res.RuleID, res.GroupName, res.IDType, res.EvaluationDetails)
399399
}
400400

401401
func (c *Client) getConfigImpl(user User, name string, context *evalContext) DynamicConfig {

evaluator.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ import (
1616
type evalResult struct {
1717
Value bool `json:"value"`
1818
JsonValue map[string]interface{} `json:"json_value"`
19-
Unsupported bool `json:"unsupported"`
19+
Unsupported bool `json:"unsupported"`
2020
RuleID string `json:"rule_id"`
21+
IDType string `json:"id_type"`
2122
GroupName string `json:"group_name"`
2223
SecondaryExposures []SecondaryExposure `json:"secondary_exposures"`
2324
UndelegatedSecondaryExposures []SecondaryExposure `json:"undelegated_secondary_exposures"`
@@ -372,7 +373,6 @@ func (e *evaluator) eval(user User, spec configSpec, depth int, context *evalCon
372373
var exposures = make([]SecondaryExposure, 0)
373374
defaultRuleID := "default"
374375
var deviceMetadata *DerivedDeviceMetadata
375-
376376
if spec.Enabled {
377377
for _, rule := range spec.Rules {
378378
r := e.evalRule(user, rule, depth+1, context)
@@ -397,6 +397,7 @@ func (e *evaluator) eval(user User, spec configSpec, depth int, context *evalCon
397397
Value: pass,
398398
JsonValue: configValue,
399399
RuleID: rule.ID,
400+
IDType: spec.IDType,
400401
GroupName: rule.GroupName,
401402
SecondaryExposures: exposures,
402403
UndelegatedSecondaryExposures: exposures,
@@ -413,6 +414,7 @@ func (e *evaluator) eval(user User, spec configSpec, depth int, context *evalCon
413414
return &evalResult{
414415
Value: pass,
415416
RuleID: rule.ID,
417+
IDType: spec.IDType,
416418
GroupName: rule.GroupName,
417419
SecondaryExposures: exposures,
418420
EvaluationDetails: evalDetails,
@@ -432,14 +434,16 @@ func (e *evaluator) eval(user User, spec configSpec, depth int, context *evalCon
432434
Value: false,
433435
JsonValue: configValue,
434436
RuleID: defaultRuleID,
437+
IDType: spec.IDType,
435438
SecondaryExposures: exposures,
436439
UndelegatedSecondaryExposures: exposures,
437440
EvaluationDetails: evalDetails,
438441
DerivedDeviceMetadata: deviceMetadata,
439442
ConfigVersion: spec.ConfigVersion,
440443
}
441444
}
442-
return &evalResult{Value: false, RuleID: defaultRuleID, SecondaryExposures: exposures, DerivedDeviceMetadata: deviceMetadata, ConfigVersion: spec.ConfigVersion}
445+
return &evalResult{Value: false, RuleID: defaultRuleID, IDType: spec.IDType,
446+
SecondaryExposures: exposures, DerivedDeviceMetadata: deviceMetadata, ConfigVersion: spec.ConfigVersion}
443447
}
444448

445449
func (e *evaluator) evalDelegate(user User, rule configRule, exposures []SecondaryExposure, depth int, context *evalContext) *evalResult {
@@ -564,7 +568,7 @@ func (e *evaluator) evalCondition(user User, cond configCondition, depth int, co
564568
case strings.EqualFold(condType, "unit_id"):
565569
value = getUnitID(user, cond.IDType)
566570
case strings.EqualFold(condType, "target_app"):
567-
if (context.ClientKey != "") {
571+
if context.ClientKey != "" {
568572
value = context.TargetAppID
569573
} else {
570574
value = e.store.getAppID()

types.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type FeatureGate struct {
4646
Name string `json:"name"`
4747
Value bool `json:"value"`
4848
RuleID string `json:"rule_id"`
49+
IDType string `json:"id_type"`
4950
GroupName string `json:"group_name"`
5051
EvaluationDetails *EvaluationDetails `json:"evaluation_details"`
5152
}
@@ -61,11 +62,12 @@ type Layer struct {
6162
AllocatedExperimentName string `json:"allocated_experiment_name"`
6263
}
6364

64-
func NewGate(name string, value bool, ruleID string, groupName string, evaluationDetails *EvaluationDetails) *FeatureGate {
65+
func NewGate(name string, value bool, ruleID string, groupName string, idType string, evaluationDetails *EvaluationDetails) *FeatureGate {
6566
return &FeatureGate{
6667
Name: name,
6768
Value: value,
6869
RuleID: ruleID,
70+
IDType: idType,
6971
GroupName: groupName,
7072
EvaluationDetails: evaluationDetails,
7173
}

0 commit comments

Comments
 (0)