Skip to content

Commit 97f48ae

Browse files
committed
fixup: add readme and missing option
Signed-off-by: Simon Schrottner <[email protected]>
1 parent a7f96d9 commit 97f48ae

File tree

12 files changed

+46
-33
lines changed

12 files changed

+46
-33
lines changed

providers/flagd/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tmp/

providers/flagd/README.md

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ The value is updated with every (re)connection to the sync implementation.
5454
This can be used to enrich evaluations with such data.
5555
If the `in-process` mode is not used, and before the provider is ready, the `getSyncMetadata` returns an empty map.
5656

57-
#### Offline mode
57+
### Offline mode (File resolver)
5858

5959
In-process resolvers can also work in an offline mode.
6060
To enable this mode, you should provide a valid flag configuration file with the option `offlineFlagSourcePath`.
6161

6262
```java
6363
FlagdProvider flagdProvider = new FlagdProvider(
6464
FlagdOptions.builder()
65-
.resolverType(Config.Resolver.IN_PROCESS)
65+
.resolverType(Config.Resolver.FILE)
6666
.offlineFlagSourcePath("PATH")
6767
.build());
6868
```
@@ -103,24 +103,25 @@ variables.
103103

104104
Given below are the supported configurations:
105105

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

125126
> [!NOTE]
126127
> Some configurations are only applicable for RPC resolver.

providers/flagd/schemas

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public final class Config {
1717
static final int DEFAULT_STREAM_DEADLINE_MS = 10 * 60 * 1000;
1818
static final int DEFAULT_STREAM_RETRY_GRACE_PERIOD = 5;
1919
static final int DEFAULT_MAX_CACHE_SIZE = 1000;
20+
static final int DEFAULT_OFFLINE_POLL_MS = 5000;
2021
static final long DEFAULT_KEEP_ALIVE = 0;
2122

2223
static final String RESOLVER_ENV_VAR = "FLAGD_RESOLVER";
@@ -33,6 +34,7 @@ public final class Config {
3334
static final String STREAM_DEADLINE_MS_ENV_VAR_NAME = "FLAGD_STREAM_DEADLINE_MS";
3435
static final String SOURCE_SELECTOR_ENV_VAR_NAME = "FLAGD_SOURCE_SELECTOR";
3536
static final String OFFLINE_SOURCE_PATH = "FLAGD_OFFLINE_FLAG_SOURCE_PATH";
37+
static final String OFFLINE_POLL_MS = "FLAGD_OFFLINE_POLL_MS";
3638
static final String KEEP_ALIVE_MS_ENV_VAR_NAME_OLD = "FLAGD_KEEP_ALIVE_TIME";
3739
static final String KEEP_ALIVE_MS_ENV_VAR_NAME = "FLAGD_KEEP_ALIVE_TIME_MS";
3840
static final String TARGET_URI_ENV_VAR_NAME = "FLAGD_TARGET_URI";

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ public class FlagdOptions {
122122
*/
123123
private String offlineFlagSourcePath;
124124

125+
/**
126+
* File polling interval.
127+
* Defaults to 0 (disabled).
128+
**/
129+
@Builder.Default
130+
private int offlinePollIntervalMs = fallBackToEnvOrDefault(Config.OFFLINE_POLL_MS, Config.DEFAULT_OFFLINE_POLL_MS);
131+
125132
/**
126133
* gRPC custom target string.
127134
*

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/InProcessResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static Connector getConnector(final FlagdOptions options, Consumer<FlagdProvider
151151
}
152152
return options.getOfflineFlagSourcePath() != null
153153
&& !options.getOfflineFlagSourcePath().isEmpty()
154-
? new FileConnector(options.getOfflineFlagSourcePath())
154+
? new FileConnector(options.getOfflineFlagSourcePath(), options.getOfflinePollIntervalMs())
155155
: new GrpcStreamConnector(options, onConnectionEvent);
156156
}
157157

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/storage/connector/file/FileConnector.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@
2424
@Slf4j
2525
public class FileConnector implements Connector {
2626

27-
private static final int POLL_INTERVAL_MS = 5000;
2827
private static final String OFFER_WARN = "Unable to offer file content to queue: queue is full";
2928

3029
private final String flagSourcePath;
30+
private final int pollInterval;
3131
private final BlockingQueue<QueuePayload> queue = new LinkedBlockingQueue<>(1);
3232
private boolean shutdown = false;
3333

34-
public FileConnector(final String flagSourcePath) {
34+
public FileConnector(final String flagSourcePath, int pollInterval) {
3535
this.flagSourcePath = flagSourcePath;
36+
this.pollInterval = pollInterval;
3637
}
3738

3839
/**
@@ -64,7 +65,7 @@ public void init() throws IOException {
6465
}
6566
}
6667

67-
Thread.sleep(POLL_INTERVAL_MS);
68+
Thread.sleep(pollInterval);
6869
}
6970

7071
log.info("Shutting down file connector.");

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/RunRpcTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.junit.platform.suite.api.IncludeEngines;
1313
import org.junit.platform.suite.api.IncludeTags;
1414
import org.junit.platform.suite.api.SelectDirectories;
15-
import org.junit.platform.suite.api.SelectFile;
1615
import org.junit.platform.suite.api.Suite;
1716
import org.testcontainers.junit.jupiter.Testcontainers;
1817

@@ -24,7 +23,7 @@
2423
@IncludeEngines("cucumber")
2524
@SelectDirectories("test-harness/gherkin")
2625
// if you want to run just one feature file, use the following line instead of @SelectDirectories
27-
//@SelectFile("test-harness/gherkin/rpc-caching.feature")
26+
// @SelectFile("test-harness/gherkin/rpc-caching.feature")
2827
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty")
2928
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "dev.openfeature.contrib.providers.flagd.e2e.steps")
3029
@ConfigurationParameter(key = OBJECT_FACTORY_PROPERTY_NAME, value = "io.cucumber.picocontainer.PicoFactory")

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/ProviderSteps.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ public void setupProvider(String providerType) throws IOException, InterruptedEx
112112

113113
state.builder
114114
.port(UNAVAILABLE_PORT)
115-
.offlineFlagSourcePath(sharedTempDir.resolve("allFlags.json").toAbsolutePath().toString());
115+
.offlineFlagSourcePath(sharedTempDir
116+
.resolve("allFlags.json")
117+
.toAbsolutePath()
118+
.toString());
116119
} else {
117120
state.builder.port(container.getPort(State.resolverType));
118121
}

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/e2e/steps/config/ConfigSteps.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class ConfigSteps extends AbstractSteps {
2626
*/
2727
public static final List<String> IGNORED_FOR_NOW = new ArrayList<String>() {
2828
{
29-
add("offlinePollIntervalMs");
3029
add("retryBackoffMaxMs");
3130
}
3231
};

providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/storage/connector/file/FileConnectorTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class FileConnectorTest {
2424
@Test
2525
void readAndExposeFeatureFlagsFromSource() throws IOException {
2626
// given
27-
final FileConnector connector = new FileConnector(getResourcePath(VALID_LONG));
27+
final FileConnector connector = new FileConnector(getResourcePath(VALID_LONG), 5000);
2828

2929
// when
3030
connector.init();
@@ -45,7 +45,7 @@ void readAndExposeFeatureFlagsFromSource() throws IOException {
4545
@Test
4646
void emitErrorStateForInvalidPath() throws IOException {
4747
// given
48-
final FileConnector connector = new FileConnector("INVALID_PATH");
48+
final FileConnector connector = new FileConnector("INVALID_PATH", 5000);
4949

5050
// when
5151
connector.init();
@@ -75,7 +75,7 @@ void watchForFileUpdatesAndEmitThem() throws IOException {
7575
final Path updPath = Paths.get(getResourcePath(UPDATABLE_FILE));
7676
Files.write(updPath, initial.getBytes(), StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
7777

78-
final FileConnector connector = new FileConnector(updPath.toString());
78+
final FileConnector connector = new FileConnector(updPath.toString(), 5000);
7979

8080
// when
8181
connector.init();

0 commit comments

Comments
 (0)