Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
<description>OpenFeature bundle for Dropwizard</description>

<properties>
<!-- Support Java 8 as the same language level supported by the Openfeature SDK -->
<java.version>8</java.version>
<!-- Support Java 11 as the same language level supported by the Openfeature SDK -->
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<dropwizard.version>5.0.0</dropwizard.version>
<openfeature-sdk.version>1.18.2</openfeature-sdk.version>
<openfeature-contrib-providers-flagd.version>0.11.17</openfeature-contrib-providers-flagd.version>
<openfeature-contrib-providers-go-feature-flag.version>1.0.1</openfeature-contrib-providers-go-feature-flag.version>
<jacoco-maven-plugin.version>0.8.14</jacoco-maven-plugin.version>
<maven-compiler-plugin.version>3.14.1</maven-compiler-plugin.version>
<maven-gpg-plugin.version>3.2.8</maven-gpg-plugin.version>
Expand All @@ -31,6 +32,7 @@
<maven-surefire-plugin.version>3.5.4</maven-surefire-plugin.version>
<maven-failsafe-plugin.version>3.5.4</maven-failsafe-plugin.version>
<mockito.version>5.20.0</mockito.version>
<testcontainers.version>1.21.3</testcontainers.version>
<central-publishing-maven-plugin.version>0.9.0</central-publishing-maven-plugin.version>
</properties>

Expand Down Expand Up @@ -75,8 +77,15 @@
<artifactId>mockito-bom</artifactId>
<version>${mockito.version}</version>
<type>pom</type>
<scope>test</scope>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-bom</artifactId>
<version>${testcontainers.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -112,6 +121,12 @@
<artifactId>flagd</artifactId>
<version>${openfeature-contrib-providers-flagd.version}</version>
</dependency>
<dependency>
<groupId>dev.openfeature.contrib.providers</groupId>
<artifactId>go-feature-flag</artifactId>
<version>${openfeature-contrib-providers-go-feature-flag.version}</version>
</dependency>

<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-testing</artifactId>
Expand All @@ -127,6 +142,21 @@
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -165,8 +195,7 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<release>${maven.compiler.release}</release>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.sideshowcoder.dropwizard_openfeature;

import com.fasterxml.jackson.annotation.JsonProperty;

import dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProviderOptions;
import dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProviderOptions.GoFeatureFlagProviderOptionsBuilder;
import dev.openfeature.contrib.providers.gofeatureflag.exception.InvalidOptions;
import jakarta.validation.constraints.NotNull;

public class GoFeatureFlagConfiguration {

@JsonProperty
@NotNull
private String endpoint;

public GoFeatureFlagProviderOptions getGoFeatureFlagProviderOptions() throws InvalidOptions {
GoFeatureFlagProviderOptionsBuilder builder = GoFeatureFlagProviderOptions.builder();

builder.endpoint(endpoint);

GoFeatureFlagProviderOptions options = builder.build();
options.validate();
return options;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package io.github.sideshowcoder.dropwizard_openfeature;

import dev.openfeature.contrib.providers.flagd.FlagdProvider;
import dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProvider;
import dev.openfeature.contrib.providers.gofeatureflag.GoFeatureFlagProviderOptions;
import dev.openfeature.contrib.providers.gofeatureflag.exception.InvalidOptions;
import dev.openfeature.sdk.Client;
import dev.openfeature.sdk.FeatureProvider;
import dev.openfeature.sdk.OpenFeatureAPI;
Expand Down Expand Up @@ -44,6 +47,13 @@ private synchronized void initializeFeatureProvider(OpenFeatureConfiguration con
case FLAGD:
featureProvider = new FlagdProvider(config.getFlagd().getFlagdOptions());
break;
case GOFEATUREFLAG:
try {
featureProvider = new GoFeatureFlagProvider(config.getGoFeatureFlag().getGoFeatureFlagProviderOptions());
} catch(InvalidOptions e) {
new RuntimeException(e);
}
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class OpenFeatureConfiguration {
@JsonProperty
private FlagdConfiguration flagd = new FlagdConfiguration();

@Valid
@JsonProperty
private GoFeatureFlagConfiguration gofeatureflag = new GoFeatureFlagConfiguration();

@Valid
@JsonProperty
private OpenFeatureHealthCheckConfiguration healthcheck = new OpenFeatureHealthCheckConfiguration();
Expand All @@ -28,6 +32,14 @@ public void setFlagd(FlagdConfiguration flagd) {
this.flagd = flagd;
}

public GoFeatureFlagConfiguration getGoFeatureFlag() {
return gofeatureflag;
}

public void setGoFeatureFlag(GoFeatureFlagConfiguration gofeatureflag) {
this.gofeatureflag = gofeatureflag;
}

public OpenFeatureHealthCheckConfiguration getHealthcheck() {
return healthcheck;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public enum ProviderType {
FLAGD,
GOFEATUREFLAG,
INMEMORY;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.github.sideshowcoder.dropwizard_openfeature;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.List;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

import com.codahale.metrics.health.HealthCheck;

import dev.openfeature.sdk.Client;
import dev.openfeature.sdk.EvaluationContext;
import dev.openfeature.sdk.ImmutableContext;
import dev.openfeature.sdk.OpenFeatureAPI;
import io.dropwizard.testing.ResourceHelpers;
import io.dropwizard.testing.junit5.DropwizardAppExtension;
import io.dropwizard.testing.junit5.DropwizardExtensionsSupport;
import io.github.sideshowcoder.dropwizard_openfeature.helpers.App;
import io.github.sideshowcoder.dropwizard_openfeature.helpers.Config;

@Testcontainers
@ExtendWith(DropwizardExtensionsSupport.class)
public class OpenFeatureBundleGoFeatureFlagProviderTest {

@Container
private static GenericContainer<?> goFeatureFlagRelay = createGoFeatureFlagContainer();

private static GenericContainer<?> createGoFeatureFlagContainer() {
GenericContainer<?> container = new GenericContainer<>(DockerImageName.parse("gofeatureflag/go-feature-flag:latest"))
.withCopyFileToContainer(MountableFile.forClasspathResource("goff-proxy.yaml"), "/goff/goff-proxy.yaml")
.withCopyFileToContainer(MountableFile.forClasspathResource("go-feature-flags-flags.yaml"), "/goff/flags.yaml");

container.setPortBindings(List.of("1031:1031"));
container.waitingFor(Wait.forHttp("/health"));

return container;
}

private static final DropwizardAppExtension<Config> APP = new DropwizardAppExtension<>(
App.class,
ResourceHelpers.resourceFilePath("go-feature-flag-provider-config.yml")
);

@Test
public void initializesHealthCheck() throws Exception {
HealthCheck.Result healthcheckResult = APP.getEnvironment().healthChecks().runHealthCheck("openfeature-health-check");
assertTrue(healthcheckResult.isHealthy());
}

@Test
public void providesFeatureFlagsViaInMemoryProvider() throws Exception {
Client client = OpenFeatureAPI.getInstance().getClient("go-feature-flag-client");
// GoFeatureFlags requires a target key for all queries!
EvaluationContext ctx = new ImmutableContext("target");
assertEquals("red", client.getStringValue("staticstringflag", "not-expected-value", ctx));
}
}
2 changes: 1 addition & 1 deletion src/test/resources/basic-flagd-config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
host: flagd
port: 8082
resolver: rpc
cacheType: disabled
cacheType: disabled
4 changes: 4 additions & 0 deletions src/test/resources/go-feature-flag-provider-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
openfeature:
provider: gofeatureflag
gofeatureflag:
endpoint: "http://localhost:1031/"
7 changes: 7 additions & 0 deletions src/test/resources/go-feature-flags-flags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
staticstringflag:
variations:
red: "red"
green: "green"
blue: "blue"
defaultRule:
variation: red
3 changes: 3 additions & 0 deletions src/test/resources/goff-proxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
retrievers:
- kind: file
path: /goff/flags.yaml