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
2 changes: 0 additions & 2 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,3 @@ jobs:
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}


3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Ignore generated protobuf Java sources vendored during local build
openfeature-provider/java/src/main/java/com/spotify/confidence/wasm/Messages.java
.DS_Store
*.stamp
.idea/

target/
wasm/confidence_resolver.wasm
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
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"}
54 changes: 52 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,54 @@ FROM openfeature-provider-js-base AS openfeature-provider-js.build

RUN make build

# ==============================================================================
# OpenFeature Provider (Java) - Build and test
# ==============================================================================
FROM eclipse-temurin:17-jdk AS openfeature-provider-java-base

# Install Maven and protobuf (Debian-based for glibc compatibility)
RUN apt-get update && apt-get install -y \
maven \
protobuf-compiler \
make \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Copy pom.xml for dependency caching
COPY openfeature-provider/java/pom.xml ./
COPY openfeature-provider/java/Makefile ./

# Download dependencies (this layer will be cached)
RUN mvn dependency:go-offline -q || true

# Copy proto files (needed for protobuf generation)
COPY confidence-resolver/protos ../../confidence-resolver/protos/
COPY wasm/proto ../../wasm/proto/

# Copy source code
COPY openfeature-provider/java/src ./src/

# Copy WASM module into resources
COPY --from=wasm-rust-guest.artifact /confidence_resolver.wasm ./src/main/resources/wasm/confidence_resolver.wasm

# Set environment variable
ENV IN_DOCKER_BUILD=1

# ==============================================================================
# Test OpenFeature Provider (Java)
# ==============================================================================
FROM openfeature-provider-java-base AS openfeature-provider-java.test

RUN make test

# ==============================================================================
# Build OpenFeature Provider (Java)
# ==============================================================================
FROM openfeature-provider-java-base AS openfeature-provider-java.build

RUN make build

# ==============================================================================
# All - Build and validate everything (default target)
# ==============================================================================
Expand All @@ -411,7 +459,8 @@ COPY --from=wasm-rust-guest.artifact /confidence_resolver.wasm /artifacts/wasm/
# Force test stages to run by copying marker files
COPY --from=confidence-resolver.test /workspace/Cargo.toml /markers/test-resolver
COPY --from=wasm-msg.test /workspace/Cargo.toml /markers/test-wasm-msg
COPY --from=openfeature-provider-js.test /app/package.json /markers/test-openfeature
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good!

COPY --from=openfeature-provider-js.test /app/package.json /markers/test-openfeature-js
COPY --from=openfeature-provider-java.test /app/pom.xml /markers/test-openfeature-java

# Force integration test stages to run (host examples)
COPY --from=node-host.test /app/package.json /markers/integration-node
Expand All @@ -425,5 +474,6 @@ COPY --from=wasm-msg.lint /workspace/Cargo.toml /markers/lint-wasm-msg
COPY --from=wasm-rust-guest.lint /workspace/Cargo.toml /markers/lint-guest

# Force build stages to run
COPY --from=openfeature-provider-js.build /app/dist/index.node.js /artifacts/openfeature/
COPY --from=openfeature-provider-js.build /app/dist/index.node.js /artifacts/openfeature-js/
COPY --from=openfeature-provider-java.build /app/target/*.jar /artifacts/openfeature-java/
COPY --from=confidence-cloudflare-resolver.lint /workspace/Cargo.toml /markers/lint-cloudflare
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ test:
$(MAKE) -C confidence-resolver test
$(MAKE) -C wasm-msg test
$(MAKE) -C openfeature-provider/js test
$(MAKE) -C openfeature-provider/java test

integration-test:
$(MAKE) -C wasm/node-host run
$(MAKE) -C wasm/java-host run
$(MAKE) -C wasm/go-host run
$(MAKE) -C wasm/python-host run
$(MAKE) -C wasm/java-host run


lint:
Expand All @@ -33,6 +35,7 @@ lint:

build: wasm/confidence_resolver.wasm
$(MAKE) -C openfeature-provider/js build
$(MAKE) -C openfeature-provider/java build

all: lint test build
@echo "✅ All checks passed!"
Expand All @@ -44,5 +47,6 @@ clean:
$(MAKE) -C wasm/go-host clean
$(MAKE) -C wasm/python-host clean
$(MAKE) -C openfeature-provider/js clean
$(MAKE) -C openfeature-provider/java clean

.DEFAULT_GOAL := all
18 changes: 18 additions & 0 deletions confidence-resolver/protos/google/api/httpbody.proto
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;
}


8 changes: 8 additions & 0 deletions openfeature-provider/java/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions openfeature-provider/java/Makefile
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)


101 changes: 101 additions & 0 deletions openfeature-provider/java/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Confidence OpenFeature Local Provider

![Status: Experimental](https://img.shields.io/badge/status-experimental-orange)

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+
Loading