Skip to content

Commit 733ab59

Browse files
authored
feat: add support for implicit identity key construction (#184)
- Update engine-test-data to v3.1.0 for new test cases - Construct identity key as environment_key + "_" + identifier when not provided - Fix weight formatting in SPLIT reason to preserve decimal places (use %g instead of %.0f)
1 parent 26db339 commit 733ab59

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

flagengine/engine-test-data

Submodule engine-test-data updated 156 files

flagengine/engine.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@ func getFlagResults(ec *engine_eval.EngineEvaluationContext, featureOverrides ma
8888
// Get identity key if identity exists
8989
var identityKey *string
9090
if ec.Identity != nil {
91-
identityKey = &ec.Identity.Key
91+
// If identity key is not provided, construct it from environment key and identifier
92+
if ec.Identity.Key == "" {
93+
constructedKey := ec.Environment.Key + "_" + ec.Identity.Identifier
94+
identityKey = &constructedKey
95+
} else {
96+
identityKey = &ec.Identity.Key
97+
}
9298
}
9399

94100
if ec.Features != nil {
@@ -147,7 +153,7 @@ func getFlagResultFromFeatureContext(featureName string, featureContext *engine_
147153
cumulativeWeight += variant.Weight
148154
if hashPercentage <= cumulativeWeight {
149155
value = variant.Value
150-
reason = fmt.Sprintf("SPLIT; weight=%.0f", variant.Weight)
156+
reason = fmt.Sprintf("SPLIT; weight=%g", variant.Weight)
151157
break
152158
}
153159
}

0 commit comments

Comments
 (0)