Skip to content

Commit 6f12d80

Browse files
committed
WIP go-feature-flag
1 parent cf49222 commit 6f12d80

File tree

10 files changed

+112
-9
lines changed

10 files changed

+112
-9
lines changed

pom.xml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
<description>OpenFeature bundle for Dropwizard</description>
1616

1717
<properties>
18-
<!-- Support Java 8 as the same language level supported by the Openfeature SDK -->
19-
<java.version>8</java.version>
18+
<!-- Support Java 11 as the same language level supported by the Openfeature SDK -->
19+
<maven.compiler.release>11</maven.compiler.release>
2020
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2121
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2222
<dropwizard.version>5.0.0</dropwizard.version>
2323
<openfeature-sdk.version>1.18.2</openfeature-sdk.version>
2424
<openfeature-contrib-providers-flagd.version>0.11.17</openfeature-contrib-providers-flagd.version>
25+
<openfeature-contrib-providers-go-feature-flag.version>1.0.1</openfeature-contrib-providers-go-feature-flag.version>
2526
<jacoco-maven-plugin.version>0.8.14</jacoco-maven-plugin.version>
2627
<maven-compiler-plugin.version>3.14.1</maven-compiler-plugin.version>
2728
<maven-gpg-plugin.version>3.2.8</maven-gpg-plugin.version>
@@ -31,6 +32,7 @@
3132
<maven-surefire-plugin.version>3.5.4</maven-surefire-plugin.version>
3233
<maven-failsafe-plugin.version>3.5.4</maven-failsafe-plugin.version>
3334
<mockito.version>5.20.0</mockito.version>
35+
<testcontainers.version>1.21.3</testcontainers.version>
3436
<central-publishing-maven-plugin.version>0.9.0</central-publishing-maven-plugin.version>
3537
</properties>
3638

@@ -75,8 +77,15 @@
7577
<artifactId>mockito-bom</artifactId>
7678
<version>${mockito.version}</version>
7779
<type>pom</type>
78-
<scope>test</scope>
80+
<scope>import</scope>
7981
</dependency>
82+
<dependency>
83+
<groupId>org.testcontainers</groupId>
84+
<artifactId>testcontainers-bom</artifactId>
85+
<version>${testcontainers.version}</version>
86+
<type>pom</type>
87+
<scope>import</scope>
88+
</dependency>
8089
</dependencies>
8190
</dependencyManagement>
8291

@@ -112,6 +121,12 @@
112121
<artifactId>flagd</artifactId>
113122
<version>${openfeature-contrib-providers-flagd.version}</version>
114123
</dependency>
124+
<dependency>
125+
<groupId>dev.openfeature.contrib.providers</groupId>
126+
<artifactId>go-feature-flag</artifactId>
127+
<version>${openfeature-contrib-providers-go-feature-flag.version}</version>
128+
</dependency>
129+
115130
<dependency>
116131
<groupId>io.dropwizard</groupId>
117132
<artifactId>dropwizard-testing</artifactId>
@@ -127,6 +142,21 @@
127142
<artifactId>mockito-junit-jupiter</artifactId>
128143
<scope>test</scope>
129144
</dependency>
145+
<dependency>
146+
<groupId>org.junit.jupiter</groupId>
147+
<artifactId>junit-jupiter</artifactId>
148+
<scope>test</scope>
149+
</dependency>
150+
<dependency>
151+
<groupId>org.testcontainers</groupId>
152+
<artifactId>junit-jupiter</artifactId>
153+
<scope>test</scope>
154+
</dependency>
155+
<dependency>
156+
<groupId>org.testcontainers</groupId>
157+
<artifactId>testcontainers</artifactId>
158+
<scope>test</scope>
159+
</dependency>
130160
</dependencies>
131161

132162
<build>
@@ -165,8 +195,7 @@
165195
<artifactId>maven-compiler-plugin</artifactId>
166196
<version>${maven-compiler-plugin.version}</version>
167197
<configuration>
168-
<source>${java.version}</source>
169-
<target>${java.version}</target>
198+
<release>${maven.compiler.release}</release>
170199
</configuration>
171200
</plugin>
172201
<plugin>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.github.sideshowcoder.dropwizard_openfeature;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProviderOptions;
6+
import dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProviderOptions.GoFeatureFlagProviderOptionsBuilder;
7+
import jakarta.validation.constraints.NotNull;
8+
9+
public class GoFeatureFlagConfiguration {
10+
11+
@JsonProperty
12+
@NotNull
13+
private String endpoint;
14+
15+
public GoFeatureFlagProviderOptions getGoFeatureFlagProviderOptions() {
16+
GoFeatureFlagProviderOptionsBuilder builder = GoFeatureFlagProviderOptions.builder();
17+
18+
builder.endpoint(endpoint);
19+
20+
return builder.build();
21+
}
22+
23+
}

src/main/java/io/github/sideshowcoder/dropwizard_openfeature/OpenFeatureBundle.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.github.sideshowcoder.dropwizard_openfeature;
22

33
import dev.openfeature.contrib.providers.flagd.FlagdProvider;
4+
import dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProvider;
5+
import dev.openfeature.contrib.providers.gofeatureflag.exception.InvalidOptions;
46
import dev.openfeature.sdk.Client;
57
import dev.openfeature.sdk.FeatureProvider;
68
import dev.openfeature.sdk.OpenFeatureAPI;
@@ -44,6 +46,13 @@ private synchronized void initializeFeatureProvider(OpenFeatureConfiguration con
4446
case FLAGD:
4547
featureProvider = new FlagdProvider(config.getFlagd().getFlagdOptions());
4648
break;
49+
case GOFEATUREFLAG:
50+
try {
51+
featureProvider = new GoFeatureFlagProvider(config.getGoFeatureFlag().getGoFeatureFlagProviderOptions());
52+
} catch(InvalidOptions e) {
53+
new RuntimeException(e);
54+
}
55+
break;
4756
}
4857
}
4958
}

