Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions client/src/main/java/io/split/client/SplitFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyn
config.getThreadFactory());

// Evaluator
_evaluator = new EvaluatorImp(splitCache, segmentCache, ruleBasedSegmentCache);
_evaluator = new EvaluatorImp(splitCache, segmentCache, ruleBasedSegmentCache, null);

// SplitClient
_client = new SplitClientImpl(this,
Expand Down Expand Up @@ -348,7 +348,8 @@ protected SplitFactoryImpl(String apiToken, SplitClientConfig config, CustomStor
_telemetrySynchronizer = new TelemetryConsumerSubmitter(customStorageWrapper, _sdkMetadata);
UserCustomRuleBasedSegmentAdapterConsumer userCustomRuleBasedSegmentAdapterConsumer =
new UserCustomRuleBasedSegmentAdapterConsumer(customStorageWrapper);
_evaluator = new EvaluatorImp(userCustomSplitAdapterConsumer, userCustomSegmentAdapterConsumer, userCustomRuleBasedSegmentAdapterConsumer);
_evaluator = new EvaluatorImp(userCustomSplitAdapterConsumer, userCustomSegmentAdapterConsumer,
userCustomRuleBasedSegmentAdapterConsumer, null);
_impressionsSender = PluggableImpressionSender.create(customStorageWrapper);
_uniqueKeysTracker = createUniqueKeysTracker(config);
_impressionsManager = buildImpressionsManager(config, userCustomImpressionAdapterConsumer,
Expand Down Expand Up @@ -446,7 +447,7 @@ protected SplitFactoryImpl(SplitClientConfig config) {
_impressionsManager, null, null, null);

// Evaluator
_evaluator = new EvaluatorImp(splitCache, segmentCache, ruleBasedSegmentCache);
_evaluator = new EvaluatorImp(splitCache, segmentCache, ruleBasedSegmentCache, null);

EventsStorage eventsStorage = new NoopEventsStorageImp();

Expand Down
28 changes: 28 additions & 0 deletions client/src/main/java/io/split/client/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.split.client.utils;

import io.split.client.dtos.ChangeDto;
import io.split.client.dtos.FallbackTreatmentsConfiguration;
import io.split.engine.evaluator.EvaluatorImp.TreatmentLabelAndChangeNumber;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
Expand Down Expand Up @@ -45,4 +47,30 @@ public static URI appendPath(URI root, String pathToAppend) throws URISyntaxExce
public static <T> boolean checkExitConditions(ChangeDto<T> change, long cn) {
return change.t < cn && change.t != -1;
}

public static TreatmentLabelAndChangeNumber checkFallbackTreatments(String treatment, String label,
String feature_name, Long changeNumber,
FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration) {
if (fallbackTreatmentsConfiguration != null) {
if (fallbackTreatmentsConfiguration.getByFlagFallbackTreatment() != null
&& fallbackTreatmentsConfiguration.getByFlagFallbackTreatment().get(feature_name) != null
&& !fallbackTreatmentsConfiguration.getByFlagFallbackTreatment().get(feature_name).getTreatment().isEmpty()) {
return new TreatmentLabelAndChangeNumber(
fallbackTreatmentsConfiguration.getByFlagFallbackTreatment().get(feature_name).getTreatment(),
fallbackTreatmentsConfiguration.getByFlagFallbackTreatment().get(feature_name).getLabel() + label,
changeNumber);
}

if (fallbackTreatmentsConfiguration.getGlobalFallbackTreatment() != null
&& !fallbackTreatmentsConfiguration.getGlobalFallbackTreatment().getTreatment().isEmpty()) {
return new TreatmentLabelAndChangeNumber(fallbackTreatmentsConfiguration.getGlobalFallbackTreatment().getTreatment(),
fallbackTreatmentsConfiguration.getGlobalFallbackTreatment().getLabel() + label,
changeNumber);
}
}

return new TreatmentLabelAndChangeNumber(treatment,
label,
changeNumber);
}
}
19 changes: 12 additions & 7 deletions client/src/main/java/io/split/engine/evaluator/EvaluatorImp.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.split.engine.evaluator;

import io.split.client.dtos.ConditionType;
import io.split.client.dtos.FallbackTreatmentsConfiguration;
import io.split.client.exceptions.ChangeNumberExceptionWrapper;
import io.split.engine.experiments.ParsedCondition;
import io.split.engine.experiments.ParsedSplit;
Expand All @@ -19,26 +20,30 @@
import java.util.Map;

import static com.google.common.base.Preconditions.checkNotNull;
import static io.split.client.utils.Utils.checkFallbackTreatments;

public class EvaluatorImp implements Evaluator {
private static final Logger _log = LoggerFactory.getLogger(EvaluatorImp.class);

private final SegmentCacheConsumer _segmentCacheConsumer;
private final EvaluationContext _evaluationContext;
private final SplitCacheConsumer _splitCacheConsumer;
private final FallbackTreatmentsConfiguration _fallbackTreatmentsConfiguration;

public EvaluatorImp(SplitCacheConsumer splitCacheConsumer, SegmentCacheConsumer segmentCache,
RuleBasedSegmentCacheConsumer ruleBasedSegmentCacheConsumer) {
RuleBasedSegmentCacheConsumer ruleBasedSegmentCacheConsumer,
FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration) {
_splitCacheConsumer = checkNotNull(splitCacheConsumer);
_segmentCacheConsumer = checkNotNull(segmentCache);
_evaluationContext = new EvaluationContext(this, _segmentCacheConsumer, ruleBasedSegmentCacheConsumer);
_fallbackTreatmentsConfiguration = fallbackTreatmentsConfiguration;
}

@Override
public TreatmentLabelAndChangeNumber evaluateFeature(String matchingKey, String bucketingKey, String featureFlag, Map<String,
Object> attributes) {
ParsedSplit parsedSplit = _splitCacheConsumer.get(featureFlag);
return evaluateParsedSplit(matchingKey, bucketingKey, attributes, parsedSplit);
return evaluateParsedSplit(matchingKey, bucketingKey, attributes, parsedSplit, featureFlag);
}

@Override
Expand All @@ -49,7 +54,7 @@ public Map<String, TreatmentLabelAndChangeNumber> evaluateFeatures(String matchi
if (parsedSplits == null) {
return results;
}
featureFlags.forEach(s -> results.put(s, evaluateParsedSplit(matchingKey, bucketingKey, attributes, parsedSplits.get(s))));
featureFlags.forEach(s -> results.put(s, evaluateParsedSplit(matchingKey, bucketingKey, attributes, parsedSplits.get(s), s)));
return results;
}

Expand Down Expand Up @@ -172,18 +177,18 @@ private String getConfig(ParsedSplit parsedSplit, String returnedTreatment) {
}

private TreatmentLabelAndChangeNumber evaluateParsedSplit(String matchingKey, String bucketingKey, Map<String, Object> attributes,
ParsedSplit parsedSplit) {
ParsedSplit parsedSplit, String feature_name) {
try {
if (parsedSplit == null) {
return new TreatmentLabelAndChangeNumber(Treatments.CONTROL, Labels.DEFINITION_NOT_FOUND);
return checkFallbackTreatments(Treatments.CONTROL, Labels.DEFINITION_NOT_FOUND, feature_name, null, _fallbackTreatmentsConfiguration);
}
return getTreatment(matchingKey, bucketingKey, parsedSplit, attributes);
} catch (ChangeNumberExceptionWrapper e) {
_log.error("Evaluator Exception", e.wrappedException());
return new EvaluatorImp.TreatmentLabelAndChangeNumber(Treatments.CONTROL, Labels.EXCEPTION, e.changeNumber());
return checkFallbackTreatments(Treatments.CONTROL, Labels.EXCEPTION, feature_name, e.changeNumber(), _fallbackTreatmentsConfiguration);
} catch (Exception e) {
_log.error("Evaluator Exception", e);
return new EvaluatorImp.TreatmentLabelAndChangeNumber(Treatments.CONTROL, Labels.EXCEPTION);
return checkFallbackTreatments(Treatments.CONTROL, Labels.EXCEPTION, feature_name, null, _fallbackTreatmentsConfiguration);
}
}

Expand Down
Loading