-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move config-reading abstract methods from each decider into a ConfigReader Interface * Add featureGroup support to control what features use the same hashing for proportionOfUsers decider * Move the provided config decider predicates to a single class as static factory methods that depend on a ConfigReader instead of separate abstract classes that must be implemented in a specific config module
- Loading branch information
Showing
24 changed files
with
529 additions
and
351 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
moirai-core/src/main/java/com/nike/moirai/config/ConfigDeciderSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.nike.moirai.config; | ||
|
||
import com.nike.moirai.FeatureCheckInput; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Support functions for creating a {@link java.util.function.Predicate} for {@link ConfigDecisionInput}. | ||
*/ | ||
public class ConfigDeciderSupport { | ||
/** | ||
* Apply a predicate to the userId from a feature check input. | ||
* | ||
* @param featureCheckInput the input to check | ||
* @param userIdCheck the predicate to apply | ||
* @return false if there is no userId in the input, otherwise the result of the predicate applied to the userId | ||
*/ | ||
public static boolean userIdCheck(FeatureCheckInput featureCheckInput, Predicate<String> userIdCheck) { | ||
return featureCheckInput.getUserId().map(userIdCheck::test).orElse(false); | ||
} | ||
|
||
/** | ||
* Apply a predicate to the dimension value from a feature check input. | ||
* | ||
* @param featureCheckInput the input to check | ||
* @param dimensionKey the dimension to check | ||
* @param dimensionCheck the predicate to apply | ||
* @return false if there is no userId in the input, otherwise the result of the predicate applied to the userId | ||
*/ | ||
public static boolean customDimensionCheck(FeatureCheckInput featureCheckInput, String dimensionKey, Predicate<Object> dimensionCheck) { | ||
return featureCheckInput.getDimension(dimensionKey).map(dimensionCheck::test).orElse(false); | ||
} | ||
|
||
private ConfigDeciderSupport() { | ||
// Prevent instantiation | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
moirai-core/src/main/java/com/nike/moirai/config/ConfigReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.nike.moirai.config; | ||
|
||
import java.util.Collection; | ||
import java.util.Optional; | ||
|
||
public interface ConfigReader<C> { | ||
/** | ||
* Provide the collection of users that should have the given feature enabled. Return an empty list if no configuration is provided for the feature. | ||
* | ||
* @param config the config source | ||
* @param featureIdentifier the feature | ||
* @return the collection of userIds that should be enabled for the feature | ||
*/ | ||
Collection<String> enabledUsers(C config, String featureIdentifier); | ||
|
||
/** | ||
* Provide the boolean value on whether the feature should be enabled. | ||
* Returning Optional.empty() is equivalent to false. | ||
* | ||
* @param config the config source | ||
* @param featureIdentifier the feature | ||
* @return true, false, or {@link Optional#empty()} | ||
*/ | ||
Optional<Boolean> featureEnabled(C config, String featureIdentifier); | ||
|
||
/** | ||
* Provide the proportion of users that should be enabled for the given feature. The proportion should be a double from 0.0 to 1.0. | ||
* 0.0 means no users will have the feature enabled, and 1.0 will mean that all users will have the feature enabled. | ||
* Values below zero will be treated the same as 0.0 and values above 1.0 will be treated the same as 1.0. | ||
* Returning Optional.empty() is equivalent to 0.0; both will return false for all users. | ||
* | ||
* @param config the config source | ||
* @param featureIdentifier the feature | ||
* @return some proportion between 0.0 and 1.0, or {@link Optional#empty()} | ||
*/ | ||
Optional<Double> enabledProportion(C config, String featureIdentifier); | ||
|
||
/** | ||
* Provide the featureGroup that the feature should belong to. This will affect the {@link ConfigDeciders#proportionOfUsers(ConfigReader)} so that | ||
* if two features with the same featureGroup have the same enabled proportion, the same users will be included in that proportion. | ||
* Returning Optional.empty() will result in the feature being grouped by itself (the featureIdentifier will be used as the featureGroup). | ||
* | ||
* @param config the config source | ||
* @param featureIdentifier the feature | ||
* @return the identifier of the feature group or {@link Optional#empty()} | ||
*/ | ||
Optional<String> featureGroup(C config, String featureIdentifier); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
moirai-core/src/main/java/com/nike/moirai/config/EnabledUsersConfigDecider.java
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
moirai-core/src/main/java/com/nike/moirai/config/FeatureEnabledConfigDecider.java
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
moirai-core/src/main/java/com/nike/moirai/config/ProportionOfUsersConfigDecider.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.