Skip to content

Commit 8370f42

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

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

integration_tests/test.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,20 @@ step_7_test_evaluation() {
269269
matches "\"variantID\":1"
270270
matches "\"flagID\":1"
271271
matches "\"segmentID\":1"
272+
matches "\"evalContext\""
273+
matches "\"entityID\":\"abc1234\""
274+
matches "\"entityType\":\"candidate\""
275+
contains "\"entityContext\":{\"property_1\":\"value_2\"}"
272276

273277
shakedown POST "$flagr_url"/evaluation -H 'Content-Type:application/json' -d '{"entityID": "abc1234", "entityType": "candidate", "flagID": 1}'
274278
status 200
275279
matches "\"variantKey\":\"key_2\""
276280
matches "\"variantID\":2"
277281
matches "\"flagID\":1"
278282
matches "\"segmentID\":2"
283+
matches "\"evalContext\""
284+
matches "\"entityID\":\"abc1234\""
285+
matches "\"entityType\":\"candidate\""
279286
}
280287

281288
step_8_test_preload() {
@@ -349,6 +356,10 @@ step_11_test_tag_batch_evaluation() {
349356
matches "\"flagID\":1"
350357
matches "\"variantKey\":\"key_1\""
351358
matches "\"variantID\":1"
359+
matches "\"evalContext\""
360+
matches "\"entityType\":\"externalalert\""
361+
contains "\"entityContext\":{\"property_1\":\"value_2\"}"
362+
contains "\"flagTags\":\[\"value_1\"\]"
352363

353364
}
354365

@@ -361,12 +372,22 @@ step_12_test_tag_operator_batch_evaluation() {
361372
matches "\"flagID\":1"
362373
matches "\"variantKey\":\"key_1\""
363374
matches "\"variantID\":1"
375+
matches "\"evalContext\""
376+
matches "\"entityType\":\"externalalert\""
377+
contains "\"entityContext\":{\"property_1\":\"value_2\"}"
378+
contains "\"flagTags\":\[\"value_1\",\"value_2\"\]"
379+
matches "\"flagTagsOperator\":\"ALL\""
364380

365381
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 }'
366382
status 200
367383
matches "\"flagID\":1"
368384
matches "\"variantKey\":\"key_1\""
369385
matches "\"variantID\":1"
386+
matches "\"evalContext\""
387+
matches "\"entityType\":\"externalalert\""
388+
contains "\"entityContext\":{\"property_1\":\"value_2\"}"
389+
contains "\"flagTags\":\[\"value_1\",\"value_3\"\]"
390+
matches "\"flagTagsOperator\":\"ANY\""
370391

371392
}
372393

pkg/handler/eval.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ var EvalFlagWithContext = func(flag *entity.Flag, evalContext models.EvalContext
195195
evalResult.EvalDebugLog.SegmentDebugLogs = logs
196196
evalResult.SegmentID = sID
197197
evalResult.VariantID = vID
198+
evalResult.EvalContext = &evalContext
199+
198200
v := flag.FlagEvaluation.VariantsMap[util.SafeUint(vID)]
199201
if v != nil {
200202
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)