@@ -20,7 +20,7 @@ var enums = require('../../utils/enums');
20
20
var fns = require ( '../../utils/fns' ) ;
21
21
var projectConfig = require ( '../project_config' ) ;
22
22
23
- var sprintf = require ( 'sprintf-js' ) . sprintf ;
23
+ var sprintf = require ( '../../utils/ sprintf' ) ;
24
24
25
25
var MODULE_NAME = 'DECISION_SERVICE' ;
26
26
var ERROR_MESSAGES = enums . ERROR_MESSAGES ;
@@ -83,7 +83,7 @@ DecisionService.prototype.getVariation = function(experimentKey, userId, attribu
83
83
var experimentBucketMap = this . __resolveExperimentBucketMap ( userId , attributes ) ;
84
84
variation = this . __getStoredVariation ( experiment , userId , experimentBucketMap ) ;
85
85
if ( ! ! variation ) {
86
- this . logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . RETURNING_STORED_VARIATION , MODULE_NAME , variation . key , experimentKey , userId ) ) ;
86
+ this . logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . RETURNING_STORED_VARIATION , MODULE_NAME , { variationKey : variation . key , experimentKey, userId} ) ) ;
87
87
return variation . key ;
88
88
}
89
89
@@ -126,7 +126,7 @@ DecisionService.prototype.__resolveExperimentBucketMap = function(userId, attrib
126
126
*/
127
127
DecisionService . prototype . __checkIfExperimentIsActive = function ( experimentKey , userId ) {
128
128
if ( ! projectConfig . isActive ( this . configObj , experimentKey ) ) {
129
- var experimentNotRunningLogMessage = sprintf ( LOG_MESSAGES . EXPERIMENT_NOT_RUNNING , MODULE_NAME , experimentKey ) ;
129
+ var experimentNotRunningLogMessage = sprintf ( LOG_MESSAGES . EXPERIMENT_NOT_RUNNING , MODULE_NAME , { experimentKey} ) ;
130
130
this . logger . log ( LOG_LEVEL . INFO , experimentNotRunningLogMessage ) ;
131
131
return false ;
132
132
}
@@ -144,11 +144,11 @@ DecisionService.prototype.__getWhitelistedVariation = function(experiment, userI
144
144
if ( ! fns . isEmpty ( experiment . forcedVariations ) && experiment . forcedVariations . hasOwnProperty ( userId ) ) {
145
145
var forcedVariationKey = experiment . forcedVariations [ userId ] ;
146
146
if ( experiment . variationKeyMap . hasOwnProperty ( forcedVariationKey ) ) {
147
- var forcedBucketingSucceededMessageLog = sprintf ( LOG_MESSAGES . USER_FORCED_IN_VARIATION , MODULE_NAME , userId , forcedVariationKey ) ;
147
+ var forcedBucketingSucceededMessageLog = sprintf ( LOG_MESSAGES . USER_FORCED_IN_VARIATION , MODULE_NAME , { userId, forcedVariationKey} ) ;
148
148
this . logger . log ( LOG_LEVEL . INFO , forcedBucketingSucceededMessageLog ) ;
149
149
return experiment . variationKeyMap [ forcedVariationKey ] ;
150
150
} else {
151
- var forcedBucketingFailedMessageLog = sprintf ( LOG_MESSAGES . FORCED_BUCKETING_FAILED , MODULE_NAME , forcedVariationKey , userId ) ;
151
+ var forcedBucketingFailedMessageLog = sprintf ( LOG_MESSAGES . FORCED_BUCKETING_FAILED , MODULE_NAME , { forcedVariationKey, userId} ) ;
152
152
this . logger . log ( LOG_LEVEL . ERROR , forcedBucketingFailedMessageLog ) ;
153
153
return null ;
154
154
}
@@ -168,7 +168,7 @@ DecisionService.prototype.__checkIfUserIsInAudience = function(experimentKey, us
168
168
var experimentAudienceConditions = projectConfig . getExperimentAudienceConditions ( this . configObj , experimentKey ) ;
169
169
var audiencesById = projectConfig . getAudiencesById ( this . configObj ) ;
170
170
if ( ! audienceEvaluator . evaluate ( experimentAudienceConditions , audiencesById , attributes ) ) {
171
- var userDoesNotMeetConditionsLogMessage = sprintf ( LOG_MESSAGES . USER_NOT_IN_EXPERIMENT , MODULE_NAME , userId , experimentKey ) ;
171
+ var userDoesNotMeetConditionsLogMessage = sprintf ( LOG_MESSAGES . USER_NOT_IN_EXPERIMENT , MODULE_NAME , { userId, experimentKey} ) ;
172
172
this . logger . log ( LOG_LEVEL . INFO , userDoesNotMeetConditionsLogMessage ) ;
173
173
return false ;
174
174
}
@@ -211,7 +211,7 @@ DecisionService.prototype.__getStoredVariation = function(experiment, userId, ex
211
211
if ( this . configObj . variationIdMap . hasOwnProperty ( variationId ) ) {
212
212
return this . configObj . variationIdMap [ decision . variation_id ] ;
213
213
} else {
214
- this . logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . SAVED_VARIATION_NOT_FOUND , MODULE_NAME , userId , variationId , experiment . key ) ) ;
214
+ this . logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . SAVED_VARIATION_NOT_FOUND , MODULE_NAME , { userId, variationId, experimentKey : experiment . key } ) ) ;
215
215
}
216
216
}
217
217
@@ -236,7 +236,7 @@ DecisionService.prototype.__getUserProfile = function(userId) {
236
236
try {
237
237
return this . userProfileService . lookup ( userId ) ;
238
238
} catch ( ex ) {
239
- this . logger . log ( LOG_LEVEL . ERROR , sprintf ( ERROR_MESSAGES . USER_PROFILE_LOOKUP_ERROR , MODULE_NAME , userId , ex . message ) ) ;
239
+ this . logger . log ( LOG_LEVEL . ERROR , sprintf ( ERROR_MESSAGES . USER_PROFILE_LOOKUP_ERROR , MODULE_NAME , { userId, error : ex . message } ) ) ;
240
240
}
241
241
} ;
242
242
@@ -263,9 +263,9 @@ DecisionService.prototype.__saveUserProfile = function(experiment, variation, us
263
263
experiment_bucket_map : newBucketMap ,
264
264
} ) ;
265
265
266
- this . logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . SAVED_VARIATION , MODULE_NAME , variation . key , experiment . key , userId ) ) ;
266
+ this . logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . SAVED_VARIATION , MODULE_NAME , { variationKey : variation . key , experimentKey : experiment . key , userId} ) ) ;
267
267
} catch ( ex ) {
268
- this . logger . log ( LOG_LEVEL . ERROR , sprintf ( ERROR_MESSAGES . USER_PROFILE_SAVE_ERROR , MODULE_NAME , userId , ex . message ) ) ;
268
+ this . logger . log ( LOG_LEVEL . ERROR , sprintf ( ERROR_MESSAGES . USER_PROFILE_SAVE_ERROR , MODULE_NAME , { userId, error : ex . message } ) ) ;
269
269
}
270
270
} ;
271
271
@@ -286,19 +286,19 @@ DecisionService.prototype.__saveUserProfile = function(experiment, variation, us
286
286
DecisionService . prototype . getVariationForFeature = function ( feature , userId , attributes ) {
287
287
var experimentDecision = this . _getVariationForFeatureExperiment ( feature , userId , attributes ) ;
288
288
if ( experimentDecision . variation !== null ) {
289
- this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_IN_FEATURE_EXPERIMENT , MODULE_NAME , userId , experimentDecision . variation . key , experimentDecision . experiment . key , feature . key ) ) ;
289
+ this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_IN_FEATURE_EXPERIMENT , MODULE_NAME , { userId, variationKey : experimentDecision . variation . key , experimentKey : experimentDecision . experiment . key , featureKey : feature . key } ) ) ;
290
290
return experimentDecision ;
291
291
}
292
292
293
- this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_NOT_IN_FEATURE_EXPERIMENT , MODULE_NAME , userId , feature . key ) ) ;
293
+ this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_NOT_IN_FEATURE_EXPERIMENT , MODULE_NAME , { userId, featureKey : feature . key } ) ) ;
294
294
295
295
var rolloutDecision = this . _getVariationForRollout ( feature , userId , attributes ) ;
296
296
if ( rolloutDecision . variation !== null ) {
297
- this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_IN_ROLLOUT , MODULE_NAME , userId , feature . key ) ) ;
297
+ this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_IN_ROLLOUT , MODULE_NAME , { userId, featureKey : feature . key } ) ) ;
298
298
return rolloutDecision ;
299
299
}
300
300
301
- this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_NOT_IN_ROLLOUT , MODULE_NAME , userId , feature . key ) ) ;
301
+ this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_NOT_IN_ROLLOUT , MODULE_NAME , { userId, featureKey : feature . key } ) ) ;
302
302
303
303
return {
304
304
experiment : null ,
@@ -327,7 +327,7 @@ DecisionService.prototype._getVariationForFeatureExperiment = function(feature,
327
327
variationKey = this . getVariation ( experiment . key , userId , attributes ) ;
328
328
}
329
329
} else {
330
- this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . FEATURE_HAS_NO_EXPERIMENTS , MODULE_NAME , feature . key ) ) ;
330
+ this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . FEATURE_HAS_NO_EXPERIMENTS , MODULE_NAME , { featureKey : feature . key } ) ) ;
331
331
}
332
332
333
333
var variation = null ;
@@ -344,20 +344,20 @@ DecisionService.prototype._getVariationForFeatureExperiment = function(feature,
344
344
DecisionService . prototype . _getExperimentInGroup = function ( group , userId ) {
345
345
var experimentId = bucketer . bucketUserIntoExperiment ( group , userId , userId , this . logger ) ;
346
346
if ( experimentId !== null ) {
347
- this . logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP , MODULE_NAME , userId , experimentId , group . id ) ) ;
347
+ this . logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . USER_BUCKETED_INTO_EXPERIMENT_IN_GROUP , MODULE_NAME , { userId, experimentId, groupId : group . id } ) ) ;
348
348
var experiment = projectConfig . getExperimentFromId ( this . configObj , experimentId , this . logger ) ;
349
349
if ( experiment ) {
350
350
return experiment ;
351
351
}
352
352
}
353
353
354
- this . logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . USER_NOT_BUCKETED_INTO_ANY_EXPERIMENT_IN_GROUP , MODULE_NAME , userId , group . id ) ) ;
354
+ this . logger . log ( LOG_LEVEL . INFO , sprintf ( LOG_MESSAGES . USER_NOT_BUCKETED_INTO_ANY_EXPERIMENT_IN_GROUP , MODULE_NAME , { userId, groupId : group . id } ) ) ;
355
355
return null ;
356
356
} ;
357
357
358
358
DecisionService . prototype . _getVariationForRollout = function ( feature , userId , attributes ) {
359
359
if ( ! feature . rolloutId ) {
360
- this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . NO_ROLLOUT_EXISTS , MODULE_NAME , feature . key ) ) ;
360
+ this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . NO_ROLLOUT_EXISTS , MODULE_NAME , { featureKey : feature . key } ) ) ;
361
361
return {
362
362
experiment : null ,
363
363
variation : null ,
@@ -367,7 +367,7 @@ DecisionService.prototype._getVariationForRollout = function(feature, userId, at
367
367
368
368
var rollout = this . configObj . rolloutIdMap [ feature . rolloutId ] ;
369
369
if ( ! rollout ) {
370
- this . logger . log ( LOG_LEVEL . ERROR , sprintf ( ERROR_MESSAGES . INVALID_ROLLOUT_ID , MODULE_NAME , feature . rolloutId , feature . key ) ) ;
370
+ this . logger . log ( LOG_LEVEL . ERROR , sprintf ( ERROR_MESSAGES . INVALID_ROLLOUT_ID , MODULE_NAME , { rolloutId : feature . rolloutId , featureKey : feature . key } ) ) ;
371
371
return {
372
372
experiment : null ,
373
373
variation : null ,
@@ -376,7 +376,7 @@ DecisionService.prototype._getVariationForRollout = function(feature, userId, at
376
376
}
377
377
378
378
if ( rollout . experiments . length === 0 ) {
379
- this . logger . log ( LOG_LEVEL . ERROR , sprintf ( LOG_MESSAGES . ROLLOUT_HAS_NO_EXPERIMENTS , MODULE_NAME , feature . rolloutId ) ) ;
379
+ this . logger . log ( LOG_LEVEL . ERROR , sprintf ( LOG_MESSAGES . ROLLOUT_HAS_NO_EXPERIMENTS , MODULE_NAME , { rolloutId : feature . rolloutId } ) ) ;
380
380
return {
381
381
experiment : null ,
382
382
variation : null ,
@@ -396,23 +396,23 @@ DecisionService.prototype._getVariationForRollout = function(feature, userId, at
396
396
experiment = this . configObj . experimentKeyMap [ rollout . experiments [ index ] . key ] ;
397
397
398
398
if ( ! this . __checkIfUserIsInAudience ( experiment . key , userId , attributes ) ) {
399
- this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE , MODULE_NAME , userId , index + 1 ) ) ;
399
+ this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_DOESNT_MEET_CONDITIONS_FOR_TARGETING_RULE , MODULE_NAME , { userId, index : index + 1 } ) ) ;
400
400
continue ;
401
401
}
402
402
403
- this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_MEETS_CONDITIONS_FOR_TARGETING_RULE , MODULE_NAME , userId , index + 1 ) ) ;
403
+ this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_MEETS_CONDITIONS_FOR_TARGETING_RULE , MODULE_NAME , { userId, index : index + 1 } ) ) ;
404
404
bucketerParams = this . __buildBucketerParams ( experiment . key , userId , userId ) ;
405
405
variationId = bucketer . bucket ( bucketerParams ) ;
406
406
variation = this . configObj . variationIdMap [ variationId ] ;
407
407
if ( variation ) {
408
- this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_BUCKETED_INTO_TARGETING_RULE , MODULE_NAME , userId , index + 1 ) ) ;
408
+ this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_BUCKETED_INTO_TARGETING_RULE , MODULE_NAME , { userId, index : index + 1 } ) ) ;
409
409
return {
410
410
experiment : experiment ,
411
411
variation : variation ,
412
412
decisionSource : DECISION_SOURCES . ROLLOUT ,
413
413
} ;
414
414
} else {
415
- this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_NOT_BUCKETED_INTO_TARGETING_RULE , MODULE_NAME , userId , index + 1 ) ) ;
415
+ this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_NOT_BUCKETED_INTO_TARGETING_RULE , MODULE_NAME , { userId, index : index + 1 } ) ) ;
416
416
break ;
417
417
}
418
418
}
@@ -423,14 +423,14 @@ DecisionService.prototype._getVariationForRollout = function(feature, userId, at
423
423
variationId = bucketer . bucket ( bucketerParams ) ;
424
424
variation = this . configObj . variationIdMap [ variationId ] ;
425
425
if ( variation ) {
426
- this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_BUCKETED_INTO_EVERYONE_TARGETING_RULE , MODULE_NAME , userId ) ) ;
426
+ this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_BUCKETED_INTO_EVERYONE_TARGETING_RULE , MODULE_NAME , { userId} ) ) ;
427
427
return {
428
428
experiment : everyoneElseExperiment ,
429
429
variation : variation ,
430
430
decisionSource : DECISION_SOURCES . ROLLOUT ,
431
431
} ;
432
432
} else {
433
- this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_NOT_BUCKETED_INTO_EVERYONE_TARGETING_RULE , MODULE_NAME , userId ) ) ;
433
+ this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . USER_NOT_BUCKETED_INTO_EVERYONE_TARGETING_RULE , MODULE_NAME , { userId} ) ) ;
434
434
}
435
435
}
436
436
@@ -454,7 +454,7 @@ DecisionService.prototype._getBucketingId = function(userId, attributes) {
454
454
if ( ( attributes != null && typeof attributes === 'object' ) && attributes . hasOwnProperty ( enums . CONTROL_ATTRIBUTES . BUCKETING_ID ) ) {
455
455
if ( typeof attributes [ enums . CONTROL_ATTRIBUTES . BUCKETING_ID ] === 'string' ) {
456
456
bucketingId = attributes [ enums . CONTROL_ATTRIBUTES . BUCKETING_ID ] ;
457
- this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . VALID_BUCKETING_ID , MODULE_NAME , bucketingId ) ) ;
457
+ this . logger . log ( LOG_LEVEL . DEBUG , sprintf ( LOG_MESSAGES . VALID_BUCKETING_ID , MODULE_NAME , { bucketingId} ) ) ;
458
458
} else {
459
459
this . logger . log ( LOG_LEVEL . WARNING , sprintf ( LOG_MESSAGES . BUCKETING_ID_NOT_STRING , MODULE_NAME ) ) ;
460
460
}
0 commit comments