Skip to content

Commit 1ffb496

Browse files
mjc1283Matt Carroll
authored andcommitted
fix(bucketer): Don't log invalid variation ID warning when bucketed into a traffic allocation range with empty string entityId (#549)
Summary: Fix an issue introduced in #515. When bucket returns empty string, we shouldn't log a warning about invalid variation ID. Empty string is a valid value for the entityId property of traffic allocation range objects. There is no invalid variation ID in this situation. Test plan: Manually tested with A/B tests and rollouts. Added new unit test. Issues: OASIS-6890
1 parent 0427cdd commit 1ffb496

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/optimizely-sdk/lib/core/bucketer/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ export var bucket = function(bucketerParams) {
114114
var entityId = this._findBucket(bucketValue, bucketerParams.trafficAllocationConfig);
115115

116116
if (!bucketerParams.variationIdMap.hasOwnProperty(entityId)) {
117-
var invalidVariationIdLogMessage = sprintf(LOG_MESSAGES.INVALID_VARIATION_ID, MODULE_NAME);
118-
bucketerParams.logger.log(LOG_LEVEL.WARNING, invalidVariationIdLogMessage);
117+
if (entityId) {
118+
var invalidVariationIdLogMessage = sprintf(LOG_MESSAGES.INVALID_VARIATION_ID, MODULE_NAME);
119+
bucketerParams.logger.log(LOG_LEVEL.WARNING, invalidVariationIdLogMessage);
120+
}
119121
return null;
120122
}
121123

@@ -128,7 +130,7 @@ export var bucket = function(bucketerParams) {
128130
* @param {string} bucketingId Bucketing ID
129131
* @param {string} userId ID of user to be bucketed into experiment
130132
* @param {Object} logger Logger implementation
131-
* @return {string} ID of experiment if user is bucketed into experiment within the group, null otherwise
133+
* @return {string|null} ID of experiment if user is bucketed into experiment within the group, null otherwise
132134
*/
133135
export var bucketUserIntoExperiment = function(group, bucketingId, userId, logger) {
134136
var bucketingKey = sprintf('%s%s', bucketingId, group.id);
@@ -148,7 +150,7 @@ export var bucketUserIntoExperiment = function(group, bucketingId, userId, logge
148150
* @param {Object[]} trafficAllocationConfig
149151
* @param {number} trafficAllocationConfig[].endOfRange
150152
* @param {number} trafficAllocationConfig[].entityId
151-
* @return {string} Entity ID for bucketing if bucket value is within traffic allocation boundaries, null otherwise
153+
* @return {string|null} Entity ID for bucketing if bucket value is within traffic allocation boundaries, null otherwise
152154
*/
153155
export var _findBucket = function(bucketValue, trafficAllocationConfig) {
154156
for (var i = 0; i < trafficAllocationConfig.length; i++) {

packages/optimizely-sdk/lib/core/bucketer/index.tests.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ describe('lib/core/bucketer', function() {
286286
bucketerParamsTest1.userId = 'ppid1';
287287
expect(bucketer.bucket(bucketerParamsTest1)).to.equal(null);
288288
});
289+
290+
it('should not log an invalid variation ID warning', function() {
291+
bucketer.bucket(bucketerParams)
292+
const foundInvalidVariationWarning = createdLogger.log.getCalls().some((call) => {
293+
const message = call.args[1];
294+
return message.includes('Bucketed into an invalid variation ID')
295+
});
296+
expect(foundInvalidVariationWarning).to.equal(false);
297+
});
289298
});
290299

291300
describe('when the traffic allocation has invalid variation ids', function() {

0 commit comments

Comments
 (0)