Skip to content

Commit

Permalink
Telemetry for new evaluation methods (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea authored Sep 7, 2023
2 parents 9700043 + a41f7db commit bb66c9f
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ public class MethodExceptions {
@SerializedName("tcs")
private long treatmentsWithConfig;

@SerializedName("tf")
private long treatmentsByFlagSet;

@SerializedName("tfs")
private long treatmentsByFlagSets;

@SerializedName("tcf")
private long treatmentsWithConfigByFlagSet;

@SerializedName("tcfs")
private long treatmentsWithConfigByFlagSets;

@SerializedName("tr")
private long track;

Expand Down Expand Up @@ -51,6 +63,38 @@ public void setTreatmentsWithConfig(long treatmentsWithConfig) {
this.treatmentsWithConfig = treatmentsWithConfig;
}

public void setTreatmentsByFlagSet(long treatmentsByFlagSet) {
this.treatmentsByFlagSet = treatmentsByFlagSet;
}

public long getTreatmentsByFlagSet() {
return treatmentsByFlagSet;
}

public void setTreatmentsByFlagSets(long treatmentsByFlagSets) {
this.treatmentsByFlagSets = treatmentsByFlagSets;
}

public long getTreatmentsByFlagSets() {
return treatmentsByFlagSets;
}

public void setTreatmentsWithConfigByFlagSet(long treatmentsWithConfigByFlagSet) {
this.treatmentsWithConfigByFlagSet = treatmentsWithConfigByFlagSet;
}

public long getTreatmentsWithConfigByFlagSet() {
return treatmentsWithConfigByFlagSet;
}

public void setTreatmentsWithConfigByFlagSets(long treatmentsWithConfigByFlagSets) {
this.treatmentsWithConfigByFlagSets = treatmentsWithConfigByFlagSets;
}

public long getTreatmentsWithConfigByFlagSets() {
return treatmentsWithConfigByFlagSets;
}

public long getTrack() {
return track;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ public class MethodLatencies {
@SerializedName("tcs")
private List<Long> treatmentsWithConfig;

@SerializedName("tf")
private List<Long> treatmentsByFlagSet;

@SerializedName("tfs")
private List<Long> treatmentsByFlagSets;

@SerializedName("tcf")
private List<Long> treatmentsWithConfigByFlagSet;

@SerializedName("tcfs")
private List<Long> treatmentsWithConfigByFlagSets;

@SerializedName("tr")
private List<Long> track;

Expand Down Expand Up @@ -53,6 +65,38 @@ public void setTreatmentsWithConfig(List<Long> treatmentsWithConfig) {
this.treatmentsWithConfig = treatmentsWithConfig;
}

public void setTreatmentsByFlagSet(List<Long> treatmentsByFlagSet) {
this.treatmentsByFlagSet = treatmentsByFlagSet;
}

public List<Long> getTreatmentsByFlagSet() {
return treatmentsByFlagSet;
}

public void setTreatmentsByFlagSets(List<Long> treatmentsByFlagSets) {
this.treatmentsByFlagSets = treatmentsByFlagSets;
}

public List<Long> getTreatmentsByFlagSets() {
return treatmentsByFlagSets;
}

public void setTreatmentsWithConfigByFlagSet(List<Long> treatmentsWithConfigByFlagSet) {
this.treatmentsWithConfigByFlagSet = treatmentsWithConfigByFlagSet;
}

public List<Long> getTreatmentsWithConfigByFlagSet() {
return treatmentsWithConfigByFlagSet;
}

public void setTreatmentsWithConfigByFlagSets(List<Long> treatmentsWithConfigByFlagSets) {
this.treatmentsWithConfigByFlagSets = treatmentsWithConfigByFlagSets;
}

public List<Long> getTreatmentsWithConfigByFlagSets() {
return treatmentsWithConfigByFlagSets;
}

public List<Long> getTrack() {
return track;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public MethodExceptions popExceptions() {
methodExceptions.setTreatmentWithConfig(methodExceptionsCounter.get(Method.TREATMENT_WITH_CONFIG).getAndSet(0L));
methodExceptions.setTreatmentsWithConfig(methodExceptionsCounter.get(Method.TREATMENTS_WITH_CONFIG).getAndSet(0L));
methodExceptions.setTrack(methodExceptionsCounter.get(Method.TRACK).getAndSet(0L));
methodExceptions.setTreatmentsByFlagSet(methodExceptionsCounter.get(Method.TREATMENTS_BY_FLAG_SET).getAndSet(0L));
methodExceptions.setTreatmentsByFlagSets(methodExceptionsCounter.get(Method.TREATMENTS_BY_FLAG_SETS).getAndSet(0L));
methodExceptions.setTreatmentsWithConfigByFlagSet(methodExceptionsCounter.get(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET).getAndSet(0L));
methodExceptions.setTreatmentsWithConfigByFlagSets(methodExceptionsCounter.get(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS).getAndSet(0L));

return methodExceptions;
}
Expand All @@ -86,6 +90,10 @@ public MethodLatencies popLatencies() {
latencies.setTreatments(popLatencies(Method.TREATMENTS));
latencies.setTreatmentWithConfig(popLatencies(Method.TREATMENT_WITH_CONFIG));
latencies.setTreatmentsWithConfig(popLatencies(Method.TREATMENTS_WITH_CONFIG));
latencies.setTreatmentsByFlagSet(popLatencies(Method.TREATMENTS_BY_FLAG_SET));
latencies.setTreatmentsByFlagSets(popLatencies(Method.TREATMENTS_BY_FLAG_SETS));
latencies.setTreatmentsWithConfigByFlagSet(popLatencies(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET));
latencies.setTreatmentsWithConfigByFlagSets(popLatencies(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS));
latencies.setTrack(popLatencies(Method.TRACK));

return latencies;
Expand Down Expand Up @@ -354,7 +362,7 @@ public void recordUpdatesFromSSE(UpdatesFromSSEEnum sseUpdate) {

private void initializeProperties() {
initializeMethodExceptionsCounter();
initializeHttpLatenciesCounter();
initializeMethodLatenciesCounter();
initializeFactoryCounters();
initializeImpressionsData();
initializeEventsData();
Expand All @@ -365,12 +373,16 @@ private void initializeProperties() {
initializeUpdatesFromSSE();
}

private void initializeHttpLatenciesCounter() {
private void initializeMethodLatenciesCounter() {
methodLatencies.put(Method.TREATMENT, new BinarySearchLatencyTracker());
methodLatencies.put(Method.TREATMENTS, new BinarySearchLatencyTracker());
methodLatencies.put(Method.TREATMENT_WITH_CONFIG, new BinarySearchLatencyTracker());
methodLatencies.put(Method.TREATMENTS_WITH_CONFIG, new BinarySearchLatencyTracker());
methodLatencies.put(Method.TRACK, new BinarySearchLatencyTracker());
methodLatencies.put(Method.TREATMENTS_BY_FLAG_SET, new BinarySearchLatencyTracker());
methodLatencies.put(Method.TREATMENTS_BY_FLAG_SETS, new BinarySearchLatencyTracker());
methodLatencies.put(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET, new BinarySearchLatencyTracker());
methodLatencies.put(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, new BinarySearchLatencyTracker());
}

private void initializeMethodExceptionsCounter() {
Expand All @@ -379,6 +391,10 @@ private void initializeMethodExceptionsCounter() {
methodExceptionsCounter.put(Method.TREATMENT_WITH_CONFIG, new AtomicLong());
methodExceptionsCounter.put(Method.TREATMENTS_WITH_CONFIG, new AtomicLong());
methodExceptionsCounter.put(Method.TRACK, new AtomicLong());
methodExceptionsCounter.put(Method.TREATMENTS_BY_FLAG_SET, new AtomicLong());
methodExceptionsCounter.put(Method.TREATMENTS_BY_FLAG_SETS, new AtomicLong());
methodExceptionsCounter.put(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET, new AtomicLong());
methodExceptionsCounter.put(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, new AtomicLong());
}

private void initializeFactoryCounters() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.split.android.client;

import static org.mockito.Mockito.verify;

import org.junit.Test;

import java.util.Collections;
import java.util.Map;

public class SplitClientImplFlagSetsTest extends SplitClientImplBaseTest {

@Test
public void getTreatmentsByFlagSetDelegatesToTreatmentManager() {
Map<String, Object> attributes = Collections.singletonMap("key", "value");
splitClient.getTreatmentsByFlagSet("set", attributes);

verify(treatmentManager).getTreatmentsByFlagSet("set", attributes, false);
}

@Test
public void getTreatmentsByFlagSetsDelegatesToTreatmentManager() {
Map<String, Object> attributes = Collections.singletonMap("key", "value");
splitClient.getTreatmentsByFlagSets(Collections.singletonList("set"), attributes);

verify(treatmentManager).getTreatmentsByFlagSets(Collections.singletonList("set"), attributes, false);
}

@Test
public void getTreatmentsWithConfigByFlagSetDelegatesToTreatmentManager() {
Map<String, Object> attributes = Collections.singletonMap("key", "value");
splitClient.getTreatmentsWithConfigByFlagSet("set", attributes);

verify(treatmentManager).getTreatmentsWithConfigByFlagSet("set", attributes, false);
}

@Test
public void getTreatmentsWithConfigByFlagSetsDelegatesToTreatmentManager() {
Map<String, Object> attributes = Collections.singletonMap("key", "value");
splitClient.getTreatmentsWithConfigByFlagSets(Collections.singletonList("set"), attributes);

verify(treatmentManager).getTreatmentsWithConfigByFlagSets(Collections.singletonList("set"), attributes, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,40 @@ public void getTreatmentsWithConfigByFlagSetsRecordsTelemetry() {

verify(mTelemetryStorageProducer).recordLatency(eq(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS), anyLong());
}

@Test
public void getTreatmentsByFlagSetExceptionIsRecordedInTelemetry() {
when(mSplitsStorage.getNamesByFlagSets(any())).thenThrow(new RuntimeException("test"));

mTreatmentManager.getTreatmentsByFlagSet("set_1", null, false);

verify(mTelemetryStorageProducer).recordException(eq(Method.TREATMENTS_BY_FLAG_SET));
}

@Test
public void getTreatmentsByFlagSetsExceptionIsRecordedInTelemetry() {
when(mSplitsStorage.getNamesByFlagSets(any())).thenThrow(new RuntimeException("test"));

mTreatmentManager.getTreatmentsByFlagSets(Arrays.asList("set_1", "set_2"), null, false);

verify(mTelemetryStorageProducer).recordException(eq(Method.TREATMENTS_BY_FLAG_SETS));
}

@Test
public void getTreatmentsWithConfigByFlagSetExceptionIsRecordedInTelemetry() {
when(mSplitsStorage.getNamesByFlagSets(any())).thenThrow(new RuntimeException("test"));

mTreatmentManager.getTreatmentsWithConfigByFlagSet("set_1", null, false);

verify(mTelemetryStorageProducer).recordException(eq(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET));
}

@Test
public void getTreatmentsWithConfigByFlagSetsExceptionIsRecordedInTelemetry() {
when(mSplitsStorage.getNamesByFlagSets(any())).thenThrow(new RuntimeException("test"));

mTreatmentManager.getTreatmentsWithConfigByFlagSets(Arrays.asList("set_1", "set_2"), null, false);

verify(mTelemetryStorageProducer).recordException(eq(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void setUp() {
public void jsonIsBuiltAsExpected() {
String serializedStats = telemetryStatsBodySerializer.serialize(getMockStats());

assertEquals("{\"lS\":{\"sp\":1000,\"ms\":2000,\"im\":3000,\"ic\":4000,\"ev\":5000,\"te\":6000,\"to\":7000},\"mL\":{\"t\":[0,0,2,0],\"ts\":[0,0,3,0],\"tc\":[0,0,5,0],\"tcs\":[0,0,4,0],\"tr\":[0,0,1,0]},\"mE\":{\"t\":2,\"ts\":3,\"tc\":5,\"tcs\":4,\"tr\":1},\"hE\":{},\"hL\":{\"sp\":[0,0,3,0],\"ms\":[0,0,5,0],\"im\":[0,0,1,0],\"ic\":[0,0,4,0],\"ev\":[0,0,2,0],\"te\":[1,0,0,0],\"to\":[0,0,6,0]},\"tR\":4,\"aR\":5,\"iQ\":2,\"iDe\":5,\"iDr\":4,\"spC\":456,\"seC\":4,\"skC\":1,\"sL\":2000,\"eQ\":4,\"eD\":2,\"sE\":[{\"e\":0,\"t\":5000},{\"e\":20,\"d\":4,\"t\":2000}],\"t\":[\"tag1\",\"tag2\"],\"ufs\":{\"sp\":4,\"ms\":8}}", serializedStats);
assertEquals("{\"lS\":{\"sp\":1000,\"ms\":2000,\"im\":3000,\"ic\":4000,\"ev\":5000,\"te\":6000,\"to\":7000},\"mL\":{\"t\":[0,0,2,0],\"ts\":[0,0,3,0],\"tc\":[0,0,5,0],\"tcs\":[0,0,4,0],\"tf\":[1,0,0,0],\"tfs\":[2,0,0,0],\"tcf\":[3,0,0,0],\"tcfs\":[4,0,0,0],\"tr\":[0,0,1,0]},\"mE\":{\"t\":2,\"ts\":3,\"tc\":5,\"tcs\":4,\"tf\":10,\"tfs\":20,\"tcf\":30,\"tcfs\":40,\"tr\":1},\"hE\":{},\"hL\":{\"sp\":[0,0,3,0],\"ms\":[0,0,5,0],\"im\":[0,0,1,0],\"ic\":[0,0,4,0],\"ev\":[0,0,2,0],\"te\":[1,0,0,0],\"to\":[0,0,6,0]},\"tR\":4,\"aR\":5,\"iQ\":2,\"iDe\":5,\"iDr\":4,\"spC\":456,\"seC\":4,\"skC\":1,\"sL\":2000,\"eQ\":4,\"eD\":2,\"sE\":[{\"e\":0,\"t\":5000},{\"e\":20,\"d\":4,\"t\":2000}],\"t\":[\"tag1\",\"tag2\"],\"ufs\":{\"sp\":4,\"ms\":8}}", serializedStats);
}

private Stats getMockStats() {
Expand All @@ -54,13 +54,21 @@ private Stats getMockStats() {
methodLatencies.setTreatments(Arrays.asList(0L, 0L, 3L, 0L));
methodLatencies.setTreatmentsWithConfig(Arrays.asList(0L, 0L, 4L, 0L));
methodLatencies.setTreatmentWithConfig(Arrays.asList(0L, 0L, 5L, 0L));
methodLatencies.setTreatmentsByFlagSet(Arrays.asList(1L, 0L, 0L, 0L));
methodLatencies.setTreatmentsByFlagSets(Arrays.asList(2L, 0L, 0L, 0L));
methodLatencies.setTreatmentsWithConfigByFlagSet(Arrays.asList(3L, 0L, 0L, 0L));
methodLatencies.setTreatmentsWithConfigByFlagSets(Arrays.asList(4L, 0L, 0L, 0L));

MethodExceptions methodExceptions = new MethodExceptions();
methodExceptions.setTrack(1);
methodExceptions.setTreatment(2);
methodExceptions.setTreatments(3);
methodExceptions.setTreatmentsWithConfig(4);
methodExceptions.setTreatmentWithConfig(5);
methodExceptions.setTreatmentsByFlagSet(10);
methodExceptions.setTreatmentsByFlagSets(20);
methodExceptions.setTreatmentsWithConfigByFlagSet(30);
methodExceptions.setTreatmentsWithConfigByFlagSets(40);

stats.setHttpLatencies(httpLatencies);
stats.setAuthRejections(5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public void popExceptionsReturnsCorrectlyBuiltMethodExceptions() {
telemetryStorage.recordException(Method.TREATMENTS);
telemetryStorage.recordException(Method.TREATMENTS_WITH_CONFIG);
telemetryStorage.recordException(Method.TREATMENT_WITH_CONFIG);
telemetryStorage.recordException(Method.TREATMENTS_BY_FLAG_SET);
telemetryStorage.recordException(Method.TREATMENTS_BY_FLAG_SETS);
telemetryStorage.recordException(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
telemetryStorage.recordException(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);

MethodExceptions methodExceptions = telemetryStorage.popExceptions();

Expand All @@ -58,6 +62,10 @@ public void popExceptionsReturnsCorrectlyBuiltMethodExceptions() {
assertEquals(1, methodExceptions.getTreatments());
assertEquals(1, methodExceptions.getTreatmentsWithConfig());
assertEquals(1, methodExceptions.getTreatmentWithConfig());
assertEquals(1, methodExceptions.getTreatmentsByFlagSet());
assertEquals(1, methodExceptions.getTreatmentsByFlagSets());
assertEquals(1, methodExceptions.getTreatmentsWithConfigByFlagSet());
assertEquals(1, methodExceptions.getTreatmentsWithConfigByFlagSets());
}

@Test
Expand All @@ -68,6 +76,10 @@ public void popExceptionsEmptiesCounters() {
telemetryStorage.recordException(Method.TREATMENTS);
telemetryStorage.recordException(Method.TREATMENTS_WITH_CONFIG);
telemetryStorage.recordException(Method.TREATMENT_WITH_CONFIG);
telemetryStorage.recordException(Method.TREATMENTS_BY_FLAG_SET);
telemetryStorage.recordException(Method.TREATMENTS_BY_FLAG_SETS);
telemetryStorage.recordException(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET);
telemetryStorage.recordException(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS);

telemetryStorage.popExceptions();

Expand All @@ -78,6 +90,10 @@ public void popExceptionsEmptiesCounters() {
assertEquals(0, secondPop.getTreatments());
assertEquals(0, secondPop.getTreatmentsWithConfig());
assertEquals(0, secondPop.getTreatmentWithConfig());
assertEquals(0, secondPop.getTreatmentsByFlagSet());
assertEquals(0, secondPop.getTreatmentsByFlagSets());
assertEquals(0, secondPop.getTreatmentsWithConfigByFlagSet());
assertEquals(0, secondPop.getTreatmentsWithConfigByFlagSets());
}

@Test
Expand All @@ -89,6 +105,10 @@ public void popLatenciesReturnsCorrectlyBuiltObject() {
telemetryStorage.recordLatency(Method.TREATMENTS, 200);
telemetryStorage.recordLatency(Method.TREATMENTS_WITH_CONFIG, 10);
telemetryStorage.recordLatency(Method.TREATMENT_WITH_CONFIG, 2000);
telemetryStorage.recordLatency(Method.TREATMENTS_BY_FLAG_SET, 15);
telemetryStorage.recordLatency(Method.TREATMENTS_BY_FLAG_SETS, 14);
telemetryStorage.recordLatency(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET, 15);
telemetryStorage.recordLatency(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, 14);

MethodLatencies methodLatencies = telemetryStorage.popLatencies();

Expand All @@ -97,12 +117,20 @@ public void popLatenciesReturnsCorrectlyBuiltObject() {
assertFalse(methodLatencies.getTreatments().stream().allMatch(l -> l == 0));
assertFalse(methodLatencies.getTreatmentsWithConfig().stream().allMatch(l -> l == 0));
assertFalse(methodLatencies.getTreatmentWithConfig().stream().allMatch(l -> l == 0));
assertFalse(methodLatencies.getTreatmentsByFlagSet().stream().allMatch(l -> l == 0));
assertFalse(methodLatencies.getTreatmentsByFlagSets().stream().allMatch(l -> l == 0));
assertFalse(methodLatencies.getTreatmentsWithConfigByFlagSet().stream().allMatch(l -> l == 0));
assertFalse(methodLatencies.getTreatmentsWithConfigByFlagSets().stream().allMatch(l -> l == 0));

assertEquals(1, (long) methodLatencies.getTreatment().get(15));
assertEquals(1, (long) methodLatencies.getTreatments().get(14));
assertEquals(1, (long) methodLatencies.getTreatmentWithConfig().get(19));
assertEquals(1, (long) methodLatencies.getTreatmentsWithConfig().get(6));
assertEquals(1, (long) methodLatencies.getTrack().get(14));
assertEquals(1, (long) methodLatencies.getTreatmentsByFlagSet().get(7));
assertEquals(1, (long) methodLatencies.getTreatmentsByFlagSets().get(7));
assertEquals(1, (long) methodLatencies.getTreatmentsWithConfigByFlagSet().get(7));
assertEquals(1, (long) methodLatencies.getTreatmentsWithConfigByFlagSets().get(7));
}

@Test
Expand All @@ -113,6 +141,10 @@ public void secondLatenciesPopHasArraysSetIn0() {
telemetryStorage.recordLatency(Method.TREATMENTS, 200);
telemetryStorage.recordLatency(Method.TREATMENTS_WITH_CONFIG, 10);
telemetryStorage.recordLatency(Method.TREATMENT_WITH_CONFIG, 2000);
telemetryStorage.recordLatency(Method.TREATMENTS_BY_FLAG_SET, 15);
telemetryStorage.recordLatency(Method.TREATMENTS_BY_FLAG_SETS, 14);
telemetryStorage.recordLatency(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SET, 15);
telemetryStorage.recordLatency(Method.TREATMENTS_WITH_CONFIG_BY_FLAG_SETS, 14);

telemetryStorage.popLatencies();

Expand All @@ -123,6 +155,10 @@ public void secondLatenciesPopHasArraysSetIn0() {
assertTrue(methodLatencies.getTreatments().stream().allMatch(l -> l == 0));
assertTrue(methodLatencies.getTreatmentsWithConfig().stream().allMatch(l -> l == 0));
assertTrue(methodLatencies.getTreatmentWithConfig().stream().allMatch(l -> l == 0));
assertTrue(methodLatencies.getTreatmentsByFlagSet().stream().allMatch(l -> l == 0));
assertTrue(methodLatencies.getTreatmentsByFlagSets().stream().allMatch(l -> l == 0));
assertTrue(methodLatencies.getTreatmentsWithConfigByFlagSet().stream().allMatch(l -> l == 0));
assertTrue(methodLatencies.getTreatmentsWithConfigByFlagSets().stream().allMatch(l -> l == 0));
}

@Test
Expand Down

0 comments on commit bb66c9f

Please sign in to comment.