-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add Java OpenFeature provider #58
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
+4,177
−8
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
433f520
feat: Add Java OpenFeature provider
fabriziodemaria f1bceb6
fix: Proto compilation in Java provider
fabriziodemaria 2db9625
fix: Ignore idea
fabriziodemaria 3d9a2f0
feat: Java provider deploy
fabriziodemaria b6dbd62
feat: Integrate Java into CI validation
fabriziodemaria 2ebe795
fix: Disable Maven deploys
fabriziodemaria db98824
fix: Fix Docker CI for Java
fabriziodemaria b571554
ci: Fix compatibility error with alpine
fabriziodemaria 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,5 +127,3 @@ jobs: | |
platforms: linux/amd64 | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"confidence-resolver":"0.5.2","confidence-cloudflare-resolver":"0.2.7","wasm-msg":"0.2.0","wasm/rust-guest":"0.1.8"} | ||
{"confidence-resolver":"0.5.2","confidence-cloudflare-resolver":"0.2.7","wasm-msg":"0.2.0","wasm/rust-guest":"0.1.8","openfeature-provider-local-java":"0.6.4"} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
syntax = "proto3"; | ||
|
||
package google.api; | ||
|
||
import "google/protobuf/any.proto"; | ||
|
||
option java_package = "com.google.api"; | ||
option java_multiple_files = true; | ||
option java_outer_classname = "HttpBodyProto"; | ||
|
||
// Minimal HttpBody to satisfy imports during local builds | ||
message HttpBody { | ||
string content_type = 1; | ||
bytes data = 2; | ||
repeated google.protobuf.Any extensions = 3; | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,59 @@ | ||
# openfeature-provider/java Makefile | ||
# Java OpenFeature local provider | ||
|
||
ROOT := $(realpath $(CURDIR)/../..) | ||
|
||
# Stamps and inputs | ||
BUILD_STAMP := .build.stamp | ||
INSTALL_STAMP := .install.stamp | ||
SRC := $(shell find src -name '*.java' 2>/dev/null) | ||
RESOURCES_WASM := src/main/resources/wasm/confidence_resolver.wasm | ||
LOCAL_WASM := $(ROOT)/wasm/confidence_resolver.wasm | ||
GEN_MESSAGES := target/generated-sources/protobuf/java/com/spotify/confidence/wasm/Messages.java | ||
|
||
.PHONY: install build test clean | ||
|
||
# Always build/copy wasm when not in Docker; inside Docker we rely on COPY from Dockerfile | ||
ifneq ($(IN_DOCKER_BUILD),1) | ||
.PHONY: $(LOCAL_WASM) | ||
|
||
$(LOCAL_WASM): | ||
$(MAKE) -C $(ROOT) wasm/confidence_resolver.wasm | ||
|
||
$(RESOURCES_WASM): $(LOCAL_WASM) | ||
@mkdir -p $(dir $@) | ||
cp $(LOCAL_WASM) $@ | ||
else | ||
# In Docker, the WASM is already copied into src/main/resources by the Dockerfile | ||
$(RESOURCES_WASM): | ||
@mkdir -p $(dir $@) | ||
@test -f $@ || (echo "Missing $@ (expected via Docker COPY)"; exit 1) | ||
endif | ||
|
||
# A lightweight install target to prep resources | ||
$(INSTALL_STAMP): pom.xml $(RESOURCES_WASM) | ||
touch $@ | ||
|
||
|
||
$(BUILD_STAMP): $(INSTALL_STAMP) pom.xml $(SRC) | ||
mvn -q -DskipTests protobuf:compile | ||
@if [ -f "$(GEN_MESSAGES)" ]; then \ | ||
mkdir -p src/main/java/com/spotify/confidence/wasm; \ | ||
cp $(GEN_MESSAGES) src/main/java/com/spotify/confidence/wasm/Messages.java; \ | ||
fi | ||
mvn -q -DskipTests package | ||
touch $@ | ||
|
||
install: $(INSTALL_STAMP) | ||
|
||
build: $(BUILD_STAMP) | ||
|
||
test: $(INSTALL_STAMP) | ||
mvn -q test | ||
|
||
clean: | ||
mvn -q clean | ||
rm -f $(BUILD_STAMP) $(INSTALL_STAMP) | ||
rm -f $(RESOURCES_WASM) | ||
|
||
|
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,101 @@ | ||
# Confidence OpenFeature Local Provider | ||
|
||
 | ||
|
||
A high-performance OpenFeature provider for [Confidence](https://confidence.spotify.com/) feature flags that evaluates flags locally for minimal latency. | ||
|
||
## Features | ||
|
||
- **Local Resolution**: Evaluates feature flags locally using WebAssembly (WASM) | ||
- **Low Latency**: No network calls during flag evaluation | ||
- **Automatic Sync**: Periodically syncs flag configurations from Confidence | ||
- **Exposure Logging**: Fully supported exposure logging (and other resolve analytics) | ||
- **OpenFeature Compatible**: Works with the standard OpenFeature SDK | ||
|
||
## Installation | ||
|
||
Add this dependency to your `pom.xml`: | ||
<!-- x-release-please-start-version --> | ||
```xml | ||
<dependency> | ||
<groupId>com.spotify.confidence</groupId> | ||
<artifactId>openfeature-provider-local</artifactId> | ||
<version>0.6.4</version> | ||
</dependency> | ||
``` | ||
<!-- x-release-please-end --> | ||
|
||
## Quick Start | ||
|
||
```java | ||
import com.spotify.confidence.ApiSecret; | ||
import com.spotify.confidence.OpenFeatureLocalResolveProvider; | ||
import dev.openfeature.sdk.OpenFeatureAPI; | ||
import dev.openfeature.sdk.Client; | ||
|
||
// Create API credentials | ||
ApiSecret apiSecret = new ApiSecret("your-client-id", "your-client-secret"); | ||
String clientSecret = "your-application-client-secret"; | ||
|
||
// Create and register the provider | ||
OpenFeatureLocalResolveProvider provider = | ||
new OpenFeatureLocalResolveProvider(apiSecret, clientSecret); | ||
OpenFeatureAPI.getInstance().setProvider(provider); | ||
|
||
// Use OpenFeature client | ||
Client client = OpenFeatureAPI.getInstance().getClient(); | ||
String value = client.getStringValue("my-flag", "default-value"); | ||
``` | ||
|
||
## Configuration | ||
|
||
|
||
### Exposure Logging | ||
|
||
Enable or disable exposure logging: | ||
|
||
```java | ||
// Enable exposure logging (default) | ||
new OpenFeatureLocalResolveProvider(apiSecret, clientSecret, true); | ||
|
||
// Disable exposure logging | ||
new OpenFeatureLocalResolveProvider(apiSecret, clientSecret, false); | ||
``` | ||
|
||
## Credentials | ||
|
||
You need two types of credentials: | ||
|
||
1. **API Secret** (`ApiSecret`): For authenticating with the Confidence API | ||
- Contains `clientId` and `clientSecret` for your Confidence application | ||
|
||
2. **Client Secret** (`String`): For flag resolution authentication | ||
- Application-specific secret for flag evaluation | ||
|
||
Both can be obtained from your Confidence dashboard. | ||
|
||
## Sticky Resolve | ||
|
||
The provider supports **Sticky Resolve** for consistent variant assignments across flag evaluations. This ensures users receive the same variant even when their targeting attributes change, and enables pausing experiment intake. | ||
|
||
**By default, sticky assignments are managed by Confidence servers.** When sticky assignment data is needed, the provider makes a network call to Confidence, which maintains the sticky repository server-side with automatic 90-day TTL management. This is a fully supported production approach that requires no additional setup. | ||
|
||
|
||
Optionally, you can implement a custom `MaterializationRepository` to manage sticky assignments in your own storage (Redis, database, etc.) to eliminate network calls and improve latency: | ||
|
||
```java | ||
// Optional: Custom storage for sticky assignments | ||
MaterializationRepository repository = new RedisMaterializationRepository(jedisPool, "myapp"); | ||
OpenFeatureLocalResolveProvider provider = new OpenFeatureLocalResolveProvider( | ||
apiSecret, | ||
clientSecret, | ||
repository | ||
); | ||
``` | ||
|
||
For detailed information on how sticky resolve works and how to implement custom storage backends, see [STICKY_RESOLVE.md](STICKY_RESOLVE.md). | ||
|
||
## Requirements | ||
|
||
- Java 17+ | ||
- OpenFeature SDK 1.6.1+ |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good!