Skip to content

Commit 637027c

Browse files
temirlantemirlan
authored andcommitted
add flag tags to models Result
1 parent 67341a8 commit 637027c

File tree

8 files changed

+55
-10
lines changed

8 files changed

+55
-10
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: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,25 @@ 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+
FlagTagsOperator: flagTagsOperator,
7980
}
8081

8182
evalResult := EvalFlag(evalContext)
8283
results.EvaluationResults = append(results.EvaluationResults, evalResult)
8384
}
8485
for _, flagKey := range flagKeys {
8586
evalContext := models.EvalContext{
86-
EnableDebug: params.Body.EnableDebug,
87-
EntityContext: entity.EntityContext,
88-
EntityID: entity.EntityID,
89-
EntityType: entity.EntityType,
90-
FlagKey: flagKey,
87+
EnableDebug: params.Body.EnableDebug,
88+
EntityContext: entity.EntityContext,
89+
EntityID: entity.EntityID,
90+
EntityType: entity.EntityType,
91+
FlagKey: flagKey,
92+
FlagTagsOperator: flagTagsOperator,
9193
}
9294

9395
evalResult := EvalFlag(evalContext)
@@ -105,10 +107,16 @@ func BlankResult(f *entity.Flag, evalContext models.EvalContext, msg string) *mo
105107
flagID := uint(0)
106108
flagKey := ""
107109
flagSnapshotID := uint(0)
110+
flagTags := []string{}
108111
if f != nil {
109112
flagID = f.ID
110113
flagSnapshotID = f.SnapshotID
111114
flagKey = f.Key
115+
if len(f.Tags) > 0 {
116+
for _, tag := range f.Tags {
117+
flagTags = append(flagTags, tag.Value)
118+
}
119+
}
112120
}
113121
return &models.EvalResult{
114122
EvalContext: &evalContext,
@@ -119,6 +127,7 @@ func BlankResult(f *entity.Flag, evalContext models.EvalContext, msg string) *mo
119127
FlagID: int64(flagID),
120128
FlagKey: flagKey,
121129
FlagSnapshotID: int64(flagSnapshotID),
130+
FlagTags: flagTags,
122131
Timestamp: util.TimeNow(),
123132
}
124133
}

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)

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)