-
Notifications
You must be signed in to change notification settings - Fork 59
feat: add Unleash provider #424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b62cbb2
add Unleash provider
liran2000 8ef55ff
add getVariant and getStringEvaluation support
liran2000 e97a55e
update readme with getStringValue usage
liran2000 3a00847
set variant and some refactor
liran2000 5eef0e2
- some fixes
liran2000 f67742a
update WireMock version to match SDK Java version
liran2000 92e3a62
add shutdown method
liran2000 8a63167
tests updates
liran2000 99dd6a7
- focused test features
liran2000 8f93bbb
enhancements
liran2000 1ddfd61
enhance test
liran2000 9b2b7b8
Remove dependencies on Unleash and Unleash provider from client usage
liran2000 2d7839b
Update readme
liran2000 61f1458
Merge branch 'main' into feature/unleash
liran2000 769be63
Rename config
liran2000 0be637c
Merge branch 'main' into feature/unleash
toddbaert c0ddb56
Update providers/unleash/README.md
toddbaert 4a61e9c
update owners and test
liran2000 e50eaff
update version to alpha
liran2000 11ccc56
Merge branch 'main' into feature/unleash
toddbaert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Unofficial Unleash OpenFeature Provider for Java | ||
|
|
||
| [Unleash](https://getunleash.io) OpenFeature Provider can provide usage for Unleash via OpenFeature Java SDK. | ||
|
|
||
| ## Installation | ||
|
|
||
| <!-- x-release-please-start-version --> | ||
|
|
||
| ```xml | ||
|
|
||
| <dependency> | ||
| <groupId>dev.openfeature.contrib.providers</groupId> | ||
| <artifactId>unleash</artifactId> | ||
| <version>0.0.1-alpha</version> | ||
| </dependency> | ||
| ``` | ||
|
|
||
| <!-- x-release-please-end-version --> | ||
|
|
||
| ## Concepts | ||
| * Boolean evaluation gets feature enabled status. | ||
| * String evaluation gets feature variant value. | ||
|
|
||
| ## Usage | ||
| Unleash OpenFeature Provider is using Unleash Java SDK. | ||
|
|
||
| ### Usage Example | ||
|
|
||
| ``` | ||
| FeatureProvider unleashProvider = new UnleashProvider(unleashProviderConfig); | ||
| OpenFeatureAPI.getInstance().setProviderAndWait(unleashProvider); | ||
| boolean featureEnabled = client.getBooleanValue(FLAG_NAME, false); | ||
|
|
||
| // Context parameters are optional, not mandatory to fill all parameters | ||
| MutableContext evaluationContext = new MutableContext(); | ||
| evaluationContext.add("userId", userIdValue); | ||
| evaluationContext.add("currentTime", String.valueOf(currentTimeValue)); | ||
| evaluationContext.add("sessionId", sessionIdValue); | ||
| evaluationContext.add("remoteAddress", remoteAddressValue); | ||
| evaluationContext.add("environment", environmentValue); | ||
| evaluationContext.add("appName", appNameValue); | ||
| evaluationContext.add(customPropertyKey, customPropertyValue); | ||
| featureEnabled = client.getBooleanValue(FLAG_NAME, false, evaluationContext); | ||
|
|
||
| String variantValue = client.getStringValue(FLAG_NAME, ""); | ||
| ``` | ||
|
|
||
| See [UnleashProviderTest.java](./src/test/java/dev/openfeature/contrib/providers/unleash/UnleashProviderTest.java) for more information. | ||
|
|
||
| ### Additional Usage Details | ||
|
|
||
| * When default value is used and returned, default variant is not used and variant name is not set. | ||
| * json/csv payloads are evaluated via object evaluation as what returned from Unleash - string, wrapped with Value. | ||
| * Additional evaluation data can be received via flag metadata, such as: | ||
| * *enabled* - boolean | ||
| * *variant-stickiness* - string | ||
| * *payload-type* - string, optional | ||
|
|
||
| ## Unleash Provider Tests Strategies | ||
|
|
||
| Unit test based on Unleash instance with Unleash features schema file, with WireMock for API mocking. | ||
| See [UnleashProviderTest.java](./src/test/java/dev/openfeature/contrib/providers/unleash/UnleashProviderTest.java) for more information. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # This file is needed to avoid errors throw by findbugs when working with lombok. | ||
| lombok.addSuppressWarnings = true | ||
| lombok.addLombokGeneratedAnnotation = true | ||
| config.stopBubbling = true | ||
| lombok.extern.findbugs.addSuppressFBWarnings = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>dev.openfeature.contrib</groupId> | ||
| <artifactId>parent</artifactId> | ||
| <version>0.1.0</version> | ||
| <relativePath>../../pom.xml</relativePath> | ||
| </parent> | ||
| <groupId>dev.openfeature.contrib.providers</groupId> | ||
| <artifactId>unleash</artifactId> | ||
| <version>0.0.1-alpha</version> <!--x-release-please-version --> | ||
|
|
||
| <name>unleash</name> | ||
| <description>unleash provider for Java</description> | ||
| <url>https://www.getunleash.io/</url> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.getunleash</groupId> | ||
| <artifactId>unleash-client-java</artifactId> | ||
| <version>8.3.1</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.slf4j</groupId> | ||
| <artifactId>slf4j-api</artifactId> | ||
| <version>2.0.9</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>com.github.tomakehurst</groupId> | ||
| <artifactId>wiremock-jre8</artifactId> | ||
| <version>2.35.1</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-slf4j2-impl</artifactId> | ||
| <version>2.20.0</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| </dependencies> | ||
| </project> |
50 changes: 50 additions & 0 deletions
50
...s/unleash/src/main/java/dev/openfeature/contrib/providers/unleash/ContextTransformer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package dev.openfeature.contrib.providers.unleash; | ||
|
|
||
| import dev.openfeature.sdk.EvaluationContext; | ||
| import io.getunleash.UnleashContext; | ||
|
|
||
| import java.time.ZonedDateTime; | ||
|
|
||
| /** | ||
| * Transformer from Unleash context to OpenFeature context and vice versa. | ||
| */ | ||
| public class ContextTransformer { | ||
|
|
||
| public static final String CONTEXT_APP_NAME = "appName"; | ||
| public static final String CONTEXT_USER_ID = "userId"; | ||
| public static final String CONTEXT_ENVIRONMENT = "environment"; | ||
| public static final String CONTEXT_REMOTE_ADDRESS = "remoteAddress"; | ||
| public static final String CONTEXT_SESSION_ID = "sessionId"; | ||
| public static final String CONTEXT_CURRENT_TIME = "currentTime"; | ||
|
|
||
| protected static UnleashContext transform(EvaluationContext ctx) { | ||
| UnleashContext.Builder unleashContextBuilder = new UnleashContext.Builder(); | ||
| ctx.asObjectMap().forEach((k, v) -> { | ||
| switch (k) { | ||
| case CONTEXT_APP_NAME: | ||
| unleashContextBuilder.appName(String.valueOf(v)); | ||
| break; | ||
| case CONTEXT_USER_ID: | ||
| unleashContextBuilder.userId(String.valueOf(v)); | ||
| break; | ||
| case CONTEXT_ENVIRONMENT: | ||
| unleashContextBuilder.environment(String.valueOf(v)); | ||
| break; | ||
| case CONTEXT_REMOTE_ADDRESS: | ||
| unleashContextBuilder.remoteAddress(String.valueOf(v)); | ||
| break; | ||
| case CONTEXT_SESSION_ID: | ||
| unleashContextBuilder.sessionId(String.valueOf(v)); | ||
| break; | ||
| case CONTEXT_CURRENT_TIME: | ||
| unleashContextBuilder.currentTime(ZonedDateTime.parse(String.valueOf(v))); | ||
toddbaert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| break; | ||
| default: | ||
| unleashContextBuilder.addProperty(k, String.valueOf(v)); | ||
| break; | ||
| } | ||
| }); | ||
| return unleashContextBuilder.build(); | ||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.