Skip to content

Commit 388f82f

Browse files
Copilotaepfli
andcommitted
Update documentation to reflect header-based implementation
Co-authored-by: aepfli <9987394+aepfli@users.noreply.github.com>
1 parent 48cb95b commit 388f82f

File tree

2 files changed

+24
-62
lines changed

2 files changed

+24
-62
lines changed

providers/flagd/README.md

Lines changed: 20 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ In the above example, in-process handlers attempt to connect to a sync service o
5151

5252
The `selector` option allows filtering flag configurations from flagd based on source identifiers when using the in-process resolver. This is useful when flagd is configured with multiple flag sources and you want to sync only a specific subset.
5353

54-
##### Current implementation (Request body)
54+
##### Usage
5555

56-
The current implementation passes the selector in the gRPC request body via the `SyncFlagsRequest`:
56+
To use selector filtering, simply configure the `selector` option when creating the provider:
5757

5858
```java
5959
FlagdProvider flagdProvider = new FlagdProvider(
@@ -68,64 +68,27 @@ Or via environment variable:
6868
export FLAGD_SOURCE_SELECTOR="source=my-app"
6969
```
7070

71-
##### Migration to header-based selector
71+
##### Implementation details
7272

7373
> [!IMPORTANT]
74-
> **Selector normalization and deprecation notice**
74+
> **Selector normalization (flagd issue #1814)**
7575
>
76-
> As part of [flagd issue #1814](https://github.com/open-feature/flagd/issues/1814), the flagd project is normalizing selector handling across all services. The preferred approach is to use the `flagd-selector` gRPC metadata header instead of the request body field.
76+
> As part of [flagd issue #1814](https://github.com/open-feature/flagd/issues/1814), the flagd project is normalizing selector handling across all services to use the `flagd-selector` gRPC metadata header.
7777
>
78-
> **Current status:**
79-
> - The Java SDK currently uses the **request body** approach (via `SyncFlagsRequest.setSelector()`)
80-
> - flagd services support both request body and header for backward compatibility
81-
> - In a future major version, the request body selector field may be removed from flagd
78+
> **Current implementation:**
79+
> - The Java SDK **automatically passes the selector via the `flagd-selector` header** (preferred approach)
80+
> - For backward compatibility with older flagd versions, the selector is **also sent in the request body**
81+
> - Both methods work with current flagd versions
82+
> - In a future major version of flagd, the request body selector field may be removed
8283
>
83-
> **Recommended migration path:**
84+
> **No migration needed:**
8485
>
85-
> To prepare for future changes and align with the preferred approach, you can pass the selector via gRPC headers using a custom `ClientInterceptor`:
86-
87-
```java
88-
import io.grpc.*;
89-
90-
private static ClientInterceptor createSelectorHeaderInterceptor(String selector) {
91-
return new ClientInterceptor() {
92-
@Override
93-
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(
94-
MethodDescriptor<ReqT, RespT> method,
95-
CallOptions callOptions,
96-
Channel next) {
97-
return new ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT>(
98-
next.newCall(method, callOptions)) {
99-
@Override
100-
public void start(Listener<RespT> responseListener, Metadata headers) {
101-
headers.put(
102-
Metadata.Key.of("flagd-selector", Metadata.ASCII_STRING_MARSHALLER),
103-
selector
104-
);
105-
super.start(responseListener, headers);
106-
}
107-
};
108-
}
109-
};
110-
}
111-
112-
// Use the interceptor when creating the provider
113-
List<ClientInterceptor> interceptors = new ArrayList<>();
114-
interceptors.add(createSelectorHeaderInterceptor("source=my-app"));
115-
116-
FlagdProvider flagdProvider = new FlagdProvider(
117-
FlagdOptions.builder()
118-
.resolverType(Config.Resolver.IN_PROCESS)
119-
.clientInterceptors(interceptors)
120-
// Note: You can still use .selector() for backward compatibility
121-
// but the header approach is preferred for future-proofing
122-
.build());
123-
```
86+
> Users do not need to make any code changes. The SDK handles selector normalization automatically.
12487
12588
**Backward compatibility:**
126-
- The current request body approach will continue to work with flagd services that support it
127-
- Both approaches can be used simultaneously during the migration period
128-
- The Java SDK will be updated in a future major version to use headers by default
89+
- Both header and request body approaches work with current flagd versions
90+
- Older flagd versions that only support request body selectors are still supported
91+
- Future flagd versions may remove request body selector support, but the SDK will continue to work using headers
12992

13093
For more details on selector normalization, see the [flagd selector normalization issue](https://github.com/open-feature/flagd/issues/1814).
13194

@@ -201,7 +164,7 @@ Given below are the supported configurations:
201164
| deadline | FLAGD_DEADLINE_MS | int | 500 | rpc & in-process & file |
202165
| streamDeadlineMs | FLAGD_STREAM_DEADLINE_MS | int | 600000 | rpc & in-process |
203166
| keepAliveTime | FLAGD_KEEP_ALIVE_TIME_MS | long | 0 | rpc & in-process |
204-
| selector | FLAGD_SOURCE_SELECTOR | String | null | in-process (see [migration guidance](#selector-filtering-in-process-mode-only)) |
167+
| selector | FLAGD_SOURCE_SELECTOR | String | null | in-process (see [details](#selector-filtering-in-process-mode-only)) |
205168
| providerId | FLAGD_SOURCE_PROVIDER_ID | String | null | in-process |
206169
| cache | FLAGD_CACHE | String - lru, disabled | lru | rpc |
207170
| maxCacheSize | FLAGD_MAX_CACHE_SIZE | int | 1000 | rpc |
@@ -213,8 +176,8 @@ Given below are the supported configurations:
213176
> [!NOTE]
214177
> Some configurations are only applicable for RPC resolver.
215178
216-
> [!WARNING]
217-
> The `selector` option currently uses the gRPC request body approach, which may be deprecated in future flagd versions. See [Selector filtering](#selector-filtering-in-process-mode-only) for migration guidance to the header-based approach.
179+
> [!NOTE]
180+
> The `selector` option automatically uses the `flagd-selector` header (the preferred approach per [flagd issue #1814](https://github.com/open-feature/flagd/issues/1814)) while maintaining backward compatibility with older flagd versions. See [Selector filtering](#selector-filtering-in-process-mode-only) for details.
218181
>
219182
220183
### Unix socket support
@@ -274,8 +237,8 @@ FlagdProvider flagdProvider = new FlagdProvider(
274237

275238
The `clientInterceptors` and `defaultAuthority` are meant for connection of the in-process resolver to a Sync API implementation on a host/port, that might require special credentials or headers.
276239

277-
> [!TIP]
278-
> `ClientInterceptor` can also be used to pass the `flagd-selector` header for selector-based filtering. See [Selector filtering](#selector-filtering-in-process-mode-only) for details on the preferred header-based approach.
240+
> [!NOTE]
241+
> The SDK automatically handles the `flagd-selector` header when the `selector` option is configured. Custom interceptors are not needed for selector filtering. See [Selector filtering](#selector-filtering-in-process-mode-only) for details.
279242
280243
```java
281244
private static ClientInterceptor createHeaderInterceptor() {

providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/FlagdOptions.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,13 @@ public class FlagdOptions {
125125
/**
126126
* Selector to be used with flag sync gRPC contract.
127127
* <p>
128-
* <b>Note:</b> This currently uses the gRPC request body approach. The preferred approach is to use
129-
* the {@code flagd-selector} header via a {@link ClientInterceptor}.
130-
* See the <a href="https://github.com/open-feature/java-sdk-contrib/tree/main/providers/flagd#selector-filtering-in-process-mode-only">selector migration guidance</a>
131-
* for details on the header-based approach.
128+
* The SDK automatically passes the selector via the {@code flagd-selector} gRPC metadata header
129+
* (the preferred approach per <a href="https://github.com/open-feature/flagd/issues/1814">flagd issue #1814</a>).
130+
* For backward compatibility with older flagd versions, the selector is also sent in the request body.
132131
* <p>
133132
* Only applicable for in-process resolver mode.
134133
*
135-
* @see <a href="/open-feature/flagd/issues/1814">flagd selector normalization issue</a>
134+
* @see <a href="/open-feature/java-sdk-contrib/tree/main/providers/flagd#selector-filtering-in-process-mode-only">Selector filtering documentation</a>
136135
**/
137136
@Builder.Default
138137
private String selector = fallBackToEnvOrDefault(Config.SOURCE_SELECTOR_ENV_VAR_NAME, null);

0 commit comments

Comments
 (0)