@@ -76,87 +76,90 @@ private String bucketToEntity(int bucketValue, List<TrafficAllocation> trafficAl
7676 }
7777
7878 private Experiment bucketToExperiment (@ Nonnull Group group ,
79- @ Nonnull String userId ) {
79+ @ Nonnull String bucketingId ) {
8080 // "salt" the bucket id using the group id
81- String bucketId = userId + group .getId ();
81+ String bucketKey = bucketingId + group .getId ();
8282
8383 List <TrafficAllocation > trafficAllocations = group .getTrafficAllocation ();
8484
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 );
8686 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 );
8888
8989 String bucketedExperimentId = bucketToEntity (bucketValue , trafficAllocations );
9090 if (bucketedExperimentId != null ) {
9191 return projectConfig .getExperimentIdMapping ().get (bucketedExperimentId );
9292 }
9393
9494 // user was not bucketed to an experiment in the group
95- logger .info ("User \" {}\" is not in any experiment of group {}." , userId , group .getId ());
9695 return null ;
9796 }
9897
9998 private Variation bucketToVariation (@ Nonnull Experiment experiment ,
100- @ Nonnull String userId ) {
99+ @ Nonnull String bucketingId ) {
101100 // "salt" the bucket id using the experiment id
102101 String experimentId = experiment .getId ();
103102 String experimentKey = experiment .getKey ();
104- String combinedBucketId = userId + experimentId ;
103+ String combinedBucketId = bucketingId + experimentId ;
105104
106105 List <TrafficAllocation > trafficAllocations = experiment .getTrafficAllocation ();
107106
108107 int hashCode = MurmurHash3 .murmurhash3_x86_32 (combinedBucketId , 0 , combinedBucketId .length (), MURMUR_HASH_SEED );
109108 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 );
111110
112111 String bucketedVariationId = bucketToEntity (bucketValue , trafficAllocations );
113112 if (bucketedVariationId != null ) {
114113 Variation bucketedVariation = experiment .getVariationIdToVariationMap ().get (bucketedVariationId );
115114 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 );
118117
119118 return bucketedVariation ;
120119 }
121120
122121 // 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 );
124123 return null ;
125124 }
126125
127126 /**
128127 * Assign a {@link Variation} of an {@link Experiment} to a user based on hashed value from murmurhash3.
129128 * @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.
131130 * @return Variation the user is bucketed into or null.
132131 */
133132 public @ Nullable Variation bucket (@ Nonnull Experiment experiment ,
134- @ Nonnull String userId ) {
133+ @ Nonnull String bucketingId ) {
135134 // ---------- Bucket User ----------
136135 String groupId = experiment .getGroupId ();
137136 // check whether the experiment belongs to a group
138137 if (!groupId .isEmpty ()) {
139138 Group experimentGroup = projectConfig .getGroupIdMapping ().get (groupId );
140139 // bucket to an experiment only if group entities are to be mutually exclusive
141140 if (experimentGroup .getPolicy ().equals (Group .RANDOM_POLICY )) {
142- Experiment bucketedExperiment = bucketToExperiment (experimentGroup , userId );
141+ Experiment bucketedExperiment = bucketToExperiment (experimentGroup , bucketingId );
143142 if (bucketedExperiment == null ) {
143+ logger .info ("User with bucketingId \" {}\" is not in any experiment of group {}." , bucketingId , experimentGroup .getId ());
144144 return null ;
145+ }
146+ else {
147+
145148 }
146149 // if the experiment a user is bucketed in within a group isn't the same as the experiment provided,
147150 // don't perform further bucketing within the experiment
148151 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 (),
150153 experimentGroup .getId ());
151154 return null ;
152155 }
153156
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 (),
155158 experimentGroup .getId ());
156159 }
157160 }
158161
159- return bucketToVariation (experiment , userId );
162+ return bucketToVariation (experiment , bucketingId );
160163 }
161164
162165
0 commit comments