-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(relay-proxy): Add the possibility to specify in the evaluation c…
…ontext which flag to evaluate in bulk evaluation flags (#2171)
- Loading branch information
1 parent
74dbfe5
commit ea9cbe2
Showing
24 changed files
with
839 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
cmd/relayproxy/testdata/controller/all_flags/valid_request_specify_flags.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"user": { | ||
"key": "a20b1cd5-7165-4e02-a279-c0c8b90a8912", | ||
"anonymous": false, | ||
"custom": { | ||
"custom1": "value1", | ||
"custom2": "value2", | ||
"gofeatureflag":{ | ||
"flagList":["array-flag", "flag-only-for-admin"] | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
cmd/relayproxy/testdata/controller/all_flags/valid_response_specify_flags.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"flags": { | ||
"array-flag": { | ||
"value": [ | ||
"batmanDefault", | ||
"supermanDefault", | ||
"superherosDefault" | ||
], | ||
"timestamp": 1652273630, | ||
"variationType": "Default", | ||
"trackEvents": true, | ||
"errorCode": "", | ||
"reason": "DEFAULT" | ||
}, | ||
"flag-only-for-admin": { | ||
"value": false, | ||
"timestamp": 1652273630, | ||
"variationType": "Default", | ||
"trackEvents": true, | ||
"errorCode": "", | ||
"reason": "DEFAULT" | ||
} | ||
}, | ||
"valid": true | ||
} |
20 changes: 20 additions & 0 deletions
20
cmd/relayproxy/testdata/ofrep/responses/valid_response_specify_flags.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"flags": [ | ||
{ | ||
"key": "array-flag", | ||
"value": [ | ||
"batmanDefault", | ||
"supermanDefault", | ||
"superherosDefault" | ||
], | ||
"reason": "DEFAULT", | ||
"variant": "Default" | ||
}, | ||
{ | ||
"key": "flag-only-for-admin", | ||
"value": false, | ||
"reason": "DEFAULT", | ||
"variant": "Default" | ||
} | ||
] | ||
} |
11 changes: 11 additions & 0 deletions
11
cmd/relayproxy/testdata/ofrep/valid_request_specify_flags.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"context": { | ||
"company": "GO Feature Flag", | ||
"firstname": "John", | ||
"lastname": "Doe", | ||
"targetingKey": "4f433951-4c8c-42b3-9f18-8c9a5ed8e9eb", | ||
"gofeatureflag": { | ||
"flagList": ["array-flag", "flag-only-for-admin"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package ffcontext | ||
|
||
import "time" | ||
|
||
type GoffContextSpecifics struct { | ||
// CurrentDateTime is the current date time to use for the evaluation. | ||
CurrentDateTime *time.Time `json:"currentDateTime"` | ||
// FlagList is the list of flags to evaluate in a bulk evaluation. | ||
FlagList []string `json:"flagList"` | ||
} | ||
|
||
// addCurrentDateTime adds the current date time to the context. | ||
// This function formats the current date time to RFC3339 format. | ||
func (g *GoffContextSpecifics) addCurrentDateTime(currentDateTime any) { | ||
switch value := currentDateTime.(type) { | ||
case *time.Time: | ||
g.CurrentDateTime = value | ||
case time.Time: | ||
g.CurrentDateTime = &value | ||
case string: | ||
if currentDateTime, err := time.ParseInLocation(time.RFC3339, value, time.Local); err == nil { | ||
g.CurrentDateTime = ¤tDateTime | ||
} | ||
return | ||
default: | ||
return | ||
} | ||
} | ||
|
||
// addListFlags adds the list of flags to evaluate in a bulk evaluation. | ||
func (g *GoffContextSpecifics) addListFlags(flagList any) { | ||
if value, ok := flagList.([]string); ok { | ||
g.FlagList = value | ||
} | ||
if value, ok := flagList.([]interface{}); ok { | ||
for _, val := range value { | ||
if valAsString, ok := val.(string); ok { | ||
g.FlagList = append(g.FlagList, valAsString) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.