Skip to content

Commit 83623fb

Browse files
remove unused examples
Signed-off-by: Thomas Poignant <[email protected]>
1 parent c77b08f commit 83623fb

16 files changed

+266
-388
lines changed

cmd/relayproxy/controller/all_flags_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ func Test_all_flag_Handler_DefaultMode(t *testing.T) {
6565
},
6666
},
6767
{
68-
name: "No user key in payload",
68+
name: "No user key in payload - should now pass and evaluate flags individually",
6969
args: args{
7070
bodyFile: "../testdata/controller/all_flags/no_user_key_request.json",
7171
configFlagsLocation: configFlagsLocation,
7272
},
7373
want: want{
74-
handlerErr: true,
75-
errorMsg: "empty key for evaluation context, impossible to retrieve flags",
76-
errorCode: http.StatusBadRequest,
74+
handlerErr: false, // No longer fails at API validation level
75+
httpCode: http.StatusOK,
76+
bodyFile: "../testdata/controller/all_flags/no_user_key_response_updated.json",
7777
},
7878
},
7979
{
@@ -194,15 +194,15 @@ func Test_all_flag_Handler_FlagsetMode(t *testing.T) {
194194
},
195195
},
196196
{
197-
name: "No user key in payload",
197+
name: "No user key in payload - should now pass and evaluate flags individually",
198198
args: args{
199199
bodyFile: "../testdata/controller/all_flags/no_user_key_request.json",
200200
configFlagsLocation: configFlagsLocation,
201201
},
202202
want: want{
203-
handlerErr: true,
204-
errorMsg: "empty key for evaluation context, impossible to retrieve flags",
205-
errorCode: http.StatusBadRequest,
203+
handlerErr: false, // No longer fails at API validation level
204+
httpCode: http.StatusOK,
205+
bodyFile: "../testdata/controller/all_flags/no_user_key_response_updated.json",
206206
},
207207
},
208208
{

cmd/relayproxy/controller/utils.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ func assertRequest(u *model.AllFlagRequest) *echo.HTTPError {
2727
}
2828

2929
// assertContextKey is checking that the user key is valid, if not an echo.HTTPError is return.
30+
// Note: Empty keys are now allowed - the core evaluation logic will determine if a targeting key
31+
// is required based on whether the flag needs bucketing (percentage-based rules, progressive rollouts).
3032
func assertContextKey(key string) *echo.HTTPError {
31-
if len(key) == 0 {
32-
return &echo.HTTPError{
33-
Code: http.StatusBadRequest,
34-
Message: "empty key for evaluation context, impossible to retrieve flags",
35-
}
36-
}
33+
// No validation needed - let core evaluation logic handle targeting key requirements
3734
return nil
3835
}
3936

cmd/relayproxy/controller/utils_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ func Test_assertRequest(t *testing.T) {
4040
"assertRequest: impossible to find user in request"),
4141
},
4242
{
43-
name: "user with User and EvaluationContext, empty key for evaluation context",
43+
name: "user with User and EvaluationContext, empty key for evaluation context should now pass",
4444
req: &model.AllFlagRequest{
4545
User: &model.UserRequest{Key: "my-key"},
4646
EvaluationContext: &model.EvaluationContextRequest{Key: ""},
4747
},
48-
wantErr: echo.NewHTTPError(
49-
http.StatusBadRequest,
50-
"empty key for evaluation context, impossible to retrieve flags"),
48+
wantErr: nil, // Empty keys are now allowed at API layer
5149
},
5250
{
5351
name: "invalid user but valid evaluation context should pass",

cmd/relayproxy/ofrep/evaluate.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,23 @@ func (h *EvaluateCtrl) BulkEvaluate(c echo.Context) error {
227227
func assertOFREPEvaluateRequest(
228228
ofrepEvalReq *model.OFREPEvalFlagRequest,
229229
) *model.OFREPCommonResponseError {
230-
if ofrepEvalReq.Context == nil || ofrepEvalReq.Context["targetingKey"] == "" {
231-
return NewOFREPCommonError(flag.ErrorCodeTargetingKeyMissing,
232-
"GO Feature Flag MUST have a targeting key in the request.")
230+
// Note: Empty targeting keys are now allowed - the core evaluation logic will determine
231+
// if a targeting key is required based on whether the flag needs bucketing.
232+
if ofrepEvalReq.Context == nil {
233+
return NewOFREPCommonError(flag.ErrorCodeInvalidContext,
234+
"GO Feature Flag requires an evaluation context in the request.")
233235
}
234236
return nil
235237
}
236238

237239
func evaluationContextFromOFREPRequest(ctx map[string]any) (ffcontext.Context, error) {
238-
if targetingKey, ok := ctx["targetingKey"].(string); ok {
239-
evalCtx := utils.ConvertEvaluationCtxFromRequest(targetingKey, ctx)
240-
return evalCtx, nil
240+
// Allow empty or missing targeting keys - core evaluation logic will handle requirements
241+
targetingKey := ""
242+
if key, ok := ctx["targetingKey"].(string); ok {
243+
targetingKey = key
241244
}
242-
return ffcontext.EvaluationContext{}, NewOFREPCommonError(
243-
flag.ErrorCodeTargetingKeyMissing,
244-
"GO Feature Flag has received no targetingKey or a none string value that is not a string.")
245+
246+
// Create evaluation context (empty targeting key is allowed)
247+
evalCtx := utils.ConvertEvaluationCtxFromRequest(targetingKey, ctx)
248+
return evalCtx, nil
245249
}

cmd/relayproxy/ofrep/evaluate_test.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ func Test_Bulk_Evaluation(t *testing.T) {
8080
},
8181
want: want{
8282
httpCode: http.StatusBadRequest,
83-
bodyFile: "../testdata/ofrep/responses/nil_context.json",
83+
bodyFile: "../testdata/ofrep/responses/nil_context_updated.json",
8484
},
8585
},
8686
{
87-
name: "No Targeting Key in context",
87+
name: "No Targeting Key in context - should now pass and evaluate flags individually",
8888
args: args{
8989
bodyFile: "../testdata/ofrep/no_targeting_key_context.json",
9090
configFlagsLocation: configFlagsLocation,
9191
},
9292
want: want{
93-
httpCode: http.StatusBadRequest,
94-
bodyFile: "../testdata/ofrep/responses/no_targeting_key_context.json",
93+
httpCode: http.StatusOK,
94+
bodyFile: "../testdata/ofrep/responses/no_targeting_key_context_updated.json",
9595
},
9696
},
9797
}
@@ -205,19 +205,43 @@ func Test_Evaluate(t *testing.T) {
205205
},
206206
want: want{
207207
httpCode: http.StatusBadRequest,
208-
bodyFile: "../testdata/ofrep/responses/nil_context_with_key.json",
208+
bodyFile: "../testdata/ofrep/responses/nil_context_with_key_updated.json",
209209
},
210210
},
211211
{
212-
name: "No Targeting Key in context",
212+
name: "No Targeting Key for bucketing-required flag - should return 400 from core evaluation",
213213
args: args{
214214
bodyFile: "../testdata/ofrep/no_targeting_key_context.json",
215215
configFlagsLocation: configFlagsLocation,
216-
flagKey: "number-flag",
216+
flagKey: "number-flag", // This flag has percentage rules, requires bucketing
217217
},
218218
want: want{
219219
httpCode: http.StatusBadRequest,
220-
bodyFile: "../testdata/ofrep/responses/no_targeting_key_context_with_key.json",
220+
bodyFile: "../testdata/ofrep/responses/no_targeting_key_bucketing_flag.json",
221+
},
222+
},
223+
{
224+
name: "No Targeting Key for non-bucketing flag - should succeed",
225+
args: args{
226+
bodyFile: "../testdata/ofrep/no_targeting_key_context.json",
227+
configFlagsLocation: configFlagsLocation,
228+
flagKey: "targeting-key-rule", // This flag has no percentages, doesn't require bucketing
229+
},
230+
want: want{
231+
httpCode: http.StatusOK,
232+
bodyFile: "../testdata/ofrep/responses/no_targeting_key_static_flag.json",
233+
},
234+
},
235+
{
236+
name: "Percentage-based flag without targeting key should return 400 error",
237+
args: args{
238+
bodyFile: "../testdata/ofrep/no_targeting_key_context.json",
239+
configFlagsLocation: configFlagsLocation,
240+
flagKey: "flag-only-for-admin", // This flag has percentage rules, requires bucketing
241+
},
242+
want: want{
243+
httpCode: http.StatusBadRequest, // Core evaluation returns 400 for missing targeting key
244+
bodyFile: "../testdata/ofrep/responses/percentage_flag_no_key_error.json",
221245
},
222246
},
223247
{
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"flags": {
3+
"array-flag": {
4+
"value": null,
5+
"timestamp": 1652273630,
6+
"variationType": "",
7+
"trackEvents": true,
8+
"errorCode": "TARGETING_KEY_MISSING",
9+
"errorDetails": "Error: Empty targeting key",
10+
"reason": "ERROR"
11+
},
12+
"disable-flag": {
13+
"value": null,
14+
"timestamp": 1652273630,
15+
"variationType": "",
16+
"trackEvents": true,
17+
"errorCode": "TARGETING_KEY_MISSING",
18+
"errorDetails": "Error: Empty targeting key",
19+
"reason": "ERROR"
20+
},
21+
"flag-only-for-admin": {
22+
"value": null,
23+
"timestamp": 1652273630,
24+
"variationType": "",
25+
"trackEvents": true,
26+
"errorCode": "TARGETING_KEY_MISSING",
27+
"errorDetails": "Error: Empty targeting key",
28+
"reason": "ERROR"
29+
},
30+
"new-admin-access": {
31+
"value": null,
32+
"timestamp": 1652273630,
33+
"variationType": "",
34+
"trackEvents": true,
35+
"errorCode": "TARGETING_KEY_MISSING",
36+
"errorDetails": "Error: Empty targeting key",
37+
"reason": "ERROR"
38+
},
39+
"number-flag": {
40+
"value": null,
41+
"timestamp": 1652273630,
42+
"variationType": "",
43+
"trackEvents": true,
44+
"errorCode": "TARGETING_KEY_MISSING",
45+
"errorDetails": "Error: Empty targeting key",
46+
"reason": "ERROR"
47+
},
48+
"targeting-key-rule": {
49+
"value": false,
50+
"timestamp": 1652273630,
51+
"variationType": "false_var",
52+
"trackEvents": true,
53+
"errorCode": "",
54+
"reason": "DEFAULT"
55+
},
56+
"test-flag-rule-apply": {
57+
"value": null,
58+
"timestamp": 1652273630,
59+
"variationType": "",
60+
"trackEvents": true,
61+
"errorCode": "TARGETING_KEY_MISSING",
62+
"errorDetails": "Error: Empty targeting key",
63+
"reason": "ERROR"
64+
},
65+
"test-flag-rule-apply-false": {
66+
"value": null,
67+
"timestamp": 1652273630,
68+
"variationType": "",
69+
"trackEvents": true,
70+
"errorCode": "TARGETING_KEY_MISSING",
71+
"errorDetails": "Error: Empty targeting key",
72+
"reason": "ERROR"
73+
},
74+
"test-flag-rule-not-apply": {
75+
"value": null,
76+
"timestamp": 1652273630,
77+
"variationType": "",
78+
"trackEvents": true,
79+
"errorCode": "TARGETING_KEY_MISSING",
80+
"errorDetails": "Error: Empty targeting key",
81+
"reason": "ERROR"
82+
}
83+
},
84+
"valid": false
85+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"errorCode": "INVALID_CONTEXT",
3+
"errorDetails": "GO Feature Flag requires an evaluation context in the request."
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"errorCode": "INVALID_CONTEXT",
3+
"errorDetails": "GO Feature Flag requires an evaluation context in the request.",
4+
"key": "number-flag"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"errorCode": "TARGETING_KEY_MISSING",
3+
"errorDetails": "Error while evaluating the flag: number-flag",
4+
"key": "number-flag"
5+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"flags": [
3+
{
4+
"key": "array-flag",
5+
"value": null,
6+
"reason": "ERROR",
7+
"variant": "",
8+
"errorCode": "TARGETING_KEY_MISSING",
9+
"errorDetails": "Error: Empty targeting key"
10+
},
11+
{
12+
"key": "disable-flag",
13+
"value": null,
14+
"reason": "ERROR",
15+
"variant": "",
16+
"errorCode": "TARGETING_KEY_MISSING",
17+
"errorDetails": "Error: Empty targeting key"
18+
},
19+
{
20+
"key": "flag-only-for-admin",
21+
"value": null,
22+
"reason": "ERROR",
23+
"variant": "",
24+
"errorCode": "TARGETING_KEY_MISSING",
25+
"errorDetails": "Error: Empty targeting key"
26+
},
27+
{
28+
"key": "new-admin-access",
29+
"value": null,
30+
"reason": "ERROR",
31+
"variant": "",
32+
"errorCode": "TARGETING_KEY_MISSING",
33+
"errorDetails": "Error: Empty targeting key"
34+
},
35+
{
36+
"key": "number-flag",
37+
"value": null,
38+
"reason": "ERROR",
39+
"variant": "",
40+
"errorCode": "TARGETING_KEY_MISSING",
41+
"errorDetails": "Error: Empty targeting key"
42+
},
43+
{
44+
"key": "targeting-key-rule",
45+
"value": false,
46+
"reason": "DEFAULT",
47+
"variant": "false_var"
48+
},
49+
{
50+
"key": "test-flag-rule-apply",
51+
"value": null,
52+
"reason": "ERROR",
53+
"variant": "",
54+
"errorCode": "TARGETING_KEY_MISSING",
55+
"errorDetails": "Error: Empty targeting key"
56+
},
57+
{
58+
"key": "test-flag-rule-apply-false",
59+
"value": null,
60+
"reason": "ERROR",
61+
"variant": "",
62+
"errorCode": "TARGETING_KEY_MISSING",
63+
"errorDetails": "Error: Empty targeting key"
64+
},
65+
{
66+
"key": "test-flag-rule-not-apply",
67+
"value": null,
68+
"reason": "ERROR",
69+
"variant": "",
70+
"errorCode": "TARGETING_KEY_MISSING",
71+
"errorDetails": "Error: Empty targeting key"
72+
}
73+
]
74+
}

0 commit comments

Comments
 (0)