4
4
import io .split .client .exceptions .ChangeNumberExceptionWrapper ;
5
5
import io .split .engine .experiments .ParsedCondition ;
6
6
import io .split .engine .experiments .ParsedSplit ;
7
+ import io .split .engine .matchers .PrerequisitesMatcher ;
7
8
import io .split .engine .splitter .Splitter ;
8
9
import io .split .grammar .Treatments ;
9
10
import io .split .storages .RuleBasedSegmentCacheConsumer ;
@@ -27,6 +28,7 @@ public class EvaluatorImp implements Evaluator {
27
28
private final RuleBasedSegmentCacheConsumer _ruleBasedSegmentCacheConsumer ;
28
29
private final EvaluationContext _evaluationContext ;
29
30
private final SplitCacheConsumer _splitCacheConsumer ;
31
+ private PrerequisitesMatcher _prerequisitesMatcher ;
30
32
31
33
public EvaluatorImp (SplitCacheConsumer splitCacheConsumer , SegmentCacheConsumer segmentCache ,
32
34
RuleBasedSegmentCacheConsumer ruleBasedSegmentCacheConsumer ) {
@@ -88,8 +90,8 @@ private List<String> getFeatureFlagNamesByFlagSets(List<String> flagSets) {
88
90
private TreatmentLabelAndChangeNumber getTreatment (String matchingKey , String bucketingKey , ParsedSplit parsedSplit , Map <String ,
89
91
Object > attributes ) throws ChangeNumberExceptionWrapper {
90
92
try {
93
+ String config = parsedSplit .configurations () != null ? parsedSplit .configurations ().get (parsedSplit .defaultTreatment ()) : null ;
91
94
if (parsedSplit .killed ()) {
92
- String config = parsedSplit .configurations () != null ? parsedSplit .configurations ().get (parsedSplit .defaultTreatment ()) : null ;
93
95
return new TreatmentLabelAndChangeNumber (
94
96
parsedSplit .defaultTreatment (),
95
97
Labels .KILLED ,
@@ -98,6 +100,17 @@ private TreatmentLabelAndChangeNumber getTreatment(String matchingKey, String bu
98
100
parsedSplit .impressionsDisabled ());
99
101
}
100
102
103
+ String bk = (bucketingKey == null ) ? matchingKey : bucketingKey ;
104
+
105
+ if (!_prerequisitesMatcher .match (matchingKey , bk , attributes , _evaluationContext )) {
106
+ return new TreatmentLabelAndChangeNumber (
107
+ parsedSplit .defaultTreatment (),
108
+ Labels .PREREQUISITES_NOT_MET ,
109
+ parsedSplit .changeNumber (),
110
+ config ,
111
+ parsedSplit .impressionsDisabled ());
112
+ }
113
+
101
114
/*
102
115
* There are three parts to a single Feature flag: 1) Whitelists 2) Traffic Allocation
103
116
* 3) Rollout. The flag inRollout is there to understand when we move into the Rollout
@@ -106,8 +119,6 @@ private TreatmentLabelAndChangeNumber getTreatment(String matchingKey, String bu
106
119
*/
107
120
boolean inRollout = false ;
108
121
109
- String bk = (bucketingKey == null ) ? matchingKey : bucketingKey ;
110
-
111
122
for (ParsedCondition parsedCondition : parsedSplit .parsedConditions ()) {
112
123
113
124
if (!inRollout && parsedCondition .conditionType () == ConditionType .ROLLOUT ) {
@@ -118,7 +129,7 @@ private TreatmentLabelAndChangeNumber getTreatment(String matchingKey, String bu
118
129
119
130
if (bucket > parsedSplit .trafficAllocation ()) {
120
131
// out of split
121
- String config = parsedSplit .configurations () != null ?
132
+ config = parsedSplit .configurations () != null ?
122
133
parsedSplit .configurations ().get (parsedSplit .defaultTreatment ()) : null ;
123
134
return new TreatmentLabelAndChangeNumber (parsedSplit .defaultTreatment (), Labels .NOT_IN_SPLIT ,
124
135
parsedSplit .changeNumber (), config , parsedSplit .impressionsDisabled ());
@@ -130,7 +141,7 @@ private TreatmentLabelAndChangeNumber getTreatment(String matchingKey, String bu
130
141
131
142
if (parsedCondition .matcher ().match (matchingKey , bucketingKey , attributes , _evaluationContext )) {
132
143
String treatment = Splitter .getTreatment (bk , parsedSplit .seed (), parsedCondition .partitions (), parsedSplit .algo ());
133
- String config = parsedSplit .configurations () != null ? parsedSplit .configurations ().get (treatment ) : null ;
144
+ config = parsedSplit .configurations () != null ? parsedSplit .configurations ().get (treatment ) : null ;
134
145
return new TreatmentLabelAndChangeNumber (
135
146
treatment ,
136
147
parsedCondition .label (),
@@ -140,7 +151,7 @@ private TreatmentLabelAndChangeNumber getTreatment(String matchingKey, String bu
140
151
}
141
152
}
142
153
143
- String config = parsedSplit .configurations () != null ? parsedSplit .configurations ().get (parsedSplit .defaultTreatment ()) : null ;
154
+ config = parsedSplit .configurations () != null ? parsedSplit .configurations ().get (parsedSplit .defaultTreatment ()) : null ;
144
155
return new TreatmentLabelAndChangeNumber (
145
156
parsedSplit .defaultTreatment (),
146
157
Labels .DEFAULT_RULE ,
@@ -158,7 +169,7 @@ private TreatmentLabelAndChangeNumber evaluateParsedSplit(String matchingKey, St
158
169
if (parsedSplit == null ) {
159
170
return new TreatmentLabelAndChangeNumber (Treatments .CONTROL , Labels .DEFINITION_NOT_FOUND );
160
171
}
161
-
172
+ _prerequisitesMatcher = new PrerequisitesMatcher ( parsedSplit . prerequisites ());
162
173
return getTreatment (matchingKey , bucketingKey , parsedSplit , attributes );
163
174
} catch (ChangeNumberExceptionWrapper e ) {
164
175
_log .error ("Evaluator Exception" , e .wrappedException ());
0 commit comments