src/main/java/io/github/sideshowcoder/dropwizard_openfeature/OpenFeatureConfiguration.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public class OpenFeatureConfiguration {
1111
@JsonProperty
1212
private FlagdConfiguration flagd = new FlagdConfiguration();
1313

14+
@Valid
15+
@JsonProperty
16+
private GoFeatureFlagConfiguration gofeatureflag = new GoFeatureFlagConfiguration();
17+
1418
@Valid
1519
@JsonProperty
1620
private OpenFeatureHealthCheckConfiguration healthcheck = new OpenFeatureHealthCheckConfiguration();
@@ -28,6 +32,14 @@ public void setFlagd(FlagdConfiguration flagd) {
2832
this.flagd = flagd;
2933
}
3034

35+
public GoFeatureFlagConfiguration getGoFeatureFlag() {
36+
return gofeatureflag;
37+
}
38+
39+
public void setGoFeatureFlag(GoFeatureFlagConfiguration gofeatureflag) {
40+
this.gofeatureflag = gofeatureflag;
41+
}
42+
3143
public OpenFeatureHealthCheckConfiguration getHealthcheck() {
3244
return healthcheck;
3345
}

src/main/java/io/github/sideshowcoder/dropwizard_openfeature/ProviderType.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
public enum ProviderType {
44
FLAGD,
5+
GOFEATUREFLAG,
56
INMEMORY;
67
}

src/test/java/io/github/sideshowcoder/dropwizard_openfeature/OpenFeatureBundleGoFeatureFlagProviderTest.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,37 @@
55

66
import org.junit.jupiter.api.Test;
77
import org.junit.jupiter.api.extension.ExtendWith;
8+
import org.testcontainers.containers.GenericContainer;
9+
import org.testcontainers.containers.wait.strategy.Wait;
10+
import org.testcontainers.junit.jupiter.Container;
11+
import org.testcontainers.junit.jupiter.Testcontainers;
12+
import org.testcontainers.utility.DockerImageName;
13+
import org.testcontainers.utility.MountableFile;
814

915
import com.codahale.metrics.health.HealthCheck;
1016

11-
import dev.openfeature.sdk.OpenFeatureAPI;
1217
import dev.openfeature.sdk.Client;
18+
import dev.openfeature.sdk.OpenFeatureAPI;
1319
import io.dropwizard.testing.ResourceHelpers;
1420
import io.dropwizard.testing.junit5.DropwizardAppExtension;
1521
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
1622
import io.github.sideshowcoder.dropwizard_openfeature.helpers.App;
1723
import io.github.sideshowcoder.dropwizard_openfeature.helpers.Config;
1824

25+
@Testcontainers
1926
@ExtendWith(DropwizardExtensionsSupport.class)
2027
public class OpenFeatureBundleGoFeatureFlagProviderTest {
2128

29+
@Container
30+
public GenericContainer goFeatureFlagRelay = new GenericContainer<>(DockerImageName.parse("gofeatureflag/go-feature-flag:latest"))
31+
.withExposedPorts(1031)
32+
.withCopyFileToContainer(MountableFile.forClasspathResource("goff-proxy.yaml"), "/goff/goff-proxy.yaml")
33+
.withCopyFileToContainer(MountableFile.forClasspathResource("go-feature-flags-flags.yaml"), "/goff/flags.yaml")
34+
.waitingFor(Wait.forHttp("/health"));
35+
36+
// TODO need to start container before dropwizard app! Need to bundle it in some kind of @BeforeAll or something to start the dropwizard app.
2237
// TODO start the gofeatureflag/go-feature-flag:latest docker image which is the relay proxy to interact with the provider https://gofeatureflag.org/docs/relay-proxy/getting_started
38+
// TODO set endpoint to the endpoint provider via the docker container
2339
// TODO create class to parse the configuration options see https://gofeatureflag.org/docs/relay-proxy/getting_started for available options
2440
// TODO how can I make this work on github? Can I start docker containers there?
2541

@@ -36,8 +52,7 @@ public void initializesHealthCheck() throws Exception {
3652

3753
@Test
3854
public void providesFeatureFlagsViaInMemoryProvider() throws Exception {
39-
// See flagd-test-flags.json for flag definitions used!
4055
Client client = OpenFeatureAPI.getInstance().getClient("go-feature-flag-client");
41-
assertEquals("red", client.getStringValue("static-string-flag", "not-expected-value"));
56+
assertEquals("red", client.getStringValue("staticstringflag", "not-expected-value"));
4257
}
4358
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
host: flagd
22
port: 8082
33
resolver: rpc
4-
cacheType: disabled
4+
cacheType: disabled
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
openfeature:
2+
provider: gofeatureflag
3+
gofeatureflag:
4+
endpoint: "http://localhost:1031/"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
staticstringflag:
2+
variations:
3+
red: "red"
4+
green: "green"
5+
blue: "blue"
6+
defaultRule:
7+
variation: red

src/test/resources/goff-proxy.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
retrievers:
2+
- kind: file
3+
path: /goff/flags.yaml

0 commit comments

Comments
 (0)