Skip to content

Commit

Permalink
[SDKS-7538] Add flag sets in Init Config
Browse files Browse the repository at this point in the history
  • Loading branch information
nmayorsplit committed Oct 4, 2023
1 parent 0d3a832 commit 8532a5a
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 126 deletions.
20 changes: 17 additions & 3 deletions client/src/main/java/io/split/client/SplitClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.split.client.impressions.ImpressionListener;
import io.split.client.impressions.ImpressionsManager;
import io.split.client.utils.FileTypeEnum;
import io.split.inputValidation.FSValidatorResult;
import io.split.integrations.IntegrationsConfig;
import io.split.storages.enums.OperationMode;
import io.split.storages.enums.StorageMode;
Expand Down Expand Up @@ -89,6 +90,7 @@ public class SplitClientConfig {
public static String splitSdkVersion;
private final long _lastSeenCacheSize;
private final HashSet<String> _flagSetsFilter;
private final int _invalidSets;

public static Builder builder() {
return new Builder();
Expand Down Expand Up @@ -144,7 +146,8 @@ private SplitClientConfig(String endpoint,
int filterUniqueKeysRefreshRate,
long lastSeenCacheSize,
ThreadFactory threadFactory,
HashSet<String> flagSetsFilter) {
HashSet<String> flagSetsFilter,
int invalidSets) {
_endpoint = endpoint;
_eventsEndpoint = eventsEndpoint;
_featuresRefreshRate = pollForFeatureChangesEveryNSeconds;
Expand Down Expand Up @@ -196,6 +199,7 @@ private SplitClientConfig(String endpoint,
_lastSeenCacheSize = lastSeenCacheSize;
_threadFactory = threadFactory;
_flagSetsFilter = flagSetsFilter;
_invalidSets = invalidSets;

Properties props = new Properties();
try {
Expand Down Expand Up @@ -381,13 +385,19 @@ public CustomStorageWrapper customStorageWrapper() {
public long getLastSeenCacheSize() {
return _lastSeenCacheSize;
}

public ThreadFactory getThreadFactory() {
return _threadFactory;
}

public HashSet<String> getSetsFilter() {
return _flagSetsFilter;
}

public int getInvalidSets() {
return _invalidSets;
}

public static final class Builder {

private String _endpoint = SDK_ENDPOINT;
Expand Down Expand Up @@ -444,6 +454,7 @@ public static final class Builder {
private final long _lastSeenCacheSize = 500000;
private ThreadFactory _threadFactory;
private HashSet<String> _flagSetsFilter = new HashSet<>();
private int _invalidSets = 0;

public Builder() {
}
Expand Down Expand Up @@ -922,7 +933,9 @@ public Builder customStorageWrapper(CustomStorageWrapper customStorageWrapper) {
* @return this builder
*/
public Builder flagSetsFilter(List<String> flagSetsFilter) {
_flagSetsFilter = cleanup(flagSetsFilter);
FSValidatorResult fsValidatorResult = cleanup(flagSetsFilter);
_flagSetsFilter = fsValidatorResult.getFlagSets();
_invalidSets = fsValidatorResult.getInvalidSets();
return this;
}

Expand Down Expand Up @@ -1074,7 +1087,8 @@ public SplitClientConfig build() {
_filterUniqueKeysRefreshRate,
_lastSeenCacheSize,
_threadFactory,
_flagSetsFilter);
_flagSetsFilter,
_invalidSets);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.split.inputValidation;

import java.util.HashSet;

public class FSValidatorResult {
private final HashSet<String> _flagSets;
private final int _invalidSets;

public FSValidatorResult(HashSet<String> flagSets, Integer invalidSets) {
_flagSets = flagSets;
_invalidSets = invalidSets;
}

public HashSet<String> getFlagSets() {
return _flagSets;
}

public int getInvalidSets() {
return _invalidSets;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ private FlagSetsValidator() {
throw new IllegalStateException("Utility class");
}

public static HashSet<String> cleanup(List<String> flagSets) {
public static FSValidatorResult cleanup(List<String> flagSets) {
if (flagSets == null || flagSets.isEmpty()) {
return new HashSet<>();
return new FSValidatorResult(new HashSet<>(), 0);
}
HashSet<String> cleanFlagSets = new HashSet<>();
int invalidSets = 0;
for (String flagSet: flagSets) {
if(flagSet != flagSet.toLowerCase()) {
_log.warn(String.format("Flag Set name %s should be all lowercase - converting string to lowercase", flagSet));
Expand All @@ -31,19 +32,20 @@ public static HashSet<String> cleanup(List<String> flagSets) {
flagSet = flagSet.trim();
}
if (!Pattern.matches(FLAG_SET_REGEX, flagSet)) {
invalidSets ++;
_log.warn(String.format("you passed %s, Flag Set must adhere to the regular expressions %s. This means an Flag Set must be " +
"start with a letter, be in lowercase, alphanumeric and have a max length of 50 characters. %s was discarded.",
flagSet, FLAG_SET_REGEX, flagSet));
continue;
}
cleanFlagSets.add(flagSet);
}
return cleanFlagSets;
return new FSValidatorResult(cleanFlagSets, invalidSets);
}

public static FlagSetsValidResult areValid(List<String> flagSets) {
HashSet<String> cleanFlagSets = cleanup(flagSets);

FSValidatorResult fsValidatorResult = cleanup(flagSets);
HashSet<String> cleanFlagSets = fsValidatorResult.getFlagSets();
return new FlagSetsValidResult(cleanFlagSets != null && cleanFlagSets.size() != 0, cleanFlagSets);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package io.split.storages.pluggable.domain;

import com.google.gson.annotations.SerializedName;
import io.split.telemetry.domain.Rates;
import io.split.telemetry.domain.URLOverrides;

import java.util.List;

Expand All @@ -11,7 +9,9 @@ public class ConfigConsumer {
/* package private */ static final String FIELD_STORAGE = "st";
/* package private */ static final String FIELD_ACTIVE_FACTORIES = "aF";
/* package private */ static final String FIELD_REDUNDANT_FACTORIES = "rF";
/* package private */ static final String FIELD__TAGS = "t";
/* package private */ static final String FIELD_TAGS = "t";
/* package private */ static final String FIELD_FLAG_SETS_TOTAL = "fsT";
/* package private */ static final String FIELD_FLAG_SETS_INVALID = "fsI";

@SerializedName(FIELD_OPERATION_MODE)
private int _operationMode;
Expand All @@ -21,46 +21,66 @@ public class ConfigConsumer {
private long _activeFactories;
@SerializedName(FIELD_REDUNDANT_FACTORIES)
private long _redundantFactories;
@SerializedName(FIELD__TAGS)
@SerializedName(FIELD_TAGS)
private List<String> _tags;
@SerializedName(FIELD_FLAG_SETS_TOTAL)
private int _flagSetsTotal;
@SerializedName(FIELD_FLAG_SETS_INVALID)
private int _flagSetsInvalid;

public int get_operationMode() {
public int getOperationMode() {
return _operationMode;
}

public void set_operationMode(int _operationMode) {
this._operationMode = _operationMode;
public void setOperationMode(int operationMode) {
this._operationMode = operationMode;
}

public String get_storage() {
public String getStorage() {
return _storage;
}

public void set_storage(String _storage) {
this._storage = _storage;
public void setStorage(String storage) {
this._storage = storage;
}

public long get_activeFactories() {
public long getActiveFactories() {
return _activeFactories;
}

public void set_activeFactories(long _activeFactories) {
this._activeFactories = _activeFactories;
public void setActiveFactories(long activeFactories) {
this._activeFactories = activeFactories;
}

public long get_redundantFactories() {
public long getRedundantFactories() {
return _redundantFactories;
}

public void set_redundantFactories(long _redundantFactories) {
this._redundantFactories = _redundantFactories;
public void setRedundantFactories(long redundantFactories) {
this._redundantFactories = redundantFactories;
}

public List<String> get_tags() {
public List<String> getTags() {
return _tags;
}

public void set_tags(List<String> _tags) {
this._tags = _tags;
public void setTags(List<String> tags) {
this._tags = tags;
}
}

public int getFlagSetsTotal() {
return _flagSetsTotal;
}

public void setFlagSetsTotal(int flagSetsTotal) {
this._flagSetsTotal = flagSetsTotal;
}

public int getFlagSetsInvalid() {
return _flagSetsInvalid;
}

public void setFlagSetsInvalid(int flagSetsInvalid) {
this._flagSetsInvalid = flagSetsInvalid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ public void finalSynchronization() {
@VisibleForTesting
ConfigConsumer generateConfig(SplitClientConfig splitClientConfig, Map<String, Long> factoryInstances, List<String> tags) {
ConfigConsumer config = new ConfigConsumer();
config.set_operationMode(splitClientConfig.operationMode()== OperationMode.STANDALONE ? 0 : 1);
config.set_storage(STORAGE);
config.set_activeFactories(factoryInstances.size());
config.set_redundantFactories(getRedundantFactories(factoryInstances));
config.set_tags(tags.size() < 10 ? tags : tags.subList(0, 10));
config.setOperationMode(splitClientConfig.operationMode()== OperationMode.STANDALONE ? 0 : 1);
config.setStorage(STORAGE);
config.setActiveFactories(factoryInstances.size());
config.setRedundantFactories(getRedundantFactories(factoryInstances));
config.setTags(tags.size() < 10 ? tags : tags.subList(0, 10));
int invalidSets = splitClientConfig.getInvalidSets();
config.setFlagSetsTotal(splitClientConfig.getSetsFilter().size() + invalidSets);
config.setFlagSetsInvalid(invalidSets);
return config;
}

Expand Down
Loading

0 comments on commit 8532a5a

Please sign in to comment.