Skip to content

feat(flagd): add http connector for In-process resolver #1299

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

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@
<module>providers/configcat</module>
<module>providers/statsig</module>
<module>providers/multiprovider</module>
<module>tools/flagd-http-connector</module>
</modules>

<scm>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
org.org.slf4j.simpleLogger.defaultLogLevel=debug
org.slf4j.simpleLogger.defaultLogLevel=debug

io.grpc.level=trace
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.org.slf4j.simpleLogger.defaultLogLevel=debug
org.slf4j.simpleLogger.defaultLogLevel=debug
org.slf4j.simpleLogger.showDateTime=

io.grpc.level=trace
35 changes: 35 additions & 0 deletions tools/flagd-http-connector/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Changelog

## [0.1.2](https://github.com/open-feature/java-sdk-contrib/compare/dev.openfeature.contrib.tools.junitopenfeature-v0.1.1...dev.openfeature.contrib.tools.junitopenfeature-v0.1.2) (2024-12-03)


### ✨ New Features

* added interception of parameterized tests to Junit OpenFeature Extension ([#1093](https://github.com/open-feature/java-sdk-contrib/issues/1093)) ([a78c906](https://github.com/open-feature/java-sdk-contrib/commit/a78c906b24b53f7d25eb01aad85ed614eb30ca05))

## [0.1.1](https://github.com/open-feature/java-sdk-contrib/compare/dev.openfeature.contrib.tools.junitopenfeature-v0.1.0...dev.openfeature.contrib.tools.junitopenfeature-v0.1.1) (2024-09-27)


### 🐛 Bug Fixes

* race condition causing default when multiple flags are used ([#983](https://github.com/open-feature/java-sdk-contrib/issues/983)) ([356a973](https://github.com/open-feature/java-sdk-contrib/commit/356a973cf2b6ddf82b8311ea200fa30df4f1d048))

## [0.1.0](https://github.com/open-feature/java-sdk-contrib/compare/dev.openfeature.contrib.tools.junitopenfeature-v0.0.3...dev.openfeature.contrib.tools.junitopenfeature-v0.1.0) (2024-09-25)


### 🐛 Bug Fixes

* **deps:** update dependency org.apache.commons:commons-lang3 to v3.17.0 ([#932](https://github.com/open-feature/java-sdk-contrib/issues/932)) ([c598d9f](https://github.com/open-feature/java-sdk-contrib/commit/c598d9f0a61f2324fb85d72fdfea34811283c575))


### 🐛 Bug Fixes

* added missing dependency and installation instruction ([#895](https://github.com/open-feature/java-sdk-contrib/issues/895)) ([6748d02](https://github.com/open-feature/java-sdk-contrib/commit/6748d02403f0ceecb6cb9ecdfb2fecf98423a7db))
* **deps:** update dependency org.apache.commons:commons-lang3 to v3.16.0 ([#908](https://github.com/open-feature/java-sdk-contrib/issues/908)) ([d21cfe3](https://github.com/open-feature/java-sdk-contrib/commit/d21cfe3ac7da1ff6e1a4dc2ee4b0db5c24ed4847))

## [0.0.2](https://github.com/open-feature/java-sdk-contrib/compare/dev.openfeature.contrib.tools.junitopenfeature-v0.0.1...dev.openfeature.contrib.tools.junitopenfeature-v0.0.2) (2024-07-29)


### ✨ New Features

* Add JUnit5 extension for OpenFeature ([#888](https://github.com/open-feature/java-sdk-contrib/issues/888)) ([9fff9db](https://github.com/open-feature/java-sdk-contrib/commit/9fff9db4bcee3c3ae8128a1b2fb040f53df1d5ed))
103 changes: 103 additions & 0 deletions tools/flagd-http-connector/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Http Connector

## Introduction
Http Connector is a tool for [flagd](https://github.com/open-feature/flagd) in-process resolver.

This mode performs flag evaluations locally (in-process).
Flag configurations for evaluation are obtained via Http.

## Http Connector functionality

HttpConnector is responsible for polling data from a specified URL at regular intervals.
It is leveraging Http cache mechanism with 'ETag' header, then when receiving 304 Not Modified response,
reducing traffic, reducing rate limits effects and changes updates. Can be enabled via useHttpCache option.
The implementation is using Java HttpClient.

## Use cases and benefits
* Reduce infrastructure/devops work, without additional containers needed.
* Use as an additional provider for fallback / internal backup service via multi-provider.

### What happens if the Http source is down when application is starting ?

It supports optional fail-safe initialization via cache, such that on initial fetch error following by
source downtime window, initial payload is taken from cache to avoid starting with default values until
the source is back up. Therefore, the cache ttl expected to be higher than the expected source
down-time to recover from during initialization.

### Sample flow
Sample flow can use:
- Github as the flags payload source.
- Redis cache as a fail-safe initialization cache.

Sample flow of initialization during Github down-time window, showing that application can still use flags
values as fetched from cache.
```mermaid
sequenceDiagram
participant Provider
participant Github
participant Redis

break source downtime
Provider->>Github: initialize
Github->>Provider: failure
end
Provider->>Redis: fetch
Redis->>Provider: last payload

```

## Usage

### Installation
<!-- x-release-please-start-version -->
```xml
<dependency>
<groupId>dev.openfeature.contrib.tools</groupId>
<artifactId>flagd-http-connector</artifactId>
<version>0.0.1</version>
</dependency>
```
<!-- x-release-please-end-version -->

### Usage example

```java

HttpConnectorOptions httpConnectorOptions = HttpConnectorOptions.builder()
.url("http://example.com/flags")
.build();
HttpConnector connector = HttpConnector.builder()
.httpConnectorOptions(httpConnectorOptions)
.build();

FlagdOptions options =
FlagdOptions.builder()
.resolverType(Config.Resolver.IN_PROCESS)
.customConnector(connector)
.build();

FlagdProvider flagdProvider = new FlagdProvider(options);
```

### Configuration
The Http Connector can be configured using the following properties in the `HttpConnectorOptions` class.:

| Property Name | Type | Description |
|-------------------------------------------|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| url | String | The URL to poll for updates. This is a required field. |
| pollIntervalSeconds | Integer | The interval in seconds at which the connector will poll the URL for updates. Default is 60 seconds. |
| connectTimeoutSeconds | Integer | The timeout in seconds for establishing a connection to the URL. Default is 10 seconds. |
| requestTimeoutSeconds | Integer | The timeout in seconds for the request to complete. Default is 10 seconds. |
| linkedBlockingQueueCapacity | Integer | The capacity of the linked blocking queue used for processing requests. Default is 100. |
| scheduledThreadPoolSize | Integer | The size of the scheduled thread pool used for processing requests. Default is 2. |
| headers | Map<String, String> | A map of headers to be included in the request. Default is an empty map. |
| httpClientExecutor | ExecutorService | The executor service used for making HTTP requests. Default is a fixed thread pool with 1 thread. |
| proxyHost | String | The host of the proxy server to use for requests. Default is null. |
| proxyPort | Integer | The port of the proxy server to use for requests. Default is null. |
| payloadCacheOptions | PayloadCacheOptions | Options for configuring the payload cache. Default is null. |
| payloadCache | PayloadCache | The payload cache to use for caching responses. Default is null. |
| useHttpCache | Boolean | Whether to use HTTP caching for the requests. Default is false. |
| PayloadCacheOptions.updateIntervalSeconds | Integer | The interval, in seconds, at which the cache is updated. By default, this is set to 30 minutes. The goal is to avoid overloading fallback cache writes, since the cache serves only as a fallback mechanism. Typically, this value can be tuned to be shorter than the cache's TTL, balancing the need to minimize unnecessary updates while still handling edge cases effectively. |



8 changes: 8 additions & 0 deletions tools/flagd-http-connector/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
Copy link
Member Author

Choose a reason for hiding this comment

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

both checkstyle files should not be here as part of the parent, but CI build is failing on checkstyle without them


<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" "https://checkstyle.org/dtds/suppressions_1_2.dtd">

<suppressions>
<!-- don't check style of generated sources (GRPC bindings) -->
<suppress files="[\\/]generated-sources[\\/]" checks="[a-zA-Z0-9]*" />
</suppressions>
Loading