Skip to content

Commit 491c6a9

Browse files
su5kktemirlan
andauthored
include flagTags in postEvaluation and postEvaluationBatch (#623)
* add flag tags to models Result * reset eval_test * add correct flagTags checking to eval_test --------- Co-authored-by: temirlan <timtursunov@temirlans-MacBook-Pro.local>
1 parent 1e7b27c commit 491c6a9

File tree

8 files changed

+51
-0
lines changed

8 files changed

+51
-0
lines changed

docs/api_docs/bundle.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,12 @@ definitions:
13531353
flagSnapshotID:
13541354
type: integer
13551355
format: int64
1356+
flagTags:
1357+
description: flagTags. flagTags looks up flags by tag. Either works.
1358+
type: array
1359+
x-omitempty: true
1360+
items:
1361+
type: string
13561362
segmentID:
13571363
type: integer
13581364
format: int64

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ step_11_test_tag_batch_evaluation() {
349349
matches "\"flagID\":1"
350350
matches "\"variantKey\":\"key_1\""
351351
matches "\"variantID\":1"
352+
contains "flagTags"
352353

353354
}
354355

@@ -361,12 +362,14 @@ step_12_test_tag_operator_batch_evaluation() {
361362
matches "\"flagID\":1"
362363
matches "\"variantKey\":\"key_1\""
363364
matches "\"variantID\":1"
365+
contains "flagTags"
364366

365367
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 }'
366368
status 200
367369
matches "\"flagID\":1"
368370
matches "\"variantKey\":\"key_1\""
369371
matches "\"variantID\":1"
372+
contains "flagTags"
370373

371374
}
372375

pkg/handler/eval.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,16 @@ func BlankResult(f *entity.Flag, evalContext models.EvalContext, msg string) *mo
105105
flagID := uint(0)
106106
flagKey := ""
107107
flagSnapshotID := uint(0)
108+
flagTags := []string{}
108109
if f != nil {
109110
flagID = f.ID
110111
flagSnapshotID = f.SnapshotID
111112
flagKey = f.Key
113+
if len(f.Tags) > 0 {
114+
for _, tag := range f.Tags {
115+
flagTags = append(flagTags, tag.Value)
116+
}
117+
}
112118
}
113119
return &models.EvalResult{
114120
EvalContext: &evalContext,
@@ -119,6 +125,7 @@ func BlankResult(f *entity.Flag, evalContext models.EvalContext, msg string) *mo
119125
FlagID: int64(flagID),
120126
FlagKey: flagKey,
121127
FlagSnapshotID: int64(flagSnapshotID),
128+
FlagTags: flagTags,
122129
Timestamp: util.TimeNow(),
123130
}
124131
}

pkg/handler/eval_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ func TestEvalFlag(t *testing.T) {
167167
})
168168
assert.NotNil(t, result)
169169
assert.NotZero(t, result.VariantID)
170+
assert.NotEmpty(t, result.FlagTags)
171+
assert.Len(t, result.FlagTags, 2)
172+
assert.Contains(t, result.FlagTags, "tag1")
173+
assert.Contains(t, result.FlagTags, "tag2")
170174
})
171175

172176
t.Run("test happy code path with flagKey", func(t *testing.T) {
@@ -467,6 +471,10 @@ func TestEvalFlagsByTags(t *testing.T) {
467471
})
468472
assert.NotZero(t, len(results))
469473
assert.NotZero(t, results[0].VariantID)
474+
assert.NotEmpty(t, results[0].FlagTags)
475+
assert.Len(t, results[0].FlagTags, 2)
476+
assert.Contains(t, results[0].FlagTags, "tag1")
477+
assert.Contains(t, results[0].FlagTags, "tag2")
470478
})
471479
}
472480

@@ -515,6 +523,7 @@ func TestPostEvaluationBatch(t *testing.T) {
515523
assert.NotNil(t, resp)
516524
})
517525
}
526+
518527
func TestTagsPostEvaluationBatch(t *testing.T) {
519528
t.Run("test happy code path", func(t *testing.T) {
520529
defer gostub.StubFunc(&EvalFlag, &models.EvalResult{}).Reset()

swagger/index.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,12 @@ definitions:
481481
flagSnapshotID:
482482
type: integer
483483
format: int64
484+
flagTags:
485+
description: flagTags. flagTags looks up flags by tag. Either works.
486+
type: array
487+
x-omitempty: true
488+
items:
489+
type: string
484490
segmentID:
485491
type: integer
486492
format: int64

swagger_gen/models/eval_result.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger_gen/restapi/embedded_spec.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)