Skip to content

Commit

Permalink
fix(OFREP): keep targetingKey in the custom data to continue to have …
Browse files Browse the repository at this point in the history
…rules enabled (#1905)

* keep targetingKey in the custom data to continue to have rules enabled

Signed-off-by: Thomas Poignant <[email protected]>

* Fix tests

Signed-off-by: Thomas Poignant <[email protected]>

---------

Signed-off-by: Thomas Poignant <[email protected]>
  • Loading branch information
thomaspoignant committed Aug 16, 2024
1 parent 945b19b commit 8c05258
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
1 change: 0 additions & 1 deletion cmd/relayproxy/ofrep/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ func assertOFREPEvaluateRequest(ofrepEvalReq *model.OFREPEvalFlagRequest) *model

func evaluationContextFromOFREPRequest(ctx map[string]any) (ffcontext.Context, error) {
if targetingKey, ok := ctx["targetingKey"].(string); ok {
delete(ctx, "targetingKey")
evalCtx := utils.ConvertEvaluationCtxFromRequest(targetingKey, ctx)
return evalCtx, nil
}
Expand Down
12 changes: 12 additions & 0 deletions cmd/relayproxy/ofrep/evaluate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ func Test_Evaluate(t *testing.T) {
bodyFile: "../testdata/ofrep/responses/not_found.json",
},
},
{
name: "targeting using the field targetingKey in the rules",
args: args{
bodyFile: "../testdata/ofrep/valid_targeting_key_query_request.json",
configFlagsLocation: configFlagsLocation,
flagKey: "targeting-key-rule",
},
want: want{
httpCode: http.StatusOK,
bodyFile: "../testdata/ofrep/responses/valid_targeting_key_query_response.json",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@
"trackEvents": true,
"errorCode": "",
"reason": "DEFAULT"
},
"targeting-key-rule": {
"value": false,
"timestamp": 1652273630,
"variationType": "false_var",
"trackEvents": true,
"errorCode": "",
"reason": "DEFAULT"
}
},
"valid": true
Expand Down
10 changes: 10 additions & 0 deletions cmd/relayproxy/testdata/controller/config_flags.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,13 @@ array-flag:
- batmanFalse
- supermanFalse
- superherosFalse

targeting-key-rule:
variations:
true_var: true
false_var: false
targeting:
- query: targetingKey eq "specific-targeting-key"
variation: true_var
defaultRule:
variation: false_var
8 changes: 7 additions & 1 deletion cmd/relayproxy/testdata/ofrep/responses/valid_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
"reason": "DEFAULT",
"variant": "Default"
},
{
"key": "targeting-key-rule",
"value": false,
"reason": "DEFAULT",
"variant": "false_var"
},
{
"key": "test-flag-rule-apply",
"value": {
Expand All @@ -59,4 +65,4 @@
"variant": "Default"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"key": "targeting-key-rule",
"value": true,
"reason": "TARGETING_MATCH",
"variant": "true_var"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"context": {
"company": "GO Feature Flag",
"firstname": "John",
"lastname": "Doe",
"targetingKey": "specific-targeting-key"
}
}

0 comments on commit 8c05258

Please sign in to comment.