Skip to content

Commit 75ccfc9

Browse files
temirlantemirlan
authored andcommitted
add eval context to model Results
1 parent 67341a8 commit 75ccfc9

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

integration_tests/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ networks:
77

88
services:
99
mysql:
10+
platform: linux/x86_64
1011
image: mysql:5.6
1112
container_name: flagr-mysql
1213
environment:

integration_tests/test.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ step_11_test_tag_batch_evaluation() {
349349
matches "\"flagID\":1"
350350
matches "\"variantKey\":\"key_1\""
351351
matches "\"variantID\":1"
352+
matches "\"evalContext\""
353+
contains "flagTags"
352354

353355
}
354356

@@ -361,12 +363,16 @@ step_12_test_tag_operator_batch_evaluation() {
361363
matches "\"flagID\":1"
362364
matches "\"variantKey\":\"key_1\""
363365
matches "\"variantID\":1"
366+
matches "\"evalContext\""
367+
contains "flagTags"
364368

365369
shakedown POST "$flagr_url"/evaluation/batch -H 'Content-Type:application/json' -d '{"entities":[{ "entityType": "externalalert", "entityContext": {"property_1": "value_2"} }],"flagTags": ["value_1", "value_3"], "flagTagsOperator": "ANY", "enableDebug": false }'
366370
status 200
367371
matches "\"flagID\":1"
368372
matches "\"variantKey\":\"key_1\""
369373
matches "\"variantID\":1"
374+
matches "\"evalContext\""
375+
contains "flagTags"
370376

371377
}
372378

pkg/handler/eval.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,27 @@ func (e *eval) PostEvaluationBatch(params evaluation.PostEvaluationBatchParams)
7171
}
7272
for _, flagID := range flagIDs {
7373
evalContext := models.EvalContext{
74-
EnableDebug: params.Body.EnableDebug,
75-
EntityContext: entity.EntityContext,
76-
EntityID: entity.EntityID,
77-
EntityType: entity.EntityType,
78-
FlagID: flagID,
74+
EnableDebug: params.Body.EnableDebug,
75+
EntityContext: entity.EntityContext,
76+
EntityID: entity.EntityID,
77+
EntityType: entity.EntityType,
78+
FlagID: flagID,
79+
FlagTags: flagTags,
80+
FlagTagsOperator: flagTagsOperator,
7981
}
8082

8183
evalResult := EvalFlag(evalContext)
8284
results.EvaluationResults = append(results.EvaluationResults, evalResult)
8385
}
8486
for _, flagKey := range flagKeys {
8587
evalContext := models.EvalContext{
86-
EnableDebug: params.Body.EnableDebug,
87-
EntityContext: entity.EntityContext,
88-
EntityID: entity.EntityID,
89-
EntityType: entity.EntityType,
90-
FlagKey: flagKey,
88+
EnableDebug: params.Body.EnableDebug,
89+
EntityContext: entity.EntityContext,
90+
EntityID: entity.EntityID,
91+
EntityType: entity.EntityType,
92+
FlagKey: flagKey,
93+
FlagTags: flagTags,
94+
FlagTagsOperator: flagTagsOperator,
9195
}
9296

9397
evalResult := EvalFlag(evalContext)
@@ -195,6 +199,7 @@ var EvalFlagWithContext = func(flag *entity.Flag, evalContext models.EvalContext
195199
evalResult.EvalDebugLog.SegmentDebugLogs = logs
196200
evalResult.SegmentID = sID
197201
evalResult.VariantID = vID
202+
198203
v := flag.FlagEvaluation.VariantsMap[util.SafeUint(vID)]
199204
if v != nil {
200205
evalResult.VariantAttachment = v.Attachment

pkg/handler/eval_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ func TestPostEvaluation(t *testing.T) {
488488
EntityID: "entityID1",
489489
EntityType: "entityType1",
490490
FlagID: int64(100),
491+
FlagTags: []string{"tag1", "tag2"},
491492
},
492493
})
493494
assert.NotNil(t, resp)

0 commit comments

Comments
 (0)