Skip to content

Commit d7add94

Browse files
authored
Merge branch 'main' into feature/statsig-1627
2 parents eef8493 + 1a85794 commit d7add94

File tree

12 files changed

+118
-72
lines changed

12 files changed

+118
-72
lines changed

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"hooks/open-telemetry": "3.3.1",
33
"providers/flagd": "0.11.18",
4-
"providers/go-feature-flag": "1.0.1",
4+
"providers/go-feature-flag": "1.1.0",
55
"providers/flagsmith": "0.0.12",
66
"providers/env-var": "0.0.12",
77
"providers/jsonlogic-eval-provider": "1.2.1",

providers/flagd/README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,27 @@ variables.
106106

107107
Given below are the supported configurations:
108108

109-
| Option name | Environment variable name | Type & Values | Default | Compatible resolver |
110-
|-----------------------|--------------------------------|--------------------------|-----------|-------------------------|
111-
| resolver | FLAGD_RESOLVER | String - rpc, in-process | rpc | |
112-
| host | FLAGD_HOST | String | localhost | rpc & in-process |
113-
| port | FLAGD_PORT | int | 8013 | rpc & in-process |
114-
| targetUri | FLAGD_TARGET_URI | string | null | rpc & in-process |
115-
| tls | FLAGD_TLS | boolean | false | rpc & in-process |
116-
| defaultAuthority | FLAGD_DEFAULT_AUTHORITY | String | null | rpc & in-process |
117-
| socketPath | FLAGD_SOCKET_PATH | String | null | rpc & in-process |
118-
| certPath | FLAGD_SERVER_CERT_PATH | String | null | rpc & in-process |
119-
| deadline | FLAGD_DEADLINE_MS | int | 500 | rpc & in-process & file |
120-
| streamDeadlineMs | FLAGD_STREAM_DEADLINE_MS | int | 600000 | rpc & in-process |
121-
| keepAliveTime | FLAGD_KEEP_ALIVE_TIME_MS | long | 0 | rpc & in-process |
122-
| selector | FLAGD_SOURCE_SELECTOR | String | null | in-process |
123-
| providerId | FLAGD_SOURCE_PROVIDER_ID | String | null | in-process |
124-
| cache | FLAGD_CACHE | String - lru, disabled | lru | rpc |
125-
| maxCacheSize | FLAGD_MAX_CACHE_SIZE | int | 1000 | rpc |
126-
| maxEventStreamRetries | FLAGD_MAX_EVENT_STREAM_RETRIES | int | 5 | rpc |
127-
| retryBackoffMs | FLAGD_RETRY_BACKOFF_MS | int | 1000 | rpc |
128-
| offlineFlagSourcePath | FLAGD_OFFLINE_FLAG_SOURCE_PATH | String | null | file |
129-
| offlinePollIntervalMs | FLAGD_OFFLINE_POLL_MS | int | 5000 | file |
109+
| Option name | Environment variable name | Type & Values | Default | Compatible resolver |
110+
|-----------------------|------------------------------------------------------------------------|--------------------------|-------------------------------|-------------------------|
111+
| resolver | FLAGD_RESOLVER | String - rpc, in-process | rpc | |
112+
| host | FLAGD_HOST | String | localhost | rpc & in-process |
113+
| port | FLAGD_PORT (rpc), FLAGD_SYNC_PORT (in-process, FLAGD_PORT as fallback) | int | 8013 (rpc), 8015 (in-process) | rpc & in-process |
114+
| targetUri | FLAGD_TARGET_URI | string | null | rpc & in-process |
115+
| tls | FLAGD_TLS | boolean | false | rpc & in-process |
116+
| defaultAuthority | FLAGD_DEFAULT_AUTHORITY | String | null | rpc & in-process |
117+
| socketPath | FLAGD_SOCKET_PATH | String | null | rpc & in-process |
118+
| certPath | FLAGD_SERVER_CERT_PATH | String | null | rpc & in-process |
119+
| deadline | FLAGD_DEADLINE_MS | int | 500 | rpc & in-process & file |
120+
| streamDeadlineMs | FLAGD_STREAM_DEADLINE_MS | int | 600000 | rpc & in-process |
121+
| keepAliveTime | FLAGD_KEEP_ALIVE_TIME_MS | long | 0 | rpc & in-process |
122+
| selector | FLAGD_SOURCE_SELECTOR | String | null | in-process |
123+
| providerId | FLAGD_SOURCE_PROVIDER_ID | String | null | in-process |
124+
| cache | FLAGD_CACHE | String - lru, disabled | lru | rpc |
125+
| maxCacheSize | FLAGD_MAX_CACHE_SIZE | int | 1000 | rpc |
126+
| maxEventStreamRetries | FLAGD_MAX_EVENT_STREAM_RETRIES | int | 5 | rpc |
127+
| retryBackoffMs | FLAGD_RETRY_BACKOFF_MS | int | 1000 | rpc |
128+
| offlineFlagSourcePath | FLAGD_OFFLINE_FLAG_SOURCE_PATH | String | null | file |
129+
| offlinePollIntervalMs | FLAGD_OFFLINE_POLL_MS | int | 5000 | file |
130130

131131
> [!NOTE]
132132
> Some configurations are only applicable for RPC resolver.

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/Config.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public final class Config {
2424
static final String RESOLVER_ENV_VAR = "FLAGD_RESOLVER";
2525
static final String HOST_ENV_VAR_NAME = "FLAGD_HOST";
2626
static final String PORT_ENV_VAR_NAME = "FLAGD_PORT";
27+
static final String SYNC_PORT_ENV_VAR_NAME = "FLAGD_SYNC_PORT";
2728
static final String TLS_ENV_VAR_NAME = "FLAGD_TLS";
2829
static final String DEFAULT_AUTHORITY_ENV_VAR_NAME = "FLAGD_DEFAULT_AUTHORITY";
2930
static final String SOCKET_PATH_ENV_VAR_NAME = "FLAGD_SOCKET_PATH";

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/FlagdOptions.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,14 @@ void prebuild() {
254254
}
255255

256256
if (port == 0 && resolverType != Config.Resolver.FILE) {
257-
port = Integer.parseInt(
258-
fallBackToEnvOrDefault(Config.PORT_ENV_VAR_NAME, determineDefaultPortForResolver()));
257+
String defaultPort = determineDefaultPortForResolver();
258+
String fromPortEnv = fallBackToEnvOrDefault(Config.PORT_ENV_VAR_NAME, defaultPort);
259+
260+
String portValue = resolverType == Config.Resolver.IN_PROCESS
261+
? fallBackToEnvOrDefault(Config.SYNC_PORT_ENV_VAR_NAME, fromPortEnv)
262+
: fromPortEnv;
263+
264+
port = Integer.parseInt(portValue);
259265
}
260266
}
261267

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/FlagdOptionsTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import static dev.openfeature.contrib.providers.flagd.Config.DEFAULT_RPC_PORT;
88
import static dev.openfeature.contrib.providers.flagd.Config.KEEP_ALIVE_MS_ENV_VAR_NAME;
99
import static dev.openfeature.contrib.providers.flagd.Config.KEEP_ALIVE_MS_ENV_VAR_NAME_OLD;
10+
import static dev.openfeature.contrib.providers.flagd.Config.PORT_ENV_VAR_NAME;
1011
import static dev.openfeature.contrib.providers.flagd.Config.RESOLVER_ENV_VAR;
1112
import static dev.openfeature.contrib.providers.flagd.Config.RESOLVER_IN_PROCESS;
1213
import static dev.openfeature.contrib.providers.flagd.Config.RESOLVER_RPC;
14+
import static dev.openfeature.contrib.providers.flagd.Config.SYNC_PORT_ENV_VAR_NAME;
1315
import static dev.openfeature.contrib.providers.flagd.Config.TARGET_URI_ENV_VAR_NAME;
1416
import static org.assertj.core.api.Assertions.assertThat;
1517
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -201,6 +203,37 @@ void testInProcessProviderFromEnv_portConfigured_usesConfiguredPort() {
201203
assertThat(flagdOptions.getPort()).isEqualTo(1000);
202204
}
203205

206+
@Test
207+
@SetEnvironmentVariable(key = RESOLVER_ENV_VAR, value = RESOLVER_IN_PROCESS)
208+
@SetEnvironmentVariable(key = SYNC_PORT_ENV_VAR_NAME, value = "9999")
209+
void testInProcessProvider_usesSyncPortEnvVarWhenSet() {
210+
FlagdOptions flagdOptions = FlagdOptions.builder().build();
211+
212+
assertThat(flagdOptions.getResolverType()).isEqualTo(Resolver.IN_PROCESS);
213+
assertThat(flagdOptions.getPort()).isEqualTo(9999);
214+
}
215+
216+
@Test
217+
@SetEnvironmentVariable(key = RESOLVER_ENV_VAR, value = RESOLVER_IN_PROCESS)
218+
@SetEnvironmentVariable(key = PORT_ENV_VAR_NAME, value = "8888")
219+
void testInProcessProvider_fallsBackToFlagdPortWhenSyncPortNotSet() {
220+
FlagdOptions flagdOptions = FlagdOptions.builder().build();
221+
222+
assertThat(flagdOptions.getResolverType()).isEqualTo(Resolver.IN_PROCESS);
223+
assertThat(flagdOptions.getPort()).isEqualTo(8888);
224+
}
225+
226+
@Test
227+
@SetEnvironmentVariable(key = RESOLVER_ENV_VAR, value = RESOLVER_IN_PROCESS)
228+
@SetEnvironmentVariable(key = PORT_ENV_VAR_NAME, value = "8888")
229+
@SetEnvironmentVariable(key = SYNC_PORT_ENV_VAR_NAME, value = "9999")
230+
void testInProcessProvider_syncPortTakesPrecedenceOverFlagdPort() {
231+
FlagdOptions flagdOptions = FlagdOptions.builder().build();
232+
233+
assertThat(flagdOptions.getResolverType()).isEqualTo(Resolver.IN_PROCESS);
234+
assertThat(flagdOptions.getPort()).isEqualTo(9999);
235+
}
236+
204237
@Test
205238
@SetEnvironmentVariable(key = RESOLVER_ENV_VAR, value = RESOLVER_RPC)
206239
void testRpcProviderFromEnv_noPortConfigured_defaultsToCorrectPort() {

providers/go-feature-flag/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## [1.1.0](https://github.com/open-feature/java-sdk-contrib/compare/dev.openfeature.contrib.providers.go-feature-flag-v1.0.1...dev.openfeature.contrib.providers.go-feature-flag-v1.1.0) (2025-11-24)
4+
5+
6+
### 🐛 Bug Fixes
7+
8+
* **flagd:** fix wrong environment variable and test execution ([#1589](https://github.com/open-feature/java-sdk-contrib/issues/1589)) ([e1d8e54](https://github.com/open-feature/java-sdk-contrib/commit/e1d8e54cb15f7e9f27626c60cebded3690a84698))
9+
10+
11+
### ✨ New Features
12+
13+
* compile go-feature-flag to Java bytecode ([#1628](https://github.com/open-feature/java-sdk-contrib/issues/1628)) ([129c9bd](https://github.com/open-feature/java-sdk-contrib/commit/129c9bdd130b3a193cf641c7ab02b43b2567b9df))
14+
315
## [1.0.1](https://github.com/open-feature/java-sdk-contrib/compare/dev.openfeature.contrib.providers.go-feature-flag-v1.0.0...dev.openfeature.contrib.providers.go-feature-flag-v1.0.1) (2025-09-19)
416

517

providers/go-feature-flag/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ For documentation related to flags management in GO Feature Flag, refer to the [
2828
<dependency>
2929
<groupId>dev.openfeature.contrib.providers</groupId>
3030
<artifactId>go-feature-flag</artifactId>
31-
<version>1.0.1</version>
31+
<version>1.1.0</version>
3232
</dependency>
3333
```
3434
<!-- x-release-please-end-version -->

providers/go-feature-flag/pom.xml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</parent>
1111
<groupId>dev.openfeature.contrib.providers</groupId>
1212
<artifactId>go-feature-flag</artifactId>
13-
<version>1.0.1</version> <!--x-release-please-version -->
13+
<version>1.1.0</version> <!--x-release-please-version -->
1414

1515
<name>go-feature-flag</name>
1616
<description>GO Feature Flag provider for Java</description>
@@ -19,6 +19,8 @@
1919
<properties>
2020
<!-- override module name defined in parent ("-" is not allowed) -->
2121
<module-name>${groupId}.gofeatureflag</module-name>
22+
23+
<wasm.version>v1.45.4</wasm.version>
2224
</properties>
2325

2426
<developers>
@@ -74,16 +76,10 @@
7476
<scope>test</scope>
7577
</dependency>
7678

77-
<dependency>
78-
<groupId>com.dylibso.chicory</groupId>
79-
<artifactId>runtime</artifactId>
80-
<version>1.5.0</version>
81-
</dependency>
82-
8379
<dependency>
8480
<groupId>com.dylibso.chicory</groupId>
8581
<artifactId>wasi</artifactId>
86-
<version>1.5.0</version>
82+
<version>1.6.0</version>
8783
</dependency>
8884

8985
<dependency>
@@ -117,20 +113,18 @@
117113
<build>
118114
<plugins>
119115
<plugin>
120-
<groupId>org.codehaus.mojo</groupId>
121-
<artifactId>exec-maven-plugin</artifactId>
116+
<groupId>com.dylibso.chicory</groupId>
117+
<artifactId>chicory-compiler-maven-plugin</artifactId>
118+
<version>1.6.0</version>
122119
<executions>
123120
<execution>
124-
<id>download-latest-github-asset</id>
125-
<phase>generate-resources</phase>
121+
<id>gofeatureflag</id>
126122
<goals>
127-
<goal>exec</goal>
123+
<goal>compile</goal>
128124
</goals>
129125
<configuration>
130-
<executable>bash</executable>
131-
<arguments>
132-
<argument>${project.basedir}/download-wasm.sh</argument>
133-
</arguments>
126+
<name>dev.openfeature.contrib.providers.gofeatureflag.wasm.Module</name>
127+
<wasmFile>wasm-releases/evaluation/gofeatureflag-evaluation_${wasm.version}.wasi</wasmFile>
134128
</configuration>
135129
</execution>
136130
</executions>

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/wasm/EvaluationWasm.java

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
package dev.openfeature.contrib.providers.gofeatureflag.wasm;
22

3+
import com.dylibso.chicory.runtime.ByteArrayMemory;
34
import com.dylibso.chicory.runtime.ExportFunction;
45
import com.dylibso.chicory.runtime.HostFunction;
6+
import com.dylibso.chicory.runtime.ImportFunction;
7+
import com.dylibso.chicory.runtime.ImportValues;
58
import com.dylibso.chicory.runtime.Instance;
69
import com.dylibso.chicory.runtime.Memory;
7-
import com.dylibso.chicory.runtime.Store;
810
import com.dylibso.chicory.wasi.WasiExitException;
911
import com.dylibso.chicory.wasi.WasiOptions;
1012
import com.dylibso.chicory.wasi.WasiPreview1;
11-
import com.dylibso.chicory.wasm.Parser;
1213
import com.dylibso.chicory.wasm.types.ValueType;
1314
import dev.openfeature.contrib.providers.gofeatureflag.bean.GoFeatureFlagResponse;
1415
import dev.openfeature.contrib.providers.gofeatureflag.exception.WasmFileNotFound;
1516
import dev.openfeature.contrib.providers.gofeatureflag.util.Const;
1617
import dev.openfeature.contrib.providers.gofeatureflag.wasm.bean.WasmInput;
1718
import dev.openfeature.sdk.ErrorCode;
1819
import dev.openfeature.sdk.Reason;
19-
import java.io.InputStream;
2020
import java.nio.charset.StandardCharsets;
21+
import java.util.Arrays;
2122
import java.util.Collections;
23+
import java.util.List;
24+
import java.util.stream.Collectors;
2225
import lombok.val;
2326

2427
/**
@@ -42,36 +45,21 @@ public EvaluationWasm() throws WasmFileNotFound {
4245
val wasi = WasiPreview1.builder()
4346
.withOptions(WasiOptions.builder().inheritSystem().build())
4447
.build();
45-
val hostFunctions = wasi.toHostFunctions();
46-
val store = new Store().addFunction(hostFunctions);
47-
store.addFunction(getProcExitFunc());
48-
this.instance = store.instantiate("evaluation", Parser.parse(getWasmFile()));
48+
List<ImportFunction> hostFunctions =
49+
Arrays.stream(wasi.toHostFunctions()).map(this::replaceProcExit).collect(Collectors.toList());
50+
this.instance = Instance.builder(Module.load())
51+
.withMemoryFactory(ByteArrayMemory::new)
52+
.withMachineFactory(Module::create)
53+
.withImportValues(
54+
ImportValues.builder().withFunctions(hostFunctions).build())
55+
.build();
4956
this.evaluate = this.instance.export("evaluate");
5057
this.malloc = this.instance.export("malloc");
5158
this.free = this.instance.export("free");
5259
}
5360

54-
/**
55-
* getWasmFile is a function that returns the path to the WASM file.
56-
* It looks for the file in the classpath under the directory "wasm".
57-
* This method handles both file system resources and JAR-packaged resources.
58-
*
59-
* @return the path to the WASM file
60-
* @throws WasmFileNotFound - if the file is not found
61-
*/
62-
private InputStream getWasmFile() throws WasmFileNotFound {
63-
try {
64-
final String wasmResourcePath = "wasm/gofeatureflag-evaluation.wasi";
65-
InputStream inputStream = EvaluationWasm.class.getClassLoader().getResourceAsStream(wasmResourcePath);
66-
if (inputStream == null) {
67-
throw new WasmFileNotFound("WASM resource not found in classpath: " + wasmResourcePath);
68-
}
69-
return inputStream;
70-
} catch (WasmFileNotFound e) {
71-
throw e;
72-
} catch (Exception e) {
73-
throw new WasmFileNotFound(e);
74-
}
61+
private ImportFunction replaceProcExit(HostFunction hf) {
62+
return hf.name().equals("proc_exit") ? getProcExitFunc() : hf;
7563
}
7664

7765
/**
@@ -81,7 +69,7 @@ private InputStream getWasmFile() throws WasmFileNotFound {
8169
*
8270
* @return a HostFunction that is called when the WASM module calls proc_exit
8371
*/
84-
private HostFunction getProcExitFunc() {
72+
private ImportFunction getProcExitFunc() {
8573
return new HostFunction(
8674
"wasi_snapshot_preview1",
8775
"proc_exit",
Binary file not shown.

0 commit comments

Comments
 (0)