Skip to content

Commit

Permalink
Fix invalid & total value count
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Oct 17, 2023
1 parent debe7b2 commit 0ca5461
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,9 @@ public MockResponse dispatch(RecordedRequest request) {
initializeClient(false, "a", "_b", "a", "a", "c", "d", "_d");
metricsLatch.await(20, TimeUnit.SECONDS);
String s = metricsPayload.get();
assertTrue(s.contains("\"fsT\":5"));
assertTrue(s.contains("\"fsI\":2"));
Logger.e("S is: " + s);
assertTrue(s.contains("\"fsI\":4"));
assertTrue(s.contains("\"fsT\":7"));
}

private void initializeClient(boolean streamingEnabled, String ... sets) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/split/android/client/SplitFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public int maxValuesCount() {
private final SplitFilter.Type mType;
private final List<String> mValues;
private int mInvalidValueCount;
private int mTotalValueCount;

public static SplitFilter byName(@NonNull List<String> values) {
return new SplitFilter(Type.BY_NAME, values);
Expand All @@ -71,6 +72,9 @@ public static SplitFilter byPrefix(@NonNull List<String> values) {
}

public static SplitFilter bySet(@NonNull List<String> values) {
if (values == null) {
values = new ArrayList<>();
}
return new SplitFilter(Type.BY_SET, values, new FlagSetsValidatorImpl());
}

Expand All @@ -89,6 +93,7 @@ public static SplitFilter bySet(@NonNull List<String> values) {
SplitFilterValidator.ValidationResult validationResult = validator.cleanup("SDK config", values);
mValues = validationResult.getValues();
mInvalidValueCount = validationResult.getInvalidValueCount();
mTotalValueCount = (values != null) ? values.size() - validationResult.getInvalidValueCount() : 0;
}

public Type getType() {
Expand All @@ -102,4 +107,8 @@ public List<String> getValues() {
public int getInvalidValueCount() {
return mInvalidValueCount;
}

public int getTotalValueCount() {
return mTotalValueCount;
}
}
14 changes: 11 additions & 3 deletions src/main/java/io/split/android/client/SyncConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ public class SyncConfig {

private final List<SplitFilter> mFilters;

private int mInvalidValueCount = 0;
private final int mInvalidValueCount;
private final int mTotalValueCount;

private SyncConfig(List<SplitFilter> filters, int invalidValueCount) {
private SyncConfig(List<SplitFilter> filters, int invalidValueCount, int totalValueCount) {
mFilters = filters;
mInvalidValueCount = invalidValueCount;
mTotalValueCount = totalValueCount;
}

public List<SplitFilter> getFilters() {
Expand All @@ -28,13 +30,18 @@ public int getInvalidValueCount() {
return mInvalidValueCount;
}

public int getTotalValueCount() {
return mTotalValueCount;
}

public static Builder builder() {
return new Builder();
}

public static class Builder {
private final List<SplitFilter> mBuilderFilters = new ArrayList<>();
private int mInvalidValueCount = 0;
private int mTotalValueCount = 0;
private final SplitValidator mSplitValidator = new SplitValidatorImpl();

public SyncConfig build() {
Expand All @@ -53,7 +60,7 @@ public SyncConfig build() {
validatedFilters.add(new SplitFilter(filter.getType(), validatedValues));
}
}
return new SyncConfig(validatedFilters, mInvalidValueCount);
return new SyncConfig(validatedFilters, mInvalidValueCount, mTotalValueCount);
}

public Builder addSplitFilter(@NonNull SplitFilter filter) {
Expand All @@ -62,6 +69,7 @@ public Builder addSplitFilter(@NonNull SplitFilter filter) {
}
mBuilderFilters.add(filter);
mInvalidValueCount += filter.getInvalidValueCount();
mTotalValueCount += filter.getTotalValueCount();
return this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,15 @@ public SplitInPlaceUpdateTask createSplitsUpdateTask(Split featureFlag, long sin
@NonNull
private TelemetryTaskFactory initializeTelemetryTaskFactory(@NonNull SplitClientConfig splitClientConfig, @Nullable Map<SplitFilter.Type, SplitFilter> filters, TelemetryStorage telemetryStorage) {
final TelemetryTaskFactory mTelemetryTaskFactory;
int flagSetCount = 0;
int invalidFlagSetCount = 0;
int totalFlagSetCount = 0;
if (filters != null && !filters.isEmpty()) {
SplitFilter bySetFilter = filters.get(SplitFilter.Type.BY_SET);
if (bySetFilter != null) {
flagSetCount = bySetFilter.getValues().size();
invalidFlagSetCount = (splitClientConfig.syncConfig() != null) ?
splitClientConfig.syncConfig().getInvalidValueCount() : 0;
if (splitClientConfig.syncConfig() != null) {
invalidFlagSetCount = splitClientConfig.syncConfig().getInvalidValueCount();
totalFlagSetCount = splitClientConfig.syncConfig().getTotalValueCount();
}
}
}

Expand All @@ -217,7 +218,7 @@ private TelemetryTaskFactory initializeTelemetryTaskFactory(@NonNull SplitClient
splitClientConfig,
mSplitsStorageContainer.getSplitsStorage(),
mSplitsStorageContainer.getMySegmentsStorageContainer(),
flagSetCount,
totalFlagSetCount,
invalidFlagSetCount);
return mTelemetryTaskFactory;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ public ValidationResult cleanup(String method, List<String> values) {
}

if (set.matches(FLAG_SET_REGEX)) {
cleanedUpSets.add(set);
if (cleanedUpSets.contains(set)) {
invalidValueCount++;
} else {
cleanedUpSets.add(set);
}
} else {
invalidValueCount++;
Logger.w(method + ": you passed "+ set +", Flag Set must adhere to the regular expressions "+ FLAG_SET_REGEX +". This means a Flag Set must be start with a letter, be in lowercase, alphanumeric and have a max length of 50 characters. "+ set +" was discarded.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void duplicatedInputValuesAreRemoved() {
SplitFilterValidator.ValidationResult result = mValidator.cleanup("method", Arrays.asList("set1", "set1"));
assertEquals(1, result.getValues().size());
assertTrue(result.getValues().contains("set1"));
assertEquals(0, result.getInvalidValueCount());
assertEquals(1, result.getInvalidValueCount());
}

@Test
Expand Down

0 comments on commit 0ca5461

Please sign in to comment.