Skip to content

Commit 2213946

Browse files
feat: flagd in-process provider (#633)
Signed-off-by: Kavindu Dodanduwa <[email protected]>
1 parent 9b622d8 commit 2213946

22 files changed

+1396
-1207
lines changed

.eslintrc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"root": true,
33
"ignorePatterns": ["**/*"],
44
"plugins": ["@nx"],
5+
"extends": [
6+
"eslint:recommended",
7+
"plugin:prettier/recommended"
8+
],
59
"overrides": [
610
{
711
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],

libs/providers/flagd/README.md

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,56 +6,81 @@ This repository and package provides the client code for interacting with it via
66

77
## Installation
88

9-
```
10-
$ npm install @openfeature/flagd-provider
9+
### npm
10+
11+
```sh
12+
npm install @openfeature/flagd-provider
1113
```
1214

13-
Required peer dependencies
15+
### yarn
1416

17+
```sh
18+
yarn add @openfeature/server-sdk @grpc/grpc-js @openfeature/flagd-core
1519
```
16-
$ npm install @openfeature/server-sdk
17-
```
1820

19-
## Usage
21+
> [!NOTE]
22+
> yarn requires manual installation of peer dependencies
23+
24+
## Configurations and Usage
25+
26+
The `FlagdProvider` supports multiple configuration options and has the ability to resolve flags remotely over RPC or in-process.
27+
Options can be defined in the constructor or as environment variables. Constructor options having the highest precedence.
28+
29+
### Available Configuration Options
30+
31+
| Option name | Environment variable name | Type | Default | Supported values |
32+
|-----------------------|--------------------------------|---------|-----------|------------------|
33+
| host | FLAGD_HOST | string | localhost | |
34+
| port | FLAGD_PORT | number | 8013 | |
35+
| tls | FLAGD_TLS | boolean | false | |
36+
| socketPath | FLAGD_SOCKET_PATH | string | - | |
37+
| resolverType | FLAGD_SOURCE_RESOLVER | string | rpc | rpc, in-process |
38+
| selector | FLAGD_SOURCE_SELECTOR | string | - | |
39+
| cache | FLAGD_CACHE | string | lru | lru,disabled |
40+
| maxCacheSize | FLAGD_MAX_CACHE_SIZE | int | 1000 | |
41+
| maxEventStreamRetries | FLAGD_MAX_EVENT_STREAM_RETRIES | int | 5 | |
2042

21-
The `FlagdProvider` supports multiple configuration options that determine now the SDK communicates with flagd.
22-
Options can be defined in the constructor or as environment variables, with constructor options having the highest precedence.
43+
Below are examples of usage patterns.
2344

24-
### Available Options
45+
### Remote flag resolving over RPC
2546

26-
| Option name | Environment variable name | Type | Default | Values |
27-
| --------------------- | ------------------------------ | ------- | --------- | ------------ |
28-
| host | FLAGD_HOST | string | localhost | |
29-
| port | FLAGD_PORT | number | 8013 | |
30-
| tls | FLAGD_TLS | boolean | false | |
31-
| socketPath | FLAGD_SOCKET_PATH | string | - | |
32-
| cache | FLAGD_CACHE | string | lru | lru,disabled |
33-
| maxCacheSize | FLAGD_MAX_CACHE_SIZE | int | 1000 | |
34-
| maxEventStreamRetries | FLAGD_MAX_EVENT_STREAM_RETRIES | int | 5 | |
47+
This is the default mode of operation of the provider.
48+
In this mode, FlagdProvider communicates with flagd via the gRPC protocol.
49+
Flag evaluations take place remotely at the connected [flagd](https://flagd.dev/) instance.
3550

36-
### Example Using TCP
51+
```ts
52+
OpenFeature.setProvider(new FlagdProvider())
53+
```
54+
55+
In the above example, the provider expects flagd to be available at `localhost:8013` (default host and port).
56+
57+
Alternatively, you can use socket paths to connect to flagd.
3758

3859
```
3960
OpenFeature.setProvider(new FlagdProvider({
40-
host: 'localhost',
41-
port: 8013,
61+
socketPath: "/tmp/flagd.socks",
4262
}))
4363
```
4464

45-
### Example Using a Unix Socket
65+
### In-process resolver
66+
67+
This mode performs flag evaluations locally (in-process).
68+
Flag configurations for evaluation are obtained via gRPC protocol using [sync protobuf schema](https://buf.build/open-feature/flagd/file/main:sync/v1/sync_service.proto) service definition.
4669

4770
```
4871
OpenFeature.setProvider(new FlagdProvider({
49-
socketPath: "/tmp/flagd.socks",
72+
resolverType: 'in-process',
5073
}))
5174
```
5275

76+
In the above example, the provider expects a flag sync service implementation to be available at `localhost:8013` (default host and port).
77+
5378
### Supported Events
5479

5580
The flagd provider emits `PROVIDER_READY`, `PROVIDER_ERROR` and `PROVIDER_CONFIGURATION_CHANGED` events.
5681

5782
| SDK event | Originating action in flagd |
58-
| -------------------------------- | ------------------------------------------------------------------------------- |
83+
|----------------------------------|---------------------------------------------------------------------------------|
5984
| `PROVIDER_READY` | The streaming connection with flagd has been established. |
6085
| `PROVIDER_ERROR` | The streaming connection with flagd has been broken. |
6186
| `PROVIDER_CONFIGURATION_CHANGED` | A flag configuration (default value, targeting rule, etc) in flagd has changed. |
@@ -65,7 +90,7 @@ For general information on events, see the [official documentation](https://open
6590
### Flag Metadata
6691

6792
| Field | Type | Value |
68-
| ------- | ------ | ------------------------------------------------- |
93+
|---------|--------|---------------------------------------------------|
6994
| `scope` | string | "selector" set for the associated source in flagd |
7095

7196
## Building

0 commit comments

Comments
 (0)