Skip to content
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

Create FlagSetFilter with empty sets in consumer mode #457

Merged
merged 4 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 5 additions & 4 deletions client/src/main/java/io/split/client/SplitClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.split.client.impressions.Impression;
import io.split.client.impressions.ImpressionsManager;
import io.split.client.interceptors.FlagSetsFilter;
import io.split.client.interceptors.FlagSetsFilterImpl;
import io.split.engine.SDKReadinessGates;
import io.split.engine.evaluator.Evaluator;
import io.split.engine.evaluator.EvaluatorImp;
Expand Down Expand Up @@ -61,6 +60,7 @@ public final class SplitClientImpl implements SplitClient {
private final Evaluator _evaluator;
private final TelemetryEvaluationProducer _telemetryEvaluationProducer;
private final TelemetryConfigProducer _telemetryConfigProducer;
private final FlagSetsFilter _flagSetsFilter;

public SplitClientImpl(SplitFactory container,
SplitCacheConsumer splitCacheConsumer,
Expand All @@ -70,7 +70,8 @@ public SplitClientImpl(SplitFactory container,
SDKReadinessGates gates,
Evaluator evaluator,
TelemetryEvaluationProducer telemetryEvaluationProducer,
TelemetryConfigProducer telemetryConfigProducer) {
TelemetryConfigProducer telemetryConfigProducer,
FlagSetsFilter flagSetsFilter) {
_container = container;
_splitCacheConsumer = checkNotNull(splitCacheConsumer);
_impressionManager = checkNotNull(impressionManager);
Expand All @@ -80,6 +81,7 @@ public SplitClientImpl(SplitFactory container,
_evaluator = checkNotNull(evaluator);
_telemetryEvaluationProducer = checkNotNull(telemetryEvaluationProducer);
_telemetryConfigProducer = checkNotNull(telemetryConfigProducer);
_flagSetsFilter = flagSetsFilter;
}

@Override
Expand Down Expand Up @@ -446,10 +448,9 @@ private Map<String, SplitResult> validateBeforeEvaluate(List<String> featureFlag
return null;
}
private List<String> filterSetsAreInConfig(Set<String> sets, MethodEnum methodEnum) {
FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(_config.getSetsFilter());
List<String> setsToReturn = new ArrayList<>();
for (String set : sets) {
if (!flagSetsFilter.Intersect(set)) {
if (!_flagSetsFilter.intersect(set)) {
_log.warn(String.format("%s: you passed %s which is not part of the configured FlagSetsFilter, " +
"ignoring Flag Set.", methodEnum, set));
continue;
Expand Down
16 changes: 12 additions & 4 deletions client/src/main/java/io/split/client/SplitFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -240,7 +241,8 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
_gates,
_evaluator,
_telemetryStorageProducer, //TelemetryEvaluation instance
_telemetryStorageProducer); //TelemetryConfiguration instance
_telemetryStorageProducer, //TelemetryConfiguration instance
flagSetsFilter);

// SplitManager
_manager = new SplitManagerImpl(splitCache, config, _gates, _telemetryStorageProducer);
Expand Down Expand Up @@ -318,7 +320,11 @@ protected SplitFactoryImpl(String apiToken, SplitClientConfig config, CustomStor

// Synchronizer
Synchronizer synchronizer = new ConsumerSynchronizer(splitTasks);

FlagSetsFilter flagSetsFilter = new FlagSetsFilterImpl(new HashSet<>());
if(!config.getSetsFilter().isEmpty()) {
_log.warn("FlagSets filter is not applicable for Consumer modes where the SDK does keep rollout data in sync. FlagSet " +
nmayorsplit marked this conversation as resolved.
Show resolved Hide resolved
"filter was discarded");
}
_client = new SplitClientImpl(this,
userCustomSplitAdapterConsumer,
_impressionsManager,
Expand All @@ -327,7 +333,8 @@ protected SplitFactoryImpl(String apiToken, SplitClientConfig config, CustomStor
_gates,
_evaluator,
_telemetryStorageProducer, //TelemetryEvaluation instance
_telemetryStorageProducer); //TelemetryConfiguration instance
_telemetryStorageProducer, //TelemetryConfiguration instance
flagSetsFilter);


// SyncManager
Expand Down Expand Up @@ -405,7 +412,8 @@ protected SplitFactoryImpl(SplitClientConfig config) {
_gates,
_evaluator,
_telemetryStorageProducer, //TelemetryEvaluation instance
_telemetryStorageProducer); //TelemetryConfiguration instance
_telemetryStorageProducer, //TelemetryConfiguration instance
flagSetsFilter);

// Synchronizer
Synchronizer synchronizer = new LocalhostSynchronizer(splitTasks, _splitFetcher, config.localhostRefreshEnabled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

public interface FlagSetsFilter {

boolean Intersect(Set<String> sets);
boolean Intersect(String set);
boolean intersect(Set<String> sets);
boolean intersect(String set);
Comment on lines +7 to +8
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public FlagSetsFilterImpl(Set<String> flagSets) {
_flagSets = flagSets;
}
@Override
public boolean Intersect(Set<String> sets) {
public boolean intersect(Set<String> sets) {
if (!_shouldFilter) {
return true;
}
Expand All @@ -28,7 +28,7 @@ public boolean Intersect(Set<String> sets) {
}

@Override
public boolean Intersect(String set) {
public boolean intersect(String set) {
if (!_shouldFilter) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static FeatureFlagsToUpdate processFeatureFlagChanges(SplitParser splitPa
toRemove.add(split.name);
continue;
}
if (!flagSetsFilter.Intersect(split.sets)) {
if (!flagSetsFilter.intersect(split.sets)) {
toRemove.add(split.name);
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private void addToFlagSets(ParsedSplit featureFlag) {
return;
}
for (String set: sets) {
if (!_flagSetsFilter.Intersect(set)) {
if (!_flagSetsFilter.intersect(set)) {
continue;
}
HashSet<String> features = _flagSets.get(set);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public UserPipelineWrapper(Pipeline pipeline) {
}

@Override
public List<Result> exec() {
public List<Result> exec() throws Exception {
try{
return _pipeline.exec();
} catch (Exception e) {
_logger.warn("Exception calling Pipeline exec", e);
return new ArrayList<>();
throw e;
}
}

Expand Down
Loading