Skip to content

Commit 885ea49

Browse files
Send the good reason if flag is disabled (#270)
1 parent 6e9af48 commit 885ea49

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

testdata/ffclient/all_flags/config_flag/flag-config-all-flags.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,10 @@ test-flag5:
3838
false: 1.2
3939
default: 1.3
4040
trackEvents: false
41+
test-flag6:
42+
percentage: 100
43+
true: 1.1
44+
false: 1.2
45+
default: 1.3
46+
trackEvents: false
47+
disable: true

testdata/ffclient/all_flags/marshal_json/valid_multiple_types.json

+8
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@
5252
"trackEvents": false,
5353
"reason":"TARGETING_MATCH",
5454
"errorCode": ""
55+
},
56+
"test-flag6": {
57+
"value": null,
58+
"timestamp": 1622206239,
59+
"variationType": "",
60+
"trackEvents": false,
61+
"reason":"DISABLED",
62+
"errorCode": ""
5563
}
5664
},
5765
"valid": true

variation.go

+18-5
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,33 @@ func (g *GoFeatureFlag) AllFlagsState(user ffuser.User) flagstate.AllFlags {
155155

156156
allFlags := flagstate.NewAllFlags()
157157
for key, currentFlag := range flags {
158-
flagValue, varType := currentFlag.Value(key, user, flag.EvaluationContext{
158+
flagValue, resolutionDetails := currentFlag.Value(key, user, flag.EvaluationContext{
159159
Environment: g.config.Environment,
160160
DefaultSdkValue: nil,
161161
})
162+
163+
// if the flag is disabled we are ignoring it.
164+
if resolutionDetails.Reason == flag.ReasonDisabled {
165+
allFlags.AddFlag(key, flagstate.FlagState{
166+
Timestamp: time.Now().Unix(),
167+
TrackEvents: currentFlag.GetTrackEvents(),
168+
Failed: resolutionDetails.ErrorCode != "",
169+
ErrorCode: resolutionDetails.ErrorCode,
170+
Reason: resolutionDetails.Reason,
171+
})
172+
continue
173+
}
174+
162175
switch v := flagValue; v.(type) {
163176
case int, float64, bool, string, []interface{}, map[string]interface{}:
164177
allFlags.AddFlag(key, flagstate.FlagState{
165178
Value: v,
166179
Timestamp: time.Now().Unix(),
167-
VariationType: varType.Variant,
180+
VariationType: resolutionDetails.Variant,
168181
TrackEvents: currentFlag.GetTrackEvents(),
169-
Failed: varType.ErrorCode != "",
170-
ErrorCode: varType.ErrorCode,
171-
Reason: varType.Reason,
182+
Failed: resolutionDetails.ErrorCode != "",
183+
ErrorCode: resolutionDetails.ErrorCode,
184+
Reason: resolutionDetails.Reason,
172185
})
173186

174187
default:

0 commit comments

Comments
 (0)