From e096c0efb2257641de39bbf665c171dc47782536 Mon Sep 17 00:00:00 2001 From: Todd Baert Date: Fri, 6 Nov 2026 11:19:48 -0500 Subject: [PATCH 1/3] feat(flagd): json-logic 1.2.0, test on java 11/25 Signed-off-by: Todd Baert --- .github/workflows/ci.yml | 57 ++++++++++++++++++- pom.xml | 35 +----------- providers/flagd/README.md | 2 +- providers/flagd/pom.xml | 6 -- .../providers/flagd/CompileTargetingMode.java | 13 +++-- .../resolver/process/InProcessResolver.java | 13 +++-- .../flagd/e2e/steps/ProviderSteps.java | 47 ++++++++------- tools/flagd-core/pom.xml | 2 +- 8 files changed, 102 insertions(+), 73 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1c02c4103..4935b7247b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,12 +48,67 @@ jobs: # *CTest suites) is not switched off by a profile in the root pom; main enforces it anyway run: mvn --batch-mode --activate-profiles 'tck,!codequality' clean verify + # flagd e2e on a JRE (no javac) with targeting compilation forced on; + # 11 covers the interpreter fallback, 25 covers the JEP 484 (Class-File API) compiler + flagd-jre: + strategy: + matrix: + build: + - java: 11 + args: --activate-profiles e2e,java11 + - java: 25 + args: --activate-profiles e2e + + name: flagd on JRE ${{ matrix.build.java }} + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Checkout Repository + uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 + with: + submodules: recursive + persist-credentials: false + + # installed first so the JDK below stays the default JAVA_HOME for maven + - name: Set up JRE ${{ matrix.build.java }} + id: jre + uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5.7.0 + with: + java-version: ${{ matrix.build.java }} + java-package: jre + distribution: 'temurin' + + - name: Set up JDK ${{ matrix.build.java }} + uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5.7.0 + with: + java-version: ${{ matrix.build.java }} + distribution: 'temurin' + cache: maven + + - name: Verify JRE has no javac + run: | + if "${{ steps.jre.outputs.path }}/bin/java" --list-modules | grep -q '^jdk.compiler@'; then + echo "JRE contains jdk.compiler; this job would not cover the no-javac case" && exit 1 + fi + + - name: Run flagd e2e on JRE + env: + FLAGD_COMPILE_TARGETING: enabled + JRE_HOME: ${{ steps.jre.outputs.path }} + # only the e2e suites; the env var would break unit tests asserting the default mode + run: >- + mvn --batch-mode -pl tools/flagd-core,providers/flagd -am ${{ matrix.build.args }} + -Djvm="$JRE_HOME/bin/java" -Dtest='Run*Test' -Dsurefire.failIfNoSpecifiedTests=false + clean verify + main: strategy: matrix: os: [ubuntu-latest] build: - - java: 21 + # latest LTS; also exercises the JEP 484 (Class-File API) JsonLogic compiler + - java: 25 # deploy profile is included to catch javadoc/SBOM/source-jar issues at PR time # note this is the publish PROFILE, not PHASE profile: codequality,deploy diff --git a/pom.xml b/pom.xml index 01e2349766..35bbcd5d43 100644 --- a/pom.xml +++ b/pom.xml @@ -69,11 +69,12 @@ --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED - false false 11 + + full @@ -333,9 +334,6 @@ true - - full - @@ -466,9 +464,6 @@ true - - full - @@ -614,7 +609,6 @@ [11,) - true @@ -631,31 +625,6 @@ - - org.apache.maven.plugins - maven-surefire-plugin - 3.6.0 - - ${skip.tests} - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.16.0 - - - default-testCompile - test-compile - - testCompile - - - true - - - - diff --git a/providers/flagd/README.md b/providers/flagd/README.md index 4daa06b84e..6e4da5c2f5 100644 --- a/providers/flagd/README.md +++ b/providers/flagd/README.md @@ -180,7 +180,7 @@ Given below are the supported configurations: > The `selector` option automatically uses the `flagd-selector` header (the preferred approach per [flagd issue #1814](https://github.com/open-feature/flagd/issues/1814)) while maintaining backward compatibility with older flagd versions. See [Selector filtering](#selector-filtering-in-process-mode-only) for details. > [!TIP] -> The `compileTargeting` option (experimental) controls pre-compilation of JsonLogic targeting rules into Java bytecode for improved evaluation performance. This requires the `jdk.compiler` module at runtime, which is typically not available in JRE-only images (distroless, Alpine, UBI Micro, etc.). In `auto` mode (the default), the provider calls `javax.tools.ToolProvider.getSystemJavaCompiler()` at initialization; if it returns non-null, compilation is enabled, otherwise the interpreter is used. Set to `enabled` to force compilation (a warning is logged if the compiler is unavailable), or `disabled` to always use the interpreter. Note that compilation adds latency to the first evaluation of each rule (source generation, in-memory javac, and class loading); subsequent evaluations of the same rule are faster. +> The `compileTargeting` option (experimental) controls pre-compilation of JsonLogic targeting rules into Java bytecode for improved evaluation performance. On Java 24+, bytecode is generated with the built-in Class-File API (JEP 484), which works on JRE-only images and compiles roughly 100x faster than javac. On older JVMs, compilation falls back to javac and requires the `jdk.compiler` module at runtime, which is typically not available in JRE-only images (distroless, Alpine, UBI Micro, etc.). In `auto` mode (the default), the provider enables compilation if either compiler is available, otherwise the interpreter is used. Set to `enabled` to force compilation (a warning is logged if no compiler is available), or `disabled` to always use the interpreter. Note that compilation adds latency to the first evaluation of each rule; subsequent evaluations of the same rule are faster. ### Unix socket support diff --git a/providers/flagd/pom.xml b/providers/flagd/pom.xml index daf72975a4..0dc4842a28 100644 --- a/providers/flagd/pom.xml +++ b/providers/flagd/pom.xml @@ -132,12 +132,6 @@ 2.0.5 test - - io.rest-assured - rest-assured - 6.2.0 - test - commons-io commons-io diff --git a/providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/CompileTargetingMode.java b/providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/CompileTargetingMode.java index 3cfe93a98f..e63e2f97a7 100644 --- a/providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/CompileTargetingMode.java +++ b/providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/CompileTargetingMode.java @@ -3,10 +3,11 @@ /** * !EXPERIMENTAL! * Controls whether JsonLogic targeting rules are compiled into Java bytecode for improved - * evaluation performance. Compilation requires the {@code jdk.compiler} module at runtime, + * evaluation performance. On Java 24+, the built-in Class-File API (JEP 484) is used, which works + * on JRE-only images. On older JVMs, compilation requires the {@code jdk.compiler} module (javac), * which is typically not available in JRE-only images. - * Compilation adds latency to the first evaluation of each rule (source generation, in-memory - * javac, class loading); subsequent evaluations are faster. This trade-off favors long-running + * Compilation adds latency to the first evaluation of each rule (much less with the Class-File + * API than with javac); subsequent evaluations are faster. This trade-off favors long-running * services where rules are evaluated many times. */ public enum CompileTargetingMode { @@ -21,9 +22,9 @@ public enum CompileTargetingMode { DISABLED, /** - * Auto-detect: checks {@code javax.tools.ToolProvider.getSystemJavaCompiler() != null} at - * initialization. If the compiler is available, compilation is enabled; otherwise the - * interpreter is used silently. This is the default. + * Auto-detect: at initialization, checks whether any JsonLogic compiler (Class-File API or + * javac) is available. If so, compilation is enabled; otherwise the interpreter is used + * silently. This is the default. */ AUTO } diff --git a/providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/InProcessResolver.java b/providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/InProcessResolver.java index 9bb44a4a6f..a6cf3912c8 100644 --- a/providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/InProcessResolver.java +++ b/providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/InProcessResolver.java @@ -19,9 +19,9 @@ import dev.openfeature.sdk.Structure; import dev.openfeature.sdk.Value; import dev.openfeature.sdk.internal.TriConsumer; +import io.github.jamsesso.jsonlogic.compiler.JsonLogicCompiler; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import javax.tools.ToolProvider; import lombok.extern.slf4j.Slf4j; /** @@ -200,20 +200,21 @@ static QueueSource getQueueSource(final FlagdOptions options) { static boolean resolveCompileTargeting(CompileTargetingMode mode) { switch (mode) { case ENABLED: - log.info("Targeting rule compilation enabled; requires the jdk.compiler module at runtime."); + log.info("Targeting rule compilation enabled; requires Java 24+ or the jdk.compiler module."); return true; case DISABLED: log.info("Targeting rule compilation is disabled."); return false; case AUTO: default: - boolean compilerAvailable = ToolProvider.getSystemJavaCompiler() != null; + boolean compilerAvailable = JsonLogicCompiler.selectProvider(JsonLogicCompiler.discoverProviders()) + .isPresent(); if (compilerAvailable) { - log.info("jdk.compiler detected; targeting rule compilation enabled automatically." + log.info("JsonLogic compiler detected; targeting rule compilation enabled automatically." + " Set FLAGD_COMPILE_TARGETING=disabled to disable."); } else { - log.info("jdk.compiler not detected; targeting rule compilation disabled." - + " Set FLAGD_COMPILE_TARGETING=enabled to force (requires a JDK at runtime)."); + log.info("No JsonLogic compiler detected; targeting rule compilation disabled." + + " Requires Java 24+ or the jdk.compiler module at runtime."); } return compilerAvailable; } diff --git a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/ProviderSteps.java b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/ProviderSteps.java index f9e1b846f1..ae170982f4 100644 --- a/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/ProviderSteps.java +++ b/providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/ProviderSteps.java @@ -1,6 +1,5 @@ package dev.openfeature.contrib.providers.flagd.e2e.steps; -import static io.restassured.RestAssured.when; import static org.assertj.core.api.Assertions.assertThat; import dev.openfeature.contrib.providers.flagd.Config; @@ -21,6 +20,12 @@ import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.testcontainers.containers.ComposeContainer; @@ -29,6 +34,7 @@ public class ProviderSteps extends AbstractSteps { public static final int UNAVAILABLE_PORT = 9999; + private static final HttpClient HTTP_CLIENT = HttpClient.newHttpClient(); public ProviderSteps(State state) { super(state); @@ -48,9 +54,7 @@ public static void afterAll() { public void tearDown() { if (state.containerEntry != null) { if (state.client != null) { - when().post("http://" + ContainerUtil.getLaunchpadUrl(state.containerEntry.container) + "/stop") - .then() - .statusCode(200); + launchpad(state.containerEntry.container, "/stop"); } ContainerPool.release(state.containerEntry); state.containerEntry = null; @@ -154,9 +158,7 @@ public void setupProvider(String providerType) throws InterruptedException { state.builder.port(UNAVAILABLE_PORT); } - when().post("http://" + ContainerUtil.getLaunchpadUrl(container) + "/start?config={config}", flagdConfig) - .then() - .statusCode(200); + launchpad(container, "/start?config=" + flagdConfig); Thread.sleep(50); @@ -177,30 +179,37 @@ public void setupProvider(String providerType) throws InterruptedException { @When("the connection is lost") public void the_connection_is_lost() { - when().post("http://" + ContainerUtil.getLaunchpadUrl(state.containerEntry.container) + "/stop") - .then() - .statusCode(200); + launchpad(state.containerEntry.container, "/stop"); } @When("the connection is lost for {int}s") public void the_connection_is_lost_for(int seconds) { - when().post( - "http://" + ContainerUtil.getLaunchpadUrl(state.containerEntry.container) - + "/restart?seconds={seconds}", - seconds) - .then() - .statusCode(200); + launchpad(state.containerEntry.container, "/restart?seconds=" + seconds); } @When("the flag was modified") public void the_flag_was_modded() { - when().post("http://" + ContainerUtil.getLaunchpadUrl(state.containerEntry.container) + "/change") - .then() - .statusCode(200); + launchpad(state.containerEntry.container, "/change"); } @Then("the client should be in {} state") public void the_client_should_be_in_fatal_state(String clientState) { assertThat(state.client.getProviderState()).isEqualTo(ProviderState.valueOf(clientState.toUpperCase())); } + + private static void launchpad(ComposeContainer container, String path) { + HttpRequest request = HttpRequest.newBuilder( + URI.create("http://" + ContainerUtil.getLaunchpadUrl(container) + path)) + .POST(HttpRequest.BodyPublishers.noBody()) + .build(); + try { + HttpResponse response = HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString()); + assertThat(response.statusCode()).as("launchpad %s", path).isEqualTo(200); + } catch (IOException e) { + throw new UncheckedIOException(e); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new IllegalStateException(e); + } + } } diff --git a/tools/flagd-core/pom.xml b/tools/flagd-core/pom.xml index a05ac97797..a3958a361b 100644 --- a/tools/flagd-core/pom.xml +++ b/tools/flagd-core/pom.xml @@ -49,7 +49,7 @@ io.github.gzsombor json-logic-java - 1.1.6 + 1.2.0 From fb96e0fb927c90d579d1bda7cfe2ed81af0a50d8 Mon Sep 17 00:00:00 2001 From: Todd Baert Date: Fri, 6 Nov 2026 11:48:57 -0500 Subject: [PATCH 2/3] fixup: jdk/jre 11/25 matrix, e2e-only profile Signed-off-by: Todd Baert --- .github/workflows/ci.yml | 87 +++++++------------ pom.xml | 8 ++ .../sync/http/HttpConnectorOptions.java | 4 +- 3 files changed, 42 insertions(+), 57 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4935b7247b..07b2be67ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,30 +48,42 @@ jobs: # *CTest suites) is not switched off by a profile in the root pom; main enforces it anyway run: mvn --batch-mode --activate-profiles 'tck,!codequality' clean verify - # flagd e2e on a JRE (no javac) with targeting compilation forced on; - # 11 covers the interpreter fallback, 25 covers the JEP 484 (Class-File API) compiler - flagd-jre: + main: strategy: - matrix: - build: - - java: 11 - args: --activate-profiles e2e,java11 - - java: 25 - args: --activate-profiles e2e + matrix: + os: [ubuntu-latest] + build: + # latest LTS; the only leg running unit tests and code quality checks + # deploy profile is included to catch javadoc/SBOM/source-jar issues at PR time + # note this is the publish PROFILE, not PHASE + - java: 25 + package: jdk + profile: codequality,deploy + # e2e only, on the oldest supported and on JREs (no javac), as in many production images + - java: 11 + package: jdk + profile: java11 + e2eOnly: true + - java: 25 + package: jre + profile: '' + e2eOnly: true + - java: 11 + package: jre + profile: java11 + e2eOnly: true - name: flagd on JRE ${{ matrix.build.java }} - runs-on: ubuntu-latest - permissions: - contents: read + name: ${{ matrix.build.package == 'jre' && 'JRE' || 'JDK' }} ${{ matrix.build.java }}${{ matrix.build.e2eOnly && ' (e2e)' || '' }} + runs-on: ${{ matrix.os}} steps: - name: Checkout Repository uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 with: submodules: recursive - persist-credentials: false # installed first so the JDK below stays the default JAVA_HOME for maven - name: Set up JRE ${{ matrix.build.java }} + if: matrix.build.package == 'jre' id: jre uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5.7.0 with: @@ -79,50 +91,13 @@ jobs: java-package: jre distribution: 'temurin' - - name: Set up JDK ${{ matrix.build.java }} - uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5.7.0 - with: - java-version: ${{ matrix.build.java }} - distribution: 'temurin' - cache: maven - - name: Verify JRE has no javac + if: matrix.build.package == 'jre' run: | if "${{ steps.jre.outputs.path }}/bin/java" --list-modules | grep -q '^jdk.compiler@'; then - echo "JRE contains jdk.compiler; this job would not cover the no-javac case" && exit 1 + echo "JRE contains jdk.compiler; tests would not cover the no-javac case" && exit 1 fi - - name: Run flagd e2e on JRE - env: - FLAGD_COMPILE_TARGETING: enabled - JRE_HOME: ${{ steps.jre.outputs.path }} - # only the e2e suites; the env var would break unit tests asserting the default mode - run: >- - mvn --batch-mode -pl tools/flagd-core,providers/flagd -am ${{ matrix.build.args }} - -Djvm="$JRE_HOME/bin/java" -Dtest='Run*Test' -Dsurefire.failIfNoSpecifiedTests=false - clean verify - - main: - strategy: - matrix: - os: [ubuntu-latest] - build: - # latest LTS; also exercises the JEP 484 (Class-File API) JsonLogic compiler - - java: 25 - # deploy profile is included to catch javadoc/SBOM/source-jar issues at PR time - # note this is the publish PROFILE, not PHASE - profile: codequality,deploy - - java: 11 - profile: java11 - - name: with Java ${{ matrix.build.java }} - runs-on: ${{ matrix.os}} - steps: - - name: Checkout Repository - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0 - with: - submodules: recursive - - name: Set up JDK ${{ matrix.build.java }} uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5.7.0 with: @@ -140,4 +115,8 @@ jobs: - name: Maven Verify # Run Maven build with e2e and specific profile, using parallel threads (if some provider decides to use a different toolchain version, this might break) - run: mvn -T 2C --batch-mode --activate-profiles e2e,${{ matrix.build.profile }} clean verify + # jre legs build with the JDK but fork tests onto the JRE + env: + JVM_ARG: ${{ matrix.build.package == 'jre' && format('-Djvm={0}/bin/java', steps.jre.outputs.path) || '' }} + PROFILES: ${{ matrix.build.e2eOnly && format('e2e,e2e-only,{0},!codequality,!deploy', matrix.build.profile) || format('e2e,{0}', matrix.build.profile) }} + run: mvn -T 2C --batch-mode --activate-profiles "$PROFILES" $JVM_ARG clean verify diff --git a/pom.xml b/pom.xml index 35bbcd5d43..2c43abff82 100644 --- a/pom.xml +++ b/pom.xml @@ -628,6 +628,14 @@ + + + e2e-only + + **/e2e/** + false + +