Skip to content

Commit

Permalink
POC Kotlin provider (#1213)
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Poignant <[email protected]>
  • Loading branch information
thomaspoignant authored Nov 4, 2023
1 parent 1647739 commit bfa5ef1
Show file tree
Hide file tree
Showing 26 changed files with 952 additions and 0 deletions.
15 changes: 15 additions & 0 deletions openfeature/providers/kotlin-provider/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
93 changes: 93 additions & 0 deletions openfeature/providers/kotlin-provider/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# GO Feature Flag Kotlin OpenFeature Provider for Android

![Static Badge](https://img.shields.io/badge/status-experimental-red)

This OpenFeature provider is a Kotlin implementation for Android to communicate with the GO Feature
Flag Server.

The OpenFeature Kotlin is experimental, and the provider is also experimental.
We don't recommend using this in production yet.

## About this provider

[GO Feature Flag](https://gofeatureflag.org) provider allows you to connect to your GO Feature Flag
instance with the OpenFeature Kotlin SDK.

This is a client provider made for Android, we do not recommend using it in a server environment.
If you want to use it in a server environment, you should use
the [`Java` provider](https://gofeatureflag.org/docs/openfeature_sdk/server_providers/openfeature_java).

## What is GO Feature Flag?

GO Feature Flag is a simple, complete and lightweight self-hosted feature flag solution 100% Open
Source.
Our focus is to avoid any complex infrastructure work to use GO Feature Flag.

This is a complete feature flagging solution with the possibility to target only a group of users,
use any types of flags, store your configuration in various location and advanced rollout
functionality. You can also collect usage data of your flags and be notified of configuration
changes.

## Install the provider

TODO

## How to use the provider?

```kotlin
val evaluationContext = ImmutableContext(
targetingKey = "0a23d9a5-0a8f-42c9-9f5f-4de3afd6cf99",
attributes = mutableMapOf(
"region" to Value.String("us-east-1"),
"email" to Value.String("[email protected]")
)
)

OpenFeatureAPI.setProvider(
GoFeatureFlagProvider(
options = GoFeatureFlagOptions(
endpoint = "http://localhost:1031"
)
), evaluationContext
)

val client = OpenFeatureAPI.getClient("my-client")
if (client.getBooleanValue("my-flag", false)) {
println("my-flag is enabled")
}
OpenFeatureAPI.shutdown()
```

### Available options

| Option name | Type | Default | Description |
|--------------------|--------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| endpoint | String | | endpoint is the URL where your GO Feature Flag server is located. |
| timeout | Long | 10000 | (optional) timeout is the time in millisecond we wait for an answer from the server. |
| maxIdleConnections | Int | 1000 | (optional) maxIdleConnections is the maximum number of connexions in the connexion pool. |
| keepAliveDuration | Long | 7200000 | (optional) keepAliveDuration is the time in millisecond we keep the connexion open. |
| apiKey | String | | (optional) If GO Feature Flag is configured to authenticate the requests, you should provide an API Key to the provider. Please ask the administrator of the relay proxy to provide an API Key. |
| retryDelay | Long | 300 | (optional) delay in millisecond to wait before retrying to connect the websocket |

### Reconnection

If the connection to the GO Feature Flag instance fails, the provider will attempt to reconnect.

### Event streaming

Event streaming is not implemented yet in the GO Feature Flag provider.

## Features status

| Status | Feature | Description |
|--------|--------------------|--------------------------------------------------------------------------------------|
|| Flag evaluation | It is possible to evaluate all the type of flags |
|| Cache invalidation | Websocket mechanism is in place to refresh the cache in case of configuration change |
|| Logging | Not supported by the SDK |
|| Flag Metadata | Not supported by the SDK |
|| Event Streaming | Not implemented |
|| Unit test | Not implemented |

<sub>Implemented: ✅ | In-progress: ⚠️ | Not implemented yet: ❌</sub>


14 changes: 14 additions & 0 deletions openfeature/providers/kotlin-provider/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.1.2" apply false
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
id("com.android.library") version "8.1.2" apply false
}

allprojects {
extra["groupId"] = "org.gofeatureflag.openfeature"
ext["version"] = "0.0.1"
}

group = project.extra["groupId"].toString()
version = project.extra["version"].toString()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}

val releaseVersion = project.extra["version"].toString()

android {
namespace = "org.gofeatureflag.openfeature"
compileSdk = 33

defaultConfig {
minSdk = 21
version = releaseVersion
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
}
}

dependencies {
implementation("dev.openfeature:kotlin-sdk:0.0.4")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("com.google.code.gson:gson:2.8.9")
implementation("dev.gustavoavila:java-android-websocket-client:2.0.2")
testImplementation("junit:junit:4.13.2")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3")
testImplementation("com.squareup.okhttp3:mockwebserver:4.12.0")
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.gofeatureflag.openfeature

import dev.openfeature.sdk.ProviderMetadata
import java.security.Provider

class GoFeatureFlagMetadata() : ProviderMetadata {
override val name: String
get() = "GoFeatureFlagProvider"
}
Loading

0 comments on commit bfa5ef1

Please sign in to comment.