Skip to content

Commit

Permalink
Send the good reason if flag is disabled (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspoignant authored Jul 19, 2022
1 parent 6e9af48 commit 885ea49
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ test-flag5:
false: 1.2
default: 1.3
trackEvents: false
test-flag6:
percentage: 100
true: 1.1
false: 1.2
default: 1.3
trackEvents: false
disable: true
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
"trackEvents": false,
"reason":"TARGETING_MATCH",
"errorCode": ""
},
"test-flag6": {
"value": null,
"timestamp": 1622206239,
"variationType": "",
"trackEvents": false,
"reason":"DISABLED",
"errorCode": ""
}
},
"valid": true
Expand Down
23 changes: 18 additions & 5 deletions variation.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,33 @@ func (g *GoFeatureFlag) AllFlagsState(user ffuser.User) flagstate.AllFlags {

allFlags := flagstate.NewAllFlags()
for key, currentFlag := range flags {
flagValue, varType := currentFlag.Value(key, user, flag.EvaluationContext{
flagValue, resolutionDetails := currentFlag.Value(key, user, flag.EvaluationContext{
Environment: g.config.Environment,
DefaultSdkValue: nil,
})

// if the flag is disabled we are ignoring it.
if resolutionDetails.Reason == flag.ReasonDisabled {
allFlags.AddFlag(key, flagstate.FlagState{
Timestamp: time.Now().Unix(),
TrackEvents: currentFlag.GetTrackEvents(),
Failed: resolutionDetails.ErrorCode != "",
ErrorCode: resolutionDetails.ErrorCode,
Reason: resolutionDetails.Reason,
})
continue
}

switch v := flagValue; v.(type) {
case int, float64, bool, string, []interface{}, map[string]interface{}:
allFlags.AddFlag(key, flagstate.FlagState{
Value: v,
Timestamp: time.Now().Unix(),
VariationType: varType.Variant,
VariationType: resolutionDetails.Variant,
TrackEvents: currentFlag.GetTrackEvents(),
Failed: varType.ErrorCode != "",
ErrorCode: varType.ErrorCode,
Reason: varType.Reason,
Failed: resolutionDetails.ErrorCode != "",
ErrorCode: resolutionDetails.ErrorCode,
Reason: resolutionDetails.Reason,
})

default:
Expand Down

0 comments on commit 885ea49

Please sign in to comment.