Skip to content

Commit

Permalink
Add missing log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gthea committed Oct 27, 2023
1 parent 248df41 commit 2514059
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,31 @@ public boolean isValid(String value) {
}

@Override
public Set<String> items(List<String> values, FlagSetsFilter flagSetsFilter) {
public Set<String> items(String method, List<String> values, FlagSetsFilter flagSetsFilter) {
Set<String> setsToReturn = new HashSet<>();

if (values == null || values.isEmpty()) {
return setsToReturn;
}

for (String flagSet : values) {
if (flagSet.trim().length() != flagSet.length()) {
Logger.w(method + ": Flag Set name " + flagSet + " has extra whitespace, trimming");
flagSet = flagSet.trim();
}

if (!flagSet.toLowerCase().equals(flagSet)) {
Logger.w(method + ": Flag Set name "+flagSet+" should be all lowercase - converting string to lowercase");
flagSet = flagSet.toLowerCase();
}

if (!isValid(flagSet)) {
Logger.w(method + ": you passed "+ flagSet +", 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. "+ flagSet +" was discarded.");
continue;
}

if (flagSetsFilter != null && !flagSetsFilter.intersect(flagSet)) {
Logger.w(method + ": you passed Flag Set: "+ flagSet +" and is not part of the configured Flag set list, ignoring the request.");
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface SplitFilterValidator {

boolean isValid(String value);

Set<String> items(List<String> values, FlagSetsFilter flagSetsFilter);
Set<String> items(String method, List<String> values, FlagSetsFilter flagSetsFilter);

class ValidationResult {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public Map<String, String> getTreatmentsByFlagSet(@NonNull String flagSet, @Null
mValidationLogger.e(CLIENT_DESTROYED_MESSAGE, validationTag);
return controlTreatmentsForSplits(new ArrayList<>(names), validationTag);
}
names = getNamesFromSet(Collections.singletonList(flagSet));
names = getNamesFromSet("getTreatmentsByFlagSet", Collections.singletonList(flagSet));

long start = System.currentTimeMillis();
try {
Expand All @@ -216,7 +216,7 @@ public Map<String, String> getTreatmentsByFlagSets(@NonNull List<String> flagSet
mValidationLogger.e(CLIENT_DESTROYED_MESSAGE, validationTag);
return controlTreatmentsForSplits(new ArrayList<>(names), validationTag);
}
names = getNamesFromSet(flagSets);
names = getNamesFromSet("getTreatmentsByFlagSets", flagSets);

long start = System.currentTimeMillis();
try {
Expand All @@ -237,7 +237,7 @@ public Map<String, SplitResult> getTreatmentsWithConfigByFlagSet(@NonNull String
String validationTag = ValidationTag.GET_TREATMENTS_WITH_CONFIG_BY_FLAG_SET;
Set<String> names = new HashSet<>();
try {
names = getNamesFromSet(Collections.singletonList(flagSet));
names = getNamesFromSet("getTreatmentsWithConfigByFlagSet", Collections.singletonList(flagSet));
if (isClientDestroyed) {
mValidationLogger.e(CLIENT_DESTROYED_MESSAGE, validationTag);
return controlTreatmentsForSplitsWithConfig(new ArrayList<>(names), validationTag);
Expand Down Expand Up @@ -266,7 +266,7 @@ public Map<String, SplitResult> getTreatmentsWithConfigByFlagSets(@NonNull List<
mValidationLogger.e(CLIENT_DESTROYED_MESSAGE, validationTag);
return controlTreatmentsForSplitsWithConfig(new ArrayList<>(names), validationTag);
}
names = getNamesFromSet(flagSets);
names = getNamesFromSet("getTreatmentsWithConfigByFlagSets", flagSets);

long start = System.currentTimeMillis();
try {
Expand Down Expand Up @@ -403,9 +403,9 @@ private void recordLatency(Method treatment, long startTime) {
}

@NonNull
private Set<String> getNamesFromSet(@NonNull List<String> flagSets) {
private Set<String> getNamesFromSet(@NonNull String method, @NonNull List<String> flagSets) {

Set<String> setsToEvaluate = mFlagSetsValidator.items(flagSets, mFlagSetsFilter);
Set<String> setsToEvaluate = mFlagSetsValidator.items(method, flagSets, mFlagSetsFilter);

if (setsToEvaluate.isEmpty()) {
return new HashSet<>();
Expand Down

0 comments on commit 2514059

Please sign in to comment.