Skip to content

Commit

Permalink
feat(server): allow A/B test with a restricted set of rules
Browse files Browse the repository at this point in the history
  • Loading branch information
fabrichter committed Oct 25, 2024
1 parent 5f601e8 commit 22e3744
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,22 @@ protected abstract DetectedLanguage getLanguage(String text, Map<String, String>
private long pingsCleanDateMillis = System.currentTimeMillis();
PipelinePool pipelinePool; // mocked in test -> package-private / not final

private final static List<String> onlyUsers;
private final static List<String> onlyRules;

static {
String onlyUsersEnv = System.getenv("LT_TEST_ONLY_USERS");
if (onlyUsersEnv == null) {
onlyUsersEnv = "";
}
String onlyRulesEnv = System.getenv("LT_TEST_ONLY_RULES");
if (onlyRulesEnv == null) {
onlyRulesEnv = "";
}
onlyUsers = Arrays.asList(onlyUsersEnv.split(","));
onlyRules = Arrays.asList(onlyRulesEnv.split(","));
}

TextChecker(HTTPServerConfig config, boolean internalServer, Queue<Runnable> workQueue, RequestCounter reqCounter) {
this.config = config;
this.workQueue = workQueue;
Expand Down Expand Up @@ -464,6 +480,12 @@ public RuleMatch[] match(AnalyzedSentence sentence) throws IOException {
}
List<String> enabledRules = getEnabledRuleIds(params);

if (onlyUsers.contains(params.getOrDefault("username", "")) ||
(abTest != null && abTest.contains("only"))) {
useEnabledOnly = true;
enabledRules = onlyRules;
}

List<String> disabledRules = getDisabledRuleIds(params);
List<CategoryId> enabledCategories = getCategoryIds("enabledCategories", params);
List<CategoryId> disabledCategories = getCategoryIds("disabledCategories", params);
Expand Down

0 comments on commit 22e3744

Please sign in to comment.