@@ -76,87 +76,90 @@ private String bucketToEntity(int bucketValue, List<TrafficAllocation> trafficAl
76
76
}
77
77
78
78
private Experiment bucketToExperiment (@ Nonnull Group group ,
79
- @ Nonnull String userId ) {
79
+ @ Nonnull String bucketingId ) {
80
80
// "salt" the bucket id using the group id
81
- String bucketId = userId + group .getId ();
81
+ String bucketKey = bucketingId + group .getId ();
82
82
83
83
List <TrafficAllocation > trafficAllocations = group .getTrafficAllocation ();
84
84
85
- int hashCode = MurmurHash3 .murmurhash3_x86_32 (bucketId , 0 , bucketId .length (), MURMUR_HASH_SEED );
85
+ int hashCode = MurmurHash3 .murmurhash3_x86_32 (bucketKey , 0 , bucketKey .length (), MURMUR_HASH_SEED );
86
86
int bucketValue = generateBucketValue (hashCode );
87
- logger .debug ("Assigned bucket {} to user \" {}\" during experiment bucketing." , bucketValue , userId );
87
+ logger .debug ("Assigned bucket {} to user with bucketingId \" {}\" during experiment bucketing." , bucketValue , bucketingId );
88
88
89
89
String bucketedExperimentId = bucketToEntity (bucketValue , trafficAllocations );
90
90
if (bucketedExperimentId != null ) {
91
91
return projectConfig .getExperimentIdMapping ().get (bucketedExperimentId );
92
92
}
93
93
94
94
// user was not bucketed to an experiment in the group
95
- logger .info ("User \" {}\" is not in any experiment of group {}." , userId , group .getId ());
96
95
return null ;
97
96
}
98
97
99
98
private Variation bucketToVariation (@ Nonnull Experiment experiment ,
100
- @ Nonnull String userId ) {
99
+ @ Nonnull String bucketingId ) {
101
100
// "salt" the bucket id using the experiment id
102
101
String experimentId = experiment .getId ();
103
102
String experimentKey = experiment .getKey ();
104
- String combinedBucketId = userId + experimentId ;
103
+ String combinedBucketId = bucketingId + experimentId ;
105
104
106
105
List <TrafficAllocation > trafficAllocations = experiment .getTrafficAllocation ();
107
106
108
107
int hashCode = MurmurHash3 .murmurhash3_x86_32 (combinedBucketId , 0 , combinedBucketId .length (), MURMUR_HASH_SEED );
109
108
int bucketValue = generateBucketValue (hashCode );
110
- logger .debug ("Assigned bucket {} to user \" {}\" during variation bucketing." , bucketValue , userId );
109
+ logger .debug ("Assigned bucket {} to user with bucketingId \" {}\" when bucketing to a variation ." , bucketValue , bucketingId );
111
110
112
111
String bucketedVariationId = bucketToEntity (bucketValue , trafficAllocations );
113
112
if (bucketedVariationId != null ) {
114
113
Variation bucketedVariation = experiment .getVariationIdToVariationMap ().get (bucketedVariationId );
115
114
String variationKey = bucketedVariation .getKey ();
116
- logger .info ("User \" {}\" is in variation \" {}\" of experiment \" {}\" ." , userId , variationKey ,
117
- experimentKey );
115
+ logger .info ("User with bucketingId \" {}\" is in variation \" {}\" of experiment \" {}\" ." , bucketingId , variationKey ,
116
+ experimentKey );
118
117
119
118
return bucketedVariation ;
120
119
}
121
120
122
121
// user was not bucketed to a variation
123
- logger .info ("User \" {}\" is not in any variation of experiment \" {}\" ." , userId , experimentKey );
122
+ logger .info ("User with bucketingId \" {}\" is not in any variation of experiment \" {}\" ." , bucketingId , experimentKey );
124
123
return null ;
125
124
}
126
125
127
126
/**
128
127
* Assign a {@link Variation} of an {@link Experiment} to a user based on hashed value from murmurhash3.
129
128
* @param experiment The Experiment in which the user is to be bucketed.
130
- * @param userId User Identifier
129
+ * @param bucketingId string A customer-assigned value used to create the key for the murmur hash.
131
130
* @return Variation the user is bucketed into or null.
132
131
*/
133
132
public @ Nullable Variation bucket (@ Nonnull Experiment experiment ,
134
- @ Nonnull String userId ) {
133
+ @ Nonnull String bucketingId ) {
135
134
// ---------- Bucket User ----------
136
135
String groupId = experiment .getGroupId ();
137
136
// check whether the experiment belongs to a group
138
137
if (!groupId .isEmpty ()) {
139
138
Group experimentGroup = projectConfig .getGroupIdMapping ().get (groupId );
140
139
// bucket to an experiment only if group entities are to be mutually exclusive
141
140
if (experimentGroup .getPolicy ().equals (Group .RANDOM_POLICY )) {
142
- Experiment bucketedExperiment = bucketToExperiment (experimentGroup , userId );
141
+ Experiment bucketedExperiment = bucketToExperiment (experimentGroup , bucketingId );
143
142
if (bucketedExperiment == null ) {
143
+ logger .info ("User with bucketingId \" {}\" is not in any experiment of group {}." , bucketingId , experimentGroup .getId ());
144
144
return null ;
145
+ }
146
+ else {
147
+
145
148
}
146
149
// if the experiment a user is bucketed in within a group isn't the same as the experiment provided,
147
150
// don't perform further bucketing within the experiment
148
151
if (!bucketedExperiment .getId ().equals (experiment .getId ())) {
149
- logger .info ("User \" {}\" is not in experiment \" {}\" of group {}." , userId , experiment .getKey (),
152
+ logger .info ("User with bucketingId \" {}\" is not in experiment \" {}\" of group {}." , bucketingId , experiment .getKey (),
150
153
experimentGroup .getId ());
151
154
return null ;
152
155
}
153
156
154
- logger .info ("User \" {}\" is in experiment \" {}\" of group {}." , userId , experiment .getKey (),
157
+ logger .info ("User with bucketingId \" {}\" is in experiment \" {}\" of group {}." , bucketingId , experiment .getKey (),
155
158
experimentGroup .getId ());
156
159
}
157
160
}
158
161
159
- return bucketToVariation (experiment , userId );
162
+ return bucketToVariation (experiment , bucketingId );
160
163
}
161
164
162
165
0 commit comments