Add DynamicPreRegistrationExperimentEnrollmentConfiguration

This commit is contained in:
Chris Eager 2021-03-09 17:53:49 -06:00 committed by Chris Eager
parent 152c927929
commit 25f603efc9
3 changed files with 133 additions and 0 deletions

View File

@ -14,6 +14,10 @@ public class DynamicConfiguration {
@Valid
private Map<String, DynamicExperimentEnrollmentConfiguration> experiments = Collections.emptyMap();
@JsonProperty
@Valid
private Map<String, DynamicPreRegistrationExperimentEnrollmentConfiguration> preRegistrationExperiments = Collections.emptyMap();
@JsonProperty
@Valid
private DynamicRateLimitsConfiguration limits = new DynamicRateLimitsConfiguration();
@ -38,6 +42,11 @@ public class DynamicConfiguration {
return Optional.ofNullable(experiments.get(experimentName));
}
public Optional<DynamicPreRegistrationExperimentEnrollmentConfiguration> getPreRegistrationEnrollmentConfiguration(
final String experimentName) {
return Optional.ofNullable(preRegistrationExperiments.get(experimentName));
}
public DynamicRateLimitsConfiguration getLimits() {
return limits;
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2021 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.whispersystems.textsecuregcm.configuration.dynamic;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Collections;
import java.util.Set;
import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
public class DynamicPreRegistrationExperimentEnrollmentConfiguration {
@JsonProperty
@Valid
private Set<String> enrolledE164s = Collections.emptySet();
@JsonProperty
@Valid
private Set<String> excludedCountryCodes = Collections.emptySet();
@JsonProperty
@Valid
private Set<String> includedCountryCodes = Collections.emptySet();
@JsonProperty
@Valid
@Min(0)
@Max(100)
private int enrollmentPercentage = 0;
public Set<String> getEnrolledE164s() {
return enrolledE164s;
}
public Set<String> getExcludedCountryCodes() {
return excludedCountryCodes;
}
public Set<String> getIncludedCountryCodes() {
return includedCountryCodes;
}
public int getEnrollmentPercentage() {
return enrollmentPercentage;
}
}

View File

@ -15,6 +15,7 @@ import com.vdurmont.semver4j.Semver;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import org.junit.jupiter.api.Test;
@ -71,6 +72,79 @@ class DynamicConfigurationTest {
}
}
@Test
void testParsePreRegistrationExperiments() throws JsonProcessingException {
{
final String emptyConfigYaml = "test: true";
final DynamicConfiguration emptyConfig = DynamicConfigurationManager.OBJECT_MAPPER
.readValue(emptyConfigYaml, DynamicConfiguration.class);
assertFalse(emptyConfig.getPreRegistrationEnrollmentConfiguration("test").isPresent());
}
{
final String experimentConfigYaml =
"preRegistrationExperiments:\n" +
" percentageOnly:\n" +
" enrollmentPercentage: 17\n" +
" e164sCountryCodesAndPercentage:\n" +
" enrolledE164s:\n" +
" - +120255551212\n" +
" - +3655323174\n" +
" enrollmentPercentage: 46\n" +
" excludedCountryCodes:\n" +
" - 47\n" +
" includedCountryCodes:\n" +
" - 56\n" +
" e164sAndExcludedCodes:\n" +
" enrolledE164s:\n" +
" - +120255551212\n" +
" excludedCountryCodes:\n" +
" - 47";
final DynamicConfiguration config = DynamicConfigurationManager.OBJECT_MAPPER
.readValue(experimentConfigYaml, DynamicConfiguration.class);
assertFalse(config.getPreRegistrationEnrollmentConfiguration("unconfigured").isPresent());
{
final Optional<DynamicPreRegistrationExperimentEnrollmentConfiguration> percentageOnly = config
.getPreRegistrationEnrollmentConfiguration("percentageOnly");
assertTrue(percentageOnly.isPresent());
assertEquals(17,
percentageOnly.get().getEnrollmentPercentage());
assertEquals(Collections.emptySet(),
percentageOnly.get().getEnrolledE164s());
}
{
final Optional<DynamicPreRegistrationExperimentEnrollmentConfiguration> e164sCountryCodesAndPercentage = config
.getPreRegistrationEnrollmentConfiguration("e164sCountryCodesAndPercentage");
assertTrue(e164sCountryCodesAndPercentage.isPresent());
assertEquals(46,
e164sCountryCodesAndPercentage.get().getEnrollmentPercentage());
assertEquals(Set.of("+120255551212", "+3655323174"),
e164sCountryCodesAndPercentage.get().getEnrolledE164s());
assertEquals(Set.of("47"),
e164sCountryCodesAndPercentage.get().getExcludedCountryCodes());
assertEquals(Set.of("56"),
e164sCountryCodesAndPercentage.get().getIncludedCountryCodes());
}
{
final Optional<DynamicPreRegistrationExperimentEnrollmentConfiguration> e164sAndExcludedCodes = config
.getPreRegistrationEnrollmentConfiguration("e164sAndExcludedCodes");
assertTrue(e164sAndExcludedCodes.isPresent());
assertEquals(0, e164sAndExcludedCodes.get().getEnrollmentPercentage());
assertEquals(Set.of("+120255551212"),
e164sAndExcludedCodes.get().getEnrolledE164s());
assertEquals(Set.of("47"),
e164sAndExcludedCodes.get().getExcludedCountryCodes());
}
}
}
@Test
void testParseRemoteDeprecationConfig() throws JsonProcessingException {
{