From ab6b8880ae97fca1891554b5dd38f682fc8406d1 Mon Sep 17 00:00:00 2001 From: Cole Bailey Date: Thu, 11 Apr 2024 18:35:40 +0200 Subject: [PATCH] feat!: allow overrides for fractional seed (#737) Signed-off-by: Cole Bailey Signed-off-by: Kavindu Dodanduwa Signed-off-by: Kavindu Dodanduwa Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Kavindu Dodanduwa Co-authored-by: Kavindu Dodanduwa --- .github/workflows/ci.yml | 8 +++--- providers/flagd/CONTRIBUTING.md | 12 +++++++-- providers/flagd/docker-compose.yaml | 25 +++++++++++++++++++ .../process/targeting/Fractional.java | 5 ++-- .../e2e/process/FlagdInProcessSetup.java | 1 - .../process/FlagdInProcessSetup.java | 1 - .../process/targeting/FractionalTest.java | 8 +++--- .../process/targeting/OperatorTest.java | 15 ++++++++--- providers/flagd/test-harness | 2 +- 9 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 providers/flagd/docker-compose.yaml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15c7602d7..38290a373 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,22 +14,22 @@ jobs: services: # flagd-testbed for flagd RPC provider e2e tests flagd: - image: ghcr.io/open-feature/flagd-testbed:v0.5.2 + image: ghcr.io/open-feature/flagd-testbed:v0.5.4 ports: - 8013:8013 # flagd-testbed for flagd RPC provider reconnect e2e tests flagd-unstable: - image: ghcr.io/open-feature/flagd-testbed-unstable:v0.5.3 + image: ghcr.io/open-feature/flagd-testbed-unstable:v0.5.4 ports: - 8014:8013 # sync-testbed for flagd in-process provider e2e tests sync: - image: ghcr.io/open-feature/sync-testbed:v0.5.2 + image: ghcr.io/open-feature/sync-testbed:v0.5.4 ports: - 9090:9090 # sync-testbed for flagd in-process provider reconnect e2e tests sync-unstable: - image: ghcr.io/open-feature/sync-testbed-unstable:v0.5.3 + image: ghcr.io/open-feature/sync-testbed-unstable:v0.5.4 ports: - 9091:9090 diff --git a/providers/flagd/CONTRIBUTING.md b/providers/flagd/CONTRIBUTING.md index d086dc232..ab3c56253 100644 --- a/providers/flagd/CONTRIBUTING.md +++ b/providers/flagd/CONTRIBUTING.md @@ -23,9 +23,17 @@ In vscode for instance, the following settings are recommended: The continuous integration runs a set of [gherkin e2e tests](https://github.com/open-feature/test-harness/blob/main/features/evaluation.feature) using [`flagd`](https://github.com/open-feature/flagd). These tests do not run with the default maven profile. If you'd like to run them locally, you can start the flagd testbed with ``` -docker run -p 8013:8013 ghcr.io/open-feature/flagd-testbed:latest +docker-compose up -d ``` and then run ``` mvn test -P e2e -``` \ No newline at end of file +``` + +Note if your docker compose networking does not resolve to localhost, you can set a custom host +``` +FLAGD_HOST=192.168.100.1 mvn test -P e2e +``` + +If test-harness is being updated, commit the changes before running `mvn`. +Otherwise, uncommitted changes will be overridden by maven test plugins. \ No newline at end of file diff --git a/providers/flagd/docker-compose.yaml b/providers/flagd/docker-compose.yaml new file mode 100644 index 000000000..71a14c025 --- /dev/null +++ b/providers/flagd/docker-compose.yaml @@ -0,0 +1,25 @@ +services: + flagd: + build: + context: test-harness + dockerfile: flagd/Dockerfile + ports: + - 8013:8013 + flagd-unstable: + build: + context: test-harness + dockerfile: flagd/Dockerfile.unstable + ports: + - 8014:8013 + flagd-sync: + build: + context: test-harness + dockerfile: sync/Dockerfile + ports: + - 9090:9090 + flagd-sync-unstable: + build: + context: test-harness + dockerfile: sync/Dockerfile.unstable + ports: + - 9091:9090 \ No newline at end of file diff --git a/providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/Fractional.java b/providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/Fractional.java index 320cc3d7c..9f2d1859f 100644 --- a/providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/Fractional.java +++ b/providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/Fractional.java @@ -45,11 +45,10 @@ public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationEx return null; } - bucketBy = properties.getTargetingKey(); + bucketBy = properties.getFlagKey() + properties.getTargetingKey(); distibutions = arguments.toArray(); } - final String hashKey = properties.getFlagKey() + bucketBy; final List propertyList = new ArrayList<>(); double distribution = 0; @@ -70,7 +69,7 @@ public Object evaluate(List arguments, Object data) throws JsonLogicEvaluationEx } // find distribution - return distributeValue(hashKey, propertyList); + return distributeValue(bucketBy, propertyList); } private static String distributeValue(final String hashKey, final List propertyList) diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/process/FlagdInProcessSetup.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/process/FlagdInProcessSetup.java index 5a47762f4..7991c785d 100644 --- a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/process/FlagdInProcessSetup.java +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/process/FlagdInProcessSetup.java @@ -21,7 +21,6 @@ public static void setup() throws InterruptedException { FlagdInProcessSetup.provider = new FlagdProvider(FlagdOptions.builder() .resolverType(Config.Evaluator.IN_PROCESS) .deadline(3000) - .host("localhost") .port(9090) .build()); StepDefinitions.setProvider(provider); diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/reconnect/process/FlagdInProcessSetup.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/reconnect/process/FlagdInProcessSetup.java index 635159e68..e32b6b8e4 100644 --- a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/reconnect/process/FlagdInProcessSetup.java +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/reconnect/process/FlagdInProcessSetup.java @@ -19,7 +19,6 @@ public static void setup() throws InterruptedException { FeatureProvider workingProvider = new FlagdProvider(FlagdOptions.builder() .resolverType(Config.Evaluator.IN_PROCESS) .deadline(3000) - .host("localhost") .port(9091) .build()); StepDefinitions.setUnstableProvider(workingProvider); diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/FractionalTest.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/FractionalTest.java index fd3e38c69..9ef877d41 100644 --- a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/FractionalTest.java +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/FractionalTest.java @@ -24,7 +24,7 @@ void selfContainedFractionalA() throws JsonLogicEvaluationException { /* Rule * [ - * "bucketKeyA", // this is resolved value of an expression + * "flagAbucketKeyA", // this is resolved value of an expression * [ * "red", * 50 @@ -37,7 +37,7 @@ void selfContainedFractionalA() throws JsonLogicEvaluationException { * */ final List rule = new ArrayList<>(); - rule.add("bucketKeyA"); + rule.add("flagAbucketKeyA"); final List bucket1 = new ArrayList<>(); bucket1.add("red"); @@ -69,7 +69,7 @@ void selfContainedFractionalB() throws JsonLogicEvaluationException { /* Rule * [ - * "bucketKeyB", // this is resolved value of an expression + * "flagAbucketKeyB", // this is resolved value of an expression * [ * "red", * 50 @@ -82,7 +82,7 @@ void selfContainedFractionalB() throws JsonLogicEvaluationException { * */ final List rule = new ArrayList<>(); - rule.add("bucketKeyB"); + rule.add("flagAbucketKeyB"); final List bucket1 = new ArrayList<>(); bucket1.add("red"); diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/OperatorTest.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/OperatorTest.java index f268bbcd5..f9dfb424d 100644 --- a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/OperatorTest.java +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/targeting/OperatorTest.java @@ -85,7 +85,10 @@ void fractionalTestA() throws TargetingRuleException { final String targetingRule = "" + "{\n" + " \"fractional\": [\n" + - " {\"var\": \"email\"},\n" + + " {\"cat\":[\n" + + " {\"var\":\"$flagd.flagKey\"},\n" + + " {\"var\": \"email\"}\n" + + " ]},\n" + " [\n" + " \"red\",\n" + " 25\n" + @@ -123,7 +126,10 @@ void fractionalTestB() throws TargetingRuleException { final String targetingRule = "" + "{\n" + " \"fractional\": [\n" + - " {\"var\": \"email\"},\n" + + " {\"cat\":[\n" + + " {\"var\":\"$flagd.flagKey\"},\n" + + " {\"var\": \"email\"}\n" + + " ]},\n" + " [\n" + " \"red\",\n" + " 25\n" + @@ -161,7 +167,10 @@ void fractionalTestC() throws TargetingRuleException { final String targetingRule = "" + "{\n" + " \"fractional\": [\n" + - " {\"var\": \"email\"},\n" + + " {\"cat\":[\n" + + " {\"var\":\"$flagd.flagKey\"},\n" + + " {\"var\": \"email\"}\n" + + " ]},\n" + " [\n" + " \"red\",\n" + " 25\n" + diff --git a/providers/flagd/test-harness b/providers/flagd/test-harness index a3f34b43d..25544e43d 160000 --- a/providers/flagd/test-harness +++ b/providers/flagd/test-harness @@ -1 +1 @@ -Subproject commit a3f34b43de0f9529c554a59d93d4524cbd2de7a7 +Subproject commit 25544e43d65500ea085d6f0e242b9a616a51f776