Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 1c49f9b

Browse files
committed
Revert "Merge pull request #116 from launchdarkly/eb/ch32302/experimentation-events"
This reverts commit 29716e6, reversing changes made to 67beb27.
1 parent 082d2d4 commit 1c49f9b

File tree

7 files changed

+11
-249
lines changed

7 files changed

+11
-249
lines changed

src/main/java/com/launchdarkly/client/EventFactory.java

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,11 @@ abstract class EventFactory {
99
protected abstract long getTimestamp();
1010
protected abstract boolean isIncludeReasons();
1111

12-
public Event.FeatureRequest newFeatureRequestEvent(FeatureFlag flag, LDUser user, JsonElement value,
13-
Integer variationIndex, EvaluationReason reason, JsonElement defaultValue, String prereqOf) {
14-
boolean requireExperimentData = isExperiment(flag, reason);
15-
return new Event.FeatureRequest(
16-
getTimestamp(),
17-
flag.getKey(),
18-
user,
19-
flag.getVersion(),
20-
variationIndex,
21-
value,
22-
defaultValue,
23-
prereqOf,
24-
requireExperimentData || flag.isTrackEvents(),
25-
flag.getDebugEventsUntilDate(),
26-
(requireExperimentData || isIncludeReasons()) ? reason : null,
27-
false
28-
);
29-
}
30-
3112
public Event.FeatureRequest newFeatureRequestEvent(FeatureFlag flag, LDUser user, EvaluationDetail<JsonElement> result, JsonElement defaultVal) {
32-
return newFeatureRequestEvent(flag, user, result == null ? null : result.getValue(),
33-
result == null ? null : result.getVariationIndex(), result == null ? null : result.getReason(),
34-
defaultVal, null);
13+
return new Event.FeatureRequest(getTimestamp(), flag.getKey(), user, flag.getVersion(),
14+
result == null ? null : result.getVariationIndex(), result == null ? null : result.getValue(),
15+
defaultVal, null, flag.isTrackEvents(), flag.getDebugEventsUntilDate(),
16+
isIncludeReasons() ? result.getReason() : null, false);
3517
}
3618

3719
public Event.FeatureRequest newDefaultFeatureRequestEvent(FeatureFlag flag, LDUser user, JsonElement defaultValue,
@@ -49,9 +31,10 @@ public Event.FeatureRequest newUnknownFeatureRequestEvent(String key, LDUser use
4931

5032
public Event.FeatureRequest newPrerequisiteFeatureRequestEvent(FeatureFlag prereqFlag, LDUser user, EvaluationDetail<JsonElement> result,
5133
FeatureFlag prereqOf) {
52-
return newFeatureRequestEvent(prereqFlag, user, result == null ? null : result.getValue(),
53-
result == null ? null : result.getVariationIndex(), result == null ? null : result.getReason(),
54-
null, prereqOf.getKey());
34+
return new Event.FeatureRequest(getTimestamp(), prereqFlag.getKey(), user, prereqFlag.getVersion(),
35+
result == null ? null : result.getVariationIndex(), result == null ? null : result.getValue(),
36+
null, prereqOf.getKey(), prereqFlag.isTrackEvents(), prereqFlag.getDebugEventsUntilDate(),
37+
isIncludeReasons() ? result.getReason() : null, false);
5538
}
5639

5740
public Event.FeatureRequest newDebugEvent(Event.FeatureRequest from) {
@@ -67,34 +50,6 @@ public Event.Identify newIdentifyEvent(LDUser user) {
6750
return new Event.Identify(getTimestamp(), user);
6851
}
6952

70-
private boolean isExperiment(FeatureFlag flag, EvaluationReason reason) {
71-
if (reason == null) {
72-
// doesn't happen in real life, but possible in testing
73-
return false;
74-
}
75-
switch (reason.getKind()) {
76-
case FALLTHROUGH:
77-
return flag.isTrackEventsFallthrough();
78-
case RULE_MATCH:
79-
if (!(reason instanceof EvaluationReason.RuleMatch)) {
80-
// shouldn't be possible
81-
return false;
82-
}
83-
EvaluationReason.RuleMatch rm = (EvaluationReason.RuleMatch)reason;
84-
int ruleIndex = rm.getRuleIndex();
85-
// Note, it is OK to rely on the rule index rather than the unique ID in this context, because the
86-
// FeatureFlag that is passed to us here *is* necessarily the same version of the flag that was just
87-
// evaluated, so we cannot be out of sync with its rule list.
88-
if (ruleIndex >= 0 && ruleIndex < flag.getRules().size()) {
89-
Rule rule = flag.getRules().get(ruleIndex);
90-
return rule.isTrackEvents();
91-
}
92-
return false;
93-
default:
94-
return false;
95-
}
96-
}
97-
9853
public static class DefaultEventFactory extends EventFactory {
9954
private final boolean includeReasons;
10055

src/main/java/com/launchdarkly/client/FeatureFlag.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class FeatureFlag implements VersionedData {
3232
private List<JsonElement> variations;
3333
private boolean clientSide;
3434
private boolean trackEvents;
35-
private boolean trackEventsFallthrough;
3635
private Long debugEventsUntilDate;
3736
private boolean deleted;
3837

@@ -49,8 +48,7 @@ static Map<String, FeatureFlag> fromJsonMap(LDConfig config, String json) {
4948

5049
FeatureFlag(String key, int version, boolean on, List<Prerequisite> prerequisites, String salt, List<Target> targets,
5150
List<Rule> rules, VariationOrRollout fallthrough, Integer offVariation, List<JsonElement> variations,
52-
boolean clientSide, boolean trackEvents, boolean trackEventsFallthrough,
53-
Long debugEventsUntilDate, boolean deleted) {
51+
boolean clientSide, boolean trackEvents, Long debugEventsUntilDate, boolean deleted) {
5452
this.key = key;
5553
this.version = version;
5654
this.on = on;
@@ -63,7 +61,6 @@ static Map<String, FeatureFlag> fromJsonMap(LDConfig config, String json) {
6361
this.variations = variations;
6462
this.clientSide = clientSide;
6563
this.trackEvents = trackEvents;
66-
this.trackEventsFallthrough = trackEventsFallthrough;
6764
this.debugEventsUntilDate = debugEventsUntilDate;
6865
this.deleted = deleted;
6966
}
@@ -181,10 +178,6 @@ public boolean isTrackEvents() {
181178
return trackEvents;
182179
}
183180

184-
public boolean isTrackEventsFallthrough() {
185-
return trackEventsFallthrough;
186-
}
187-
188181
public Long getDebugEventsUntilDate() {
189182
return debugEventsUntilDate;
190183
}

src/main/java/com/launchdarkly/client/FeatureFlagBuilder.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class FeatureFlagBuilder {
1919
private List<JsonElement> variations = new ArrayList<>();
2020
private boolean clientSide;
2121
private boolean trackEvents;
22-
private boolean trackEventsFallthrough;
2322
private Long debugEventsUntilDate;
2423
private boolean deleted;
2524

@@ -41,7 +40,6 @@ class FeatureFlagBuilder {
4140
this.variations = f.getVariations();
4241
this.clientSide = f.isClientSide();
4342
this.trackEvents = f.isTrackEvents();
44-
this.trackEventsFallthrough = f.isTrackEventsFallthrough();
4543
this.debugEventsUntilDate = f.getDebugEventsUntilDate();
4644
this.deleted = f.isDeleted();
4745
}
@@ -105,11 +103,6 @@ FeatureFlagBuilder trackEvents(boolean trackEvents) {
105103
this.trackEvents = trackEvents;
106104
return this;
107105
}
108-
109-
FeatureFlagBuilder trackEventsFallthrough(boolean trackEventsFallthrough) {
110-
this.trackEventsFallthrough = trackEventsFallthrough;
111-
return this;
112-
}
113106

114107
FeatureFlagBuilder debugEventsUntilDate(Long debugEventsUntilDate) {
115108
this.debugEventsUntilDate = debugEventsUntilDate;
@@ -123,6 +116,6 @@ FeatureFlagBuilder deleted(boolean deleted) {
123116

124117
FeatureFlag build() {
125118
return new FeatureFlag(key, version, on, prerequisites, salt, targets, rules, fallthrough, offVariation, variations,
126-
clientSide, trackEvents, trackEventsFallthrough, debugEventsUntilDate, deleted);
119+
clientSide, trackEvents, debugEventsUntilDate, deleted);
127120
}
128121
}

src/main/java/com/launchdarkly/client/Rule.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,22 @@
1010
class Rule extends VariationOrRollout {
1111
private String id;
1212
private List<Clause> clauses;
13-
private boolean trackEvents;
1413

1514
// We need this so Gson doesn't complain in certain java environments that restrict unsafe allocation
1615
Rule() {
1716
super();
1817
}
1918

20-
Rule(String id, List<Clause> clauses, Integer variation, Rollout rollout, boolean trackEvents) {
19+
Rule(String id, List<Clause> clauses, Integer variation, Rollout rollout) {
2120
super(variation, rollout);
2221
this.id = id;
2322
this.clauses = clauses;
24-
this.trackEvents = trackEvents;
25-
}
26-
27-
Rule(String id, List<Clause> clauses, Integer variation, Rollout rollout) {
28-
this(id, clauses, variation, rollout, false);
2923
}
3024

3125
String getId() {
3226
return id;
3327
}
3428

35-
Iterable<Clause> getClauses() {
36-
return clauses;
37-
}
38-
39-
boolean isTrackEvents() {
40-
return trackEvents;
41-
}
42-
4329
boolean matchesUser(FeatureStore store, LDUser user) {
4430
for (Clause clause : clauses) {
4531
if (!clause.matchesUser(store, user)) {

src/test/java/com/launchdarkly/client/LDClientEventTest.java

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@
1515
import static com.launchdarkly.client.TestUtil.jdouble;
1616
import static com.launchdarkly.client.TestUtil.jint;
1717
import static com.launchdarkly.client.TestUtil.js;
18-
import static com.launchdarkly.client.TestUtil.makeClauseToMatchUser;
19-
import static com.launchdarkly.client.TestUtil.makeClauseToNotMatchUser;
2018
import static com.launchdarkly.client.TestUtil.specificEventProcessor;
2119
import static com.launchdarkly.client.TestUtil.specificFeatureStore;
2220
import static com.launchdarkly.client.VersionedDataKind.FEATURES;
2321
import static org.junit.Assert.assertEquals;
24-
import static org.junit.Assert.assertFalse;
2522
import static org.junit.Assert.assertNull;
26-
import static org.junit.Assert.assertTrue;
2723

2824
public class LDClientEventTest {
2925
private static final LDUser user = new LDUser("userkey");
@@ -261,111 +257,6 @@ public void jsonVariationDetailSendsEventForUnknownFlag() throws Exception {
261257
EvaluationReason.error(ErrorKind.FLAG_NOT_FOUND));
262258
}
263259

264-
@Test
265-
public void eventTrackingAndReasonCanBeForcedForRule() throws Exception {
266-
Clause clause = makeClauseToMatchUser(user);
267-
Rule rule = new RuleBuilder().id("id").clauses(clause).variation(1).trackEvents(true).build();
268-
FeatureFlag flag = new FeatureFlagBuilder("flag")
269-
.on(true)
270-
.rules(Arrays.asList(rule))
271-
.offVariation(0)
272-
.variations(js("off"), js("on"))
273-
.build();
274-
featureStore.upsert(FEATURES, flag);
275-
276-
client.stringVariation("flag", user, "default");
277-
278-
// Note, we did not call stringVariationDetail and the flag is not tracked, but we should still get
279-
// tracking and a reason, because the rule-level trackEvents flag is on for the matched rule.
280-
281-
assertEquals(1, eventSink.events.size());
282-
Event.FeatureRequest event = (Event.FeatureRequest)eventSink.events.get(0);
283-
assertTrue(event.trackEvents);
284-
assertEquals(EvaluationReason.ruleMatch(0, "id"), event.reason);
285-
}
286-
287-
@Test
288-
public void eventTrackingAndReasonAreNotForcedIfFlagIsNotSetForMatchingRule() throws Exception {
289-
Clause clause0 = makeClauseToNotMatchUser(user);
290-
Clause clause1 = makeClauseToMatchUser(user);
291-
Rule rule0 = new RuleBuilder().id("id0").clauses(clause0).variation(1).trackEvents(true).build();
292-
Rule rule1 = new RuleBuilder().id("id1").clauses(clause1).variation(1).trackEvents(false).build();
293-
FeatureFlag flag = new FeatureFlagBuilder("flag")
294-
.on(true)
295-
.rules(Arrays.asList(rule0, rule1))
296-
.offVariation(0)
297-
.variations(js("off"), js("on"))
298-
.build();
299-
featureStore.upsert(FEATURES, flag);
300-
301-
client.stringVariation("flag", user, "default");
302-
303-
// It matched rule1, which has trackEvents: false, so we don't get the override behavior
304-
305-
assertEquals(1, eventSink.events.size());
306-
Event.FeatureRequest event = (Event.FeatureRequest)eventSink.events.get(0);
307-
assertFalse(event.trackEvents);
308-
assertNull(event.reason);
309-
}
310-
311-
@Test
312-
public void eventTrackingAndReasonCanBeForcedForFallthrough() throws Exception {
313-
FeatureFlag flag = new FeatureFlagBuilder("flag")
314-
.on(true)
315-
.fallthrough(new VariationOrRollout(0, null))
316-
.variations(js("fall"), js("off"), js("on"))
317-
.trackEventsFallthrough(true)
318-
.build();
319-
featureStore.upsert(FEATURES, flag);
320-
321-
client.stringVariation("flag", user, "default");
322-
323-
// Note, we did not call stringVariationDetail and the flag is not tracked, but we should still get
324-
// tracking and a reason, because trackEventsFallthrough is on and the evaluation fell through.
325-
326-
assertEquals(1, eventSink.events.size());
327-
Event.FeatureRequest event = (Event.FeatureRequest)eventSink.events.get(0);
328-
assertTrue(event.trackEvents);
329-
assertEquals(EvaluationReason.fallthrough(), event.reason);
330-
}
331-
332-
@Test
333-
public void eventTrackingAndReasonAreNotForcedForFallthroughIfFlagIsNotSet() throws Exception {
334-
FeatureFlag flag = new FeatureFlagBuilder("flag")
335-
.on(true)
336-
.fallthrough(new VariationOrRollout(0, null))
337-
.variations(js("fall"), js("off"), js("on"))
338-
.trackEventsFallthrough(false)
339-
.build();
340-
featureStore.upsert(FEATURES, flag);
341-
342-
client.stringVariation("flag", user, "default");
343-
344-
assertEquals(1, eventSink.events.size());
345-
Event.FeatureRequest event = (Event.FeatureRequest)eventSink.events.get(0);
346-
assertFalse(event.trackEvents);
347-
assertNull(event.reason);
348-
}
349-
350-
@Test
351-
public void eventTrackingAndReasonAreNotForcedForFallthroughIfReasonIsNotFallthrough() throws Exception {
352-
FeatureFlag flag = new FeatureFlagBuilder("flag")
353-
.on(false) // so the evaluation reason will be OFF, not FALLTHROUGH
354-
.offVariation(1)
355-
.fallthrough(new VariationOrRollout(0, null))
356-
.variations(js("fall"), js("off"), js("on"))
357-
.trackEventsFallthrough(true)
358-
.build();
359-
featureStore.upsert(FEATURES, flag);
360-
361-
client.stringVariation("flag", user, "default");
362-
363-
assertEquals(1, eventSink.events.size());
364-
Event.FeatureRequest event = (Event.FeatureRequest)eventSink.events.get(0);
365-
assertFalse(event.trackEvents);
366-
assertNull(event.reason);
367-
}
368-
369260
@Test
370261
public void eventIsSentForExistingPrererequisiteFlag() throws Exception {
371262
FeatureFlag f0 = new FeatureFlagBuilder("feature0")
@@ -466,8 +357,6 @@ private void checkFeatureEvent(Event e, FeatureFlag flag, JsonElement value, Jso
466357
assertEquals(defaultVal, fe.defaultVal);
467358
assertEquals(prereqOf, fe.prereqOf);
468359
assertEquals(reason, fe.reason);
469-
assertEquals(flag.isTrackEvents(), fe.trackEvents);
470-
assertEquals(flag.getDebugEventsUntilDate(), fe.debugEventsUntilDate);
471360
}
472361

473362
private void checkUnknownFeatureEvent(Event e, String key, JsonElement defaultVal, String prereqOf,
@@ -481,7 +370,5 @@ private void checkUnknownFeatureEvent(Event e, String key, JsonElement defaultVa
481370
assertEquals(defaultVal, fe.defaultVal);
482371
assertEquals(prereqOf, fe.prereqOf);
483372
assertEquals(reason, fe.reason);
484-
assertFalse(fe.trackEvents);
485-
assertNull(fe.debugEventsUntilDate);
486373
}
487374
}

src/test/java/com/launchdarkly/client/RuleBuilder.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/test/java/com/launchdarkly/client/TestUtil.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,6 @@ public static FeatureFlag flagWithValue(String key, JsonElement value) {
176176
.build();
177177
}
178178

179-
public static Clause makeClauseToMatchUser(LDUser user) {
180-
return new Clause("key", Operator.in, Arrays.asList(user.getKey()), false);
181-
}
182-
183-
public static Clause makeClauseToNotMatchUser(LDUser user) {
184-
return new Clause("key", Operator.in, Arrays.asList(js("not-" + user.getKeyAsString())), false);
185-
}
186-
187179
public static class DataBuilder {
188180
private Map<VersionedDataKind<?>, Map<String, ? extends VersionedData>> data = new HashMap<>();
189181

0 commit comments

Comments
 (0)