Skip to content

Commit 28c65d5

Browse files
authored
chore: add disable metadata option (#1267)
Signed-off-by: Todd Baert <[email protected]>
1 parent 22d2a35 commit 28c65d5

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

Diff for: providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/FlagdOptions.java

+10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ public class FlagdOptions {
4040
*/
4141
private int port;
4242

43+
// TODO: remove the metadata call entirely after https://github.com/open-feature/flagd/issues/1584
44+
/**
45+
* Disables call to sync.GetMetadata (see: https://buf.build/open-feature/flagd/docs/main:flagd.sync.v1#flagd.sync.v1.FlagSyncService.GetMetadata).
46+
* Disabling will prevent static context from flagd being used in evaluations.
47+
* GetMetadata and this option will be removed.
48+
*/
49+
@Deprecated
50+
@Builder.Default
51+
private boolean syncMetadataDisabled = false;
52+
4353
/**
4454
* Use TLS connectivity.
4555
*/

Diff for: providers/flagd/src/main/java/dev/openfeature/contrib/providers/flagd/resolver/process/storage/connector/sync/SyncStreamQueueSource.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class SyncStreamQueueSource implements QueueSource {
3939
private final int streamDeadline;
4040
private final String selector;
4141
private final String providerId;
42+
private final boolean syncMetadataDisabled;
4243
private final ChannelConnector<FlagSyncServiceStub, FlagSyncServiceBlockingStub> channelConnector;
4344
private final LinkedBlockingQueue<StreamResponseModel<SyncFlagsResponse>> incomingQueue =
4445
new LinkedBlockingQueue<>(QUEUE_SIZE);
@@ -52,6 +53,7 @@ public SyncStreamQueueSource(final FlagdOptions options, Consumer<FlagdProviderE
5253
streamDeadline = options.getStreamDeadlineMs();
5354
selector = options.getSelector();
5455
providerId = options.getProviderId();
56+
syncMetadataDisabled = options.isSyncMetadataDisabled();
5557
channelConnector = new ChannelConnector<>(options, FlagSyncServiceGrpc::newBlockingStub, onConnectionEvent);
5658
this.stub = FlagSyncServiceGrpc.newStub(channelConnector.getChannel()).withWaitForReady();
5759
}
@@ -66,6 +68,7 @@ protected SyncStreamQueueSource(
6668
providerId = options.getProviderId();
6769
channelConnector = connectorMock;
6870
stub = stubMock;
71+
syncMetadataDisabled = options.isSyncMetadataDisabled();
6972
}
7073

7174
/** Initialize sync stream connector. */
@@ -118,11 +121,14 @@ private void observeSyncStream() throws InterruptedException {
118121

119122
restart(); // start the stream within the context
120123

121-
try {
122-
metadataResponse = channelConnector.getBlockingStub().getMetadata(metadataRequest.build());
123-
} catch (Exception metaEx) {
124-
log.error("Metadata exception: {}, cancelling stream", metaEx.getMessage(), metaEx);
125-
context.cancel(metaEx);
124+
// TODO: remove the metadata call entirely after https://github.com/open-feature/flagd/issues/1584
125+
if (!syncMetadataDisabled) {
126+
try {
127+
metadataResponse = channelConnector.getBlockingStub().getMetadata(metadataRequest.build());
128+
} catch (Exception metaEx) {
129+
log.error("Metadata exception: {}, cancelling stream", metaEx.getMessage(), metaEx);
130+
context.cancel(metaEx);
131+
}
126132
}
127133

128134
// inner loop for handling messages

Diff for: providers/flagd/src/test/java/dev/openfeature/contrib/providers/flagd/resolver/process/storage/connector/sync/SyncStreamQueueSourceTest.java

+23
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,29 @@ void onNextEnqueuesDataPayload() throws Exception {
8181
verify(stub, times(1)).syncFlags(any(), any());
8282
}
8383

84+
@Test
85+
void onNextEnqueuesDataPayloadMetadataDisabled() throws Exception {
86+
// disable GetMetadata call
87+
SyncStreamQueueSource connector = new SyncStreamQueueSource(
88+
FlagdOptions.builder().syncMetadataDisabled(true).build(), mockConnector, stub);
89+
connector.init();
90+
latch = new CountDownLatch(1);
91+
latch.await();
92+
93+
// fire onNext (data) event
94+
observer.onNext(SyncFlagsResponse.newBuilder().build());
95+
96+
// should enqueue data payload
97+
BlockingQueue<QueuePayload> streamQueue = connector.getStreamQueue();
98+
QueuePayload payload = streamQueue.poll(1000, TimeUnit.MILLISECONDS);
99+
assertNotNull(payload);
100+
assertEquals(QueuePayloadType.DATA, payload.getType());
101+
// should NOT have restarted the stream (1 call)
102+
verify(stub, times(1)).syncFlags(any(), any());
103+
// should NOT have called getMetadata
104+
verify(blockingStub, times(0)).getMetadata(any());
105+
}
106+
84107
@Test
85108
void onErrorEnqueuesDataPayload() throws Exception {
86109
SyncStreamQueueSource connector =

0 commit comments

Comments
 (0)