Skip to content

Commit e19dabd

Browse files
author
Mike Davis
authored
(feat): Implement default ProjectConfigManager. (#287)
* Extract ProjectConfig interface and create DatafileProjectConfig. * Create ProjectConfigManager and refactor for dynamic ProjectConfig updates. * Add PollingProjectConfigManager implementation. * Add Apache HttpClient implementation of ProjectConfigManager. * Move forced variations mapping into DecisionService. * Add ability to block execution until ProjectConfig resolves.
1 parent 0edbf4f commit e19dabd

File tree

47 files changed

+3821
-1744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3821
-1744
lines changed

core-api/src/jmh/java/com/optimizely/ab/config/parser/JacksonConfigParserBenchmark.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2018, Optimizely and contributors
3+
* Copyright 2018-2019 Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -17,7 +17,7 @@
1717
package com.optimizely.ab.config.parser;
1818

1919
import com.optimizely.ab.config.ProjectConfig;
20-
import com.optimizely.ab.config.ProjectConfigTestUtils;
20+
import com.optimizely.ab.config.DatafileProjectConfigTestUtils;
2121
import org.openjdk.jmh.annotations.*;
2222

2323
import java.io.IOException;
@@ -38,9 +38,9 @@ public class JacksonConfigParserBenchmark {
3838
@Setup
3939
public void setUp() throws IOException {
4040
parser = new JacksonConfigParser();
41-
jsonV2 = ProjectConfigTestUtils.validConfigJsonV2();
42-
jsonV3 = ProjectConfigTestUtils.validConfigJsonV3();
43-
jsonV4 = ProjectConfigTestUtils.validConfigJsonV4();
41+
jsonV2 = DatafileProjectConfigTestUtils.validConfigJsonV2();
42+
jsonV3 = DatafileProjectConfigTestUtils.validConfigJsonV3();
43+
jsonV4 = DatafileProjectConfigTestUtils.validConfigJsonV4();
4444
}
4545

4646
@Benchmark

core-api/src/main/java/com/optimizely/ab/Optimizely.java

Lines changed: 179 additions & 146 deletions
Large diffs are not rendered by default.

core-api/src/main/java/com/optimizely/ab/UnknownEventTypeException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016-2017, Optimizely and contributors
3+
* Copyright 2016-2017, 2019 Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616
*/
1717
package com.optimizely.ab;
1818

19-
import com.optimizely.ab.config.EventType;
2019
import com.optimizely.ab.config.ProjectConfig;
20+
import com.optimizely.ab.config.EventType;
2121

2222
/**
2323
* Exception thrown when attempting to use/refer to an {@link EventType} that isn't present in the current

core-api/src/main/java/com/optimizely/ab/UnknownExperimentException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
*
3-
* Copyright 2016-2017, Optimizely and contributors
3+
* Copyright 2016-2017, 2019 Optimizely and contributors
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -16,8 +16,8 @@
1616
*/
1717
package com.optimizely.ab;
1818

19-
import com.optimizely.ab.config.Experiment;
2019
import com.optimizely.ab.config.ProjectConfig;
20+
import com.optimizely.ab.config.Experiment;
2121

2222
/**
2323
* Exception thrown when attempting to use/refer to an {@link Experiment} that isn't present in the current

core-api/src/main/java/com/optimizely/ab/bucketing/Bucketer.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@
3636
* identifier.
3737
* <p>
3838
* The user identifier <i>must</i> be provided in the first data argument passed to
39-
* {@link #bucket(Experiment, String)} and <i>must</i> be non-null and non-empty.
39+
* {@link #bucket(Experiment, String, ProjectConfig)} and <i>must</i> be non-null and non-empty.
4040
*
4141
* @see <a href="https://en.wikipedia.org/wiki/MurmurHash">MurmurHash</a>
4242
*/
4343
@Immutable
4444
public class Bucketer {
4545

46-
private final ProjectConfig projectConfig;
47-
4846
private static final Logger logger = LoggerFactory.getLogger(Bucketer.class);
4947

5048
private static final int MURMUR_HASH_SEED = 1;
@@ -55,10 +53,6 @@ public class Bucketer {
5553
@VisibleForTesting
5654
static final int MAX_TRAFFIC_VALUE = 10000;
5755

58-
public Bucketer(ProjectConfig projectConfig) {
59-
this.projectConfig = projectConfig;
60-
}
61-
6256
private String bucketToEntity(int bucketValue, List<TrafficAllocation> trafficAllocations) {
6357
int currentEndOfRange;
6458
for (TrafficAllocation currAllocation : trafficAllocations) {
@@ -76,7 +70,8 @@ private String bucketToEntity(int bucketValue, List<TrafficAllocation> trafficAl
7670
}
7771

7872
private Experiment bucketToExperiment(@Nonnull Group group,
79-
@Nonnull String bucketingId) {
73+
@Nonnull String bucketingId,
74+
@Nonnull ProjectConfig projectConfig) {
8075
// "salt" the bucket id using the group id
8176
String bucketKey = bucketingId + group.getId();
8277

@@ -132,15 +127,16 @@ private Variation bucketToVariation(@Nonnull Experiment experiment,
132127
*/
133128
@Nullable
134129
public Variation bucket(@Nonnull Experiment experiment,
135-
@Nonnull String bucketingId) {
130+
@Nonnull String bucketingId,
131+
@Nonnull ProjectConfig projectConfig) {
136132
// ---------- Bucket User ----------
137133
String groupId = experiment.getGroupId();
138134
// check whether the experiment belongs to a group
139135
if (!groupId.isEmpty()) {
140136
Group experimentGroup = projectConfig.getGroupIdMapping().get(groupId);
141137
// bucket to an experiment only if group entities are to be mutually exclusive
142138
if (experimentGroup.getPolicy().equals(Group.RANDOM_POLICY)) {
143-
Experiment bucketedExperiment = bucketToExperiment(experimentGroup, bucketingId);
139+
Experiment bucketedExperiment = bucketToExperiment(experimentGroup, bucketingId, projectConfig);
144140
if (bucketedExperiment == null) {
145141
logger.info("User with bucketingId \"{}\" is not in any experiment of group {}.", bucketingId, experimentGroup.getId());
146142
return null;

0 commit comments

Comments
 (0)