Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public class FlagdOptions {
*/
private int port;

// TODO: remove the metadata call entirely after https://github.com/open-feature/flagd/issues/1584
/**
* Disables call to sync.GetMetadata (see: https://buf.build/open-feature/flagd/docs/main:flagd.sync.v1#flagd.sync.v1.FlagSyncService.GetMetadata).
* Disabling will prevent static context from flagd being used in evaluations.
* GetMetadata and this option will be removed.
*/
@Deprecated
@Builder.Default
private boolean syncMetadataDisabled = false;

/**
* Use TLS connectivity.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class SyncStreamQueueSource implements QueueSource {
private final int streamDeadline;
private final String selector;
private final String providerId;
private final boolean syncMetadataDisabled;
private final ChannelConnector<FlagSyncServiceStub, FlagSyncServiceBlockingStub> channelConnector;
private final LinkedBlockingQueue<StreamResponseModel<SyncFlagsResponse>> incomingQueue =
new LinkedBlockingQueue<>(QUEUE_SIZE);
Expand All @@ -52,6 +53,7 @@ public SyncStreamQueueSource(final FlagdOptions options, Consumer<FlagdProviderE
streamDeadline = options.getStreamDeadlineMs();
selector = options.getSelector();
providerId = options.getProviderId();
syncMetadataDisabled = options.isSyncMetadataDisabled();
channelConnector = new ChannelConnector<>(options, FlagSyncServiceGrpc::newBlockingStub, onConnectionEvent);
this.stub = FlagSyncServiceGrpc.newStub(channelConnector.getChannel()).withWaitForReady();
}
Expand All @@ -66,6 +68,7 @@ protected SyncStreamQueueSource(
providerId = options.getProviderId();
channelConnector = connectorMock;
stub = stubMock;
syncMetadataDisabled = options.isSyncMetadataDisabled();
}

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

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

try {
metadataResponse = channelConnector.getBlockingStub().getMetadata(metadataRequest.build());
} catch (Exception metaEx) {
log.error("Metadata exception: {}, cancelling stream", metaEx.getMessage(), metaEx);
context.cancel(metaEx);
// TODO: remove the metadata call entirely after https://github.com/open-feature/flagd/issues/1584
if (!syncMetadataDisabled) {
try {
metadataResponse = channelConnector.getBlockingStub().getMetadata(metadataRequest.build());
} catch (Exception metaEx) {
log.error("Metadata exception: {}, cancelling stream", metaEx.getMessage(), metaEx);
context.cancel(metaEx);
}
}

// inner loop for handling messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,29 @@ void onNextEnqueuesDataPayload() throws Exception {
verify(stub, times(1)).syncFlags(any(), any());
}

@Test
void onNextEnqueuesDataPayloadMetadataDisabled() throws Exception {
// disable GetMetadata call
SyncStreamQueueSource connector = new SyncStreamQueueSource(
FlagdOptions.builder().syncMetadataDisabled(true).build(), mockConnector, stub);
connector.init();
latch = new CountDownLatch(1);
latch.await();

// fire onNext (data) event
observer.onNext(SyncFlagsResponse.newBuilder().build());

// should enqueue data payload
BlockingQueue<QueuePayload> streamQueue = connector.getStreamQueue();
QueuePayload payload = streamQueue.poll(1000, TimeUnit.MILLISECONDS);
assertNotNull(payload);
assertEquals(QueuePayloadType.DATA, payload.getType());
// should NOT have restarted the stream (1 call)
verify(stub, times(1)).syncFlags(any(), any());
// should NOT have called getMetadata
verify(blockingStub, times(0)).getMetadata(any());
}

@Test
void onErrorEnqueuesDataPayload() throws Exception {
SyncStreamQueueSource connector =
Expand Down
Loading