diff --git a/docs/api_docs/bundle.yaml b/docs/api_docs/bundle.yaml index afb7a808..c40ef6ef 100644 --- a/docs/api_docs/bundle.yaml +++ b/docs/api_docs/bundle.yaml @@ -1353,6 +1353,12 @@ definitions: flagSnapshotID: type: integer format: int64 + flagTags: + description: flagTags. flagTags looks up flags by tag. Either works. + type: array + x-omitempty: true + items: + type: string segmentID: type: integer format: int64 diff --git a/integration_tests/docker-compose.yml b/integration_tests/docker-compose.yml index 16f0ceca..0a476b4f 100644 --- a/integration_tests/docker-compose.yml +++ b/integration_tests/docker-compose.yml @@ -7,6 +7,7 @@ networks: services: mysql: + platform: linux/x86_64 image: mysql:5.6 container_name: flagr-mysql environment: diff --git a/integration_tests/test.sh b/integration_tests/test.sh index 006d7246..034a5dfc 100644 --- a/integration_tests/test.sh +++ b/integration_tests/test.sh @@ -349,6 +349,7 @@ step_11_test_tag_batch_evaluation() { matches "\"flagID\":1" matches "\"variantKey\":\"key_1\"" matches "\"variantID\":1" + contains "flagTags" } @@ -361,12 +362,14 @@ step_12_test_tag_operator_batch_evaluation() { matches "\"flagID\":1" matches "\"variantKey\":\"key_1\"" matches "\"variantID\":1" + contains "flagTags" 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 }' status 200 matches "\"flagID\":1" matches "\"variantKey\":\"key_1\"" matches "\"variantID\":1" + contains "flagTags" } diff --git a/pkg/handler/eval.go b/pkg/handler/eval.go index 18b0f6d1..99f7568c 100644 --- a/pkg/handler/eval.go +++ b/pkg/handler/eval.go @@ -105,10 +105,16 @@ func BlankResult(f *entity.Flag, evalContext models.EvalContext, msg string) *mo flagID := uint(0) flagKey := "" flagSnapshotID := uint(0) + flagTags := []string{} if f != nil { flagID = f.ID flagSnapshotID = f.SnapshotID flagKey = f.Key + if len(f.Tags) > 0 { + for _, tag := range f.Tags { + flagTags = append(flagTags, tag.Value) + } + } } return &models.EvalResult{ EvalContext: &evalContext, @@ -119,6 +125,7 @@ func BlankResult(f *entity.Flag, evalContext models.EvalContext, msg string) *mo FlagID: int64(flagID), FlagKey: flagKey, FlagSnapshotID: int64(flagSnapshotID), + FlagTags: flagTags, Timestamp: util.TimeNow(), } } diff --git a/pkg/handler/eval_test.go b/pkg/handler/eval_test.go index 0f26c5c9..3fb3002a 100644 --- a/pkg/handler/eval_test.go +++ b/pkg/handler/eval_test.go @@ -167,6 +167,10 @@ func TestEvalFlag(t *testing.T) { }) assert.NotNil(t, result) assert.NotZero(t, result.VariantID) + assert.NotEmpty(t, result.FlagTags) + assert.Len(t, result.FlagTags, 2) + assert.Contains(t, result.FlagTags, "tag1") + assert.Contains(t, result.FlagTags, "tag2") }) t.Run("test happy code path with flagKey", func(t *testing.T) { @@ -467,6 +471,10 @@ func TestEvalFlagsByTags(t *testing.T) { }) assert.NotZero(t, len(results)) assert.NotZero(t, results[0].VariantID) + assert.NotEmpty(t, results[0].FlagTags) + assert.Len(t, results[0].FlagTags, 2) + assert.Contains(t, results[0].FlagTags, "tag1") + assert.Contains(t, results[0].FlagTags, "tag2") }) } @@ -515,6 +523,7 @@ func TestPostEvaluationBatch(t *testing.T) { assert.NotNil(t, resp) }) } + func TestTagsPostEvaluationBatch(t *testing.T) { t.Run("test happy code path", func(t *testing.T) { defer gostub.StubFunc(&EvalFlag, &models.EvalResult{}).Reset() diff --git a/swagger/index.yaml b/swagger/index.yaml index 50caa85d..a2421b25 100644 --- a/swagger/index.yaml +++ b/swagger/index.yaml @@ -481,6 +481,12 @@ definitions: flagSnapshotID: type: integer format: int64 + flagTags: + description: flagTags. flagTags looks up flags by tag. Either works. + type: array + x-omitempty: true + items: + type: string segmentID: type: integer format: int64 diff --git a/swagger_gen/models/eval_result.go b/swagger_gen/models/eval_result.go index 4b53ee81..4a2cf89b 100644 --- a/swagger_gen/models/eval_result.go +++ b/swagger_gen/models/eval_result.go @@ -33,6 +33,9 @@ type EvalResult struct { // flag snapshot ID FlagSnapshotID int64 `json:"flagSnapshotID,omitempty"` + // flagTags. flagTags looks up flags by tag. Either works. + FlagTags []string `json:"flagTags,omitempty"` + // segment ID SegmentID int64 `json:"segmentID,omitempty"` diff --git a/swagger_gen/restapi/embedded_spec.go b/swagger_gen/restapi/embedded_spec.go index c7ec7207..5051dc3a 100644 --- a/swagger_gen/restapi/embedded_spec.go +++ b/swagger_gen/restapi/embedded_spec.go @@ -1639,6 +1639,14 @@ func init() { "type": "integer", "format": "int64" }, + "flagTags": { + "description": "flagTags. flagTags looks up flags by tag. Either works.", + "type": "array", + "items": { + "type": "string" + }, + "x-omitempty": true + }, "segmentID": { "type": "integer", "format": "int64" @@ -3730,6 +3738,14 @@ func init() { "type": "integer", "format": "int64" }, + "flagTags": { + "description": "flagTags. flagTags looks up flags by tag. Either works.", + "type": "array", + "items": { + "type": "string" + }, + "x-omitempty": true + }, "segmentID": { "type": "integer", "format": "int64"