Skip to content

Java: Add OpenFeature provider#59

Open
msiebert wants to merge 11 commits intomasterfrom
msiebert-openfeature-provider
Open

Java: Add OpenFeature provider#59
msiebert wants to merge 11 commits intomasterfrom
msiebert-openfeature-provider

Conversation

@msiebert
Copy link
Copy Markdown
Contributor

Summary

  • Adds an OpenFeature provider (MixpanelProvider) as a separate Maven subproject (openfeature-provider/) that wraps the Mixpanel Java SDK's BaseFlagsProvider
  • Implements all five OpenFeature evaluation types: boolean, string, integer, double, and object
  • Uses OpenFeature Java SDK dev.openfeature:sdk:1.20.1

Design Decisions

  • Wraps BaseFlagsProvider: Accepts any flags provider (local or remote) via the constructor
  • Global context via initialize(): Context is set once through the OpenFeature initialize(EvaluationContext) lifecycle method and stored in a field. Per-evaluation context parameters are ignored.
  • PROVIDER_NOT_READY for local providers: When wrapping a LocalFlagsProvider, checks areFlagsReady() before each evaluation. Skipped for remote providers (always ready).
  • STATIC reason: All successful resolutions use reason STATIC; all failures use ERROR
  • targetingKey not special: Treated as a regular context property — no mapping to distinct_id
  • Error codes: FLAG_NOT_FOUND (fallback returned), TYPE_MISMATCH (wrong type), PROVIDER_NOT_READY (local flags not loaded), GENERAL (exceptions)
  • Numeric coercion: Integer evaluation accepts Long/Double with overflow protection; Double evaluation accepts Integer/Long
  • shutdown() is a no-op

Test Coverage

29 tests covering:

  • All five flag types (boolean, string, integer, double, object) — success and type mismatch
  • Flag-not-found for all types
  • PROVIDER_NOT_READY with LocalFlagsProvider (ready and not ready)
  • PROVIDER_NOT_READY skipped for non-local providers
  • Global context set via initialize, per-eval context ignored
  • targetingKey passed as regular property
  • Integer overflow returns TYPE_MISMATCH
  • Exception handling returns default values
  • Metadata name and shutdown no-op

Test plan

  • mvn test in openfeature-provider/ — 29/29 passing

🤖 Generated with Claude Code

Implements an OpenFeature FeatureProvider that wraps BaseFlagsProvider,
enabling Mixpanel feature flags to be used via the OpenFeature standard.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@msiebert msiebert self-assigned this Mar 19, 2026
msiebert and others added 2 commits March 20, 2026 11:05
The OpenFeature SDK merges all context layers before calling the
provider. The provider was ignoring this merged context and using a
stored global context from initialize(). Now uses convertContext(ctx)
in evaluate() and getObjectEvaluation(). Also adds variant key
passthrough and null variant key tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- shutdown() now delegates to underlying flags provider via shutdown()
- Add shutdown() to BaseFlagsProvider (no-op) and LocalFlagsProvider (calls close())
- Reject non-whole decimals in integer coercion (42.5 → TYPE_MISMATCH)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@msiebert msiebert changed the title Add OpenFeature provider Java: Add OpenFeature provider Mar 31, 2026
msiebert and others added 8 commits April 1, 2026 12:49
Extract fetchVariant, errorResult, and successResult helpers to
eliminate 6 duplicated builder patterns. Add proper imports for
Arrays and ArrayList. Extract buildResult in LocalFlagsProvider
to consolidate variant construction and exposure tracking. Simplify
isQaTester tracking and collapse nested runtime condition checks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ants

Extract targetingKey from EvaluationContext.getTargetingKey() explicitly
in convertContext. Add Object[] array handling in objectToValue. Replace
string literal reasons with Reason.STATIC and Reason.ERROR constants.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rename artifact from mixpanel-java-openfeature-provider to
mixpanel-java-openfeature, give it its own version (0.1.0) independent
of the main SDK, and add Maven Central publishing plugins (source,
javadoc, GPG signing, central-publishing).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Org policy requires actions pinned to full-length commit SHAs instead of
version tags. Also skip GPG signing when installing the core library
locally in the OpenFeature provider job.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
OpenFeature SDK 1.20.1 requires Java 11+ (class version 55.0), so the
provider cannot compile under Java 8.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fixes CodeQL actions/missing-workflow-permissions alert by declaring
explicit read-only contents permission.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Deduplicate getObjectEvaluation and evaluate by extracting shared logic
into a common evaluate method that accepts a mapper function. Also log
exceptions during shutdown instead of silently ignoring them.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@msiebert msiebert marked this pull request as ready for review April 3, 2026 05:17
@msiebert msiebert requested review from a team and rahul-mixpanel April 3, 2026 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant