Skip to content

Commit 326b771

Browse files
committed
comments addressed
1 parent 697e13d commit 326b771

File tree

6 files changed

+26
-25
lines changed

6 files changed

+26
-25
lines changed

lib/optimizely.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,7 @@ def send_impression(config, experiment, variation_key, flag_key, rule_key, enabl
10811081
end
10821082

10831083
experiment_id = experiment['id']
1084+
experiment_key = experiment['key']
10841085

10851086
variation_id = ''
10861087
variation_id = config.get_variation_id_from_key_by_experiment_id(experiment_id, variation_key) if experiment_id != ''
@@ -1097,7 +1098,7 @@ def send_impression(config, experiment, variation_key, flag_key, rule_key, enabl
10971098
@event_processor.process(user_event)
10981099
return unless @notification_center.notification_count(NotificationCenter::NOTIFICATION_TYPES[:ACTIVATE]).positive?
10991100

1100-
@logger.log(Logger::INFO, "Activating user '#{user_id}' in experiment '#{experiment_id}'.")
1101+
@logger.log(Logger::INFO, "Activating user '#{user_id}' in experiment '#{experiment_key}'.")
11011102

11021103
experiment = nil if experiment_id == ''
11031104
variation = nil

lib/optimizely/config/datafile_project_config.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ def get_variation_id_from_key_by_experiment_id(experiment_id, variation_key)
333333
#
334334
# Returns the variation or nil if not found
335335

336-
variation_key_map_by_experiment_id = @variation_key_map_by_experiment_id[experiment_id]
337-
if variation_key_map_by_experiment_id
338-
variation = variation_key_map_by_experiment_id[variation_key]
336+
variation_key_map = @variation_key_map_by_experiment_id[experiment_id]
337+
if variation_key_map
338+
variation = variation_key_map[variation_key]
339339
return variation['id'] if variation
340340

341341
@logger.log Logger::ERROR, "Variation key '#{variation_key}' is not in datafile."
@@ -372,16 +372,16 @@ def get_variation_id_from_key(experiment_key, variation_key)
372372
end
373373

374374
def get_whitelisted_variations(experiment_id)
375-
# Retrieves whitelisted variations for a given experiment Key
375+
# Retrieves whitelisted variations for a given experiment id
376376
#
377-
# experiment_key - String Key representing the experiment
377+
# experiment_id - String id representing the experiment
378378
#
379379
# Returns whitelisted variations for the experiment or nil
380380

381381
experiment = @experiment_id_map[experiment_id]
382382
return experiment['forcedVariations'] if experiment
383383

384-
@logger.log Logger::ERROR, "Experiment key '#{experiment_id}' is not in datafile."
384+
@logger.log Logger::ERROR, "Experiment ID '#{experiment_id}' is not in datafile."
385385
@error_handler.handle_error InvalidExperimentError
386386
end
387387

lib/optimizely/decision_service.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ def get_variation(project_config, experiment_id, user_id, attributes = nil, deci
7171
experiment = project_config.get_experiment_from_id(experiment_id)
7272
return nil, decide_reasons if experiment.nil?
7373

74+
experiment_key = experiment['key']
7475
unless project_config.experiment_running?(experiment)
75-
message = "Experiment '#{experiment_id}' is not running."
76+
message = "Experiment '#{experiment_key}' is not running."
7677
@logger.log(Logger::INFO, message)
7778
decide_reasons.push(message)
7879
return nil, decide_reasons
@@ -96,7 +97,7 @@ def get_variation(project_config, experiment_id, user_id, attributes = nil, deci
9697
saved_variation_id, reasons_received = get_saved_variation_id(project_config, experiment_id, user_profile)
9798
decide_reasons.push(*reasons_received)
9899
if saved_variation_id
99-
message = "Returning previously activated variation ID #{saved_variation_id} of experiment '#{experiment_id}' for user '#{user_id}' from user profile."
100+
message = "Returning previously activated variation ID #{saved_variation_id} of experiment '#{experiment_key}' for user '#{user_id}' from user profile."
100101
@logger.log(Logger::INFO, message)
101102
decide_reasons.push(message)
102103
return saved_variation_id, decide_reasons
@@ -107,7 +108,7 @@ def get_variation(project_config, experiment_id, user_id, attributes = nil, deci
107108
user_meets_audience_conditions, reasons_received = Audience.user_meets_audience_conditions?(project_config, experiment, attributes, @logger)
108109
decide_reasons.push(*reasons_received)
109110
unless user_meets_audience_conditions
110-
message = "User '#{user_id}' does not meet the conditions to be in experiment '#{experiment_id}'."
111+
message = "User '#{user_id}' does not meet the conditions to be in experiment '#{experiment_key}'."
111112
@logger.log(Logger::INFO, message)
112113
decide_reasons.push(message)
113114
return nil, decide_reasons
@@ -191,7 +192,7 @@ def get_variation_for_feature_experiment(project_config, feature_flag, user_id,
191192

192193
next unless variation_id
193194

194-
variation = project_config.variation_id_map_by_experiment_id[experiment_id][variation_id]
195+
variation = project_config.get_variation_from_id_by_experiment_id(experiment_id, variation_id)
195196

196197
return Decision.new(experiment, variation, DECISION_SOURCES['FEATURE_TEST']), decide_reasons
197198
end
@@ -346,7 +347,6 @@ def get_forced_variation(project_config, experiment_key, user_id)
346347
end
347348

348349
experiment_to_variation_map = @forced_variation_map[user_id]
349-
# to be corrected
350350
experiment = project_config.get_experiment_from_key(experiment_key)
351351
experiment_id = experiment['id'] if experiment
352352
# check for nil and empty string experiment ID

spec/config/datafile_project_config_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@
918918
it 'should log a message when there is no experiment key map for the experiment' do
919919
config.get_whitelisted_variations('invalid_key')
920920
expect(spy_logger).to have_received(:log).with(Logger::ERROR,
921-
"Experiment key 'invalid_key' is not in datafile.")
921+
"Experiment ID 'invalid_key' is not in datafile.")
922922
end
923923
end
924924

spec/decision_service_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@
181181
"Starting to evaluate audience '11154' with conditions: [\"and\", [\"or\", [\"or\", {\"name\": \"browser_type\", \"type\": \"custom_attribute\", \"value\": \"firefox\"}]]].",
182182
"Audience '11154' evaluated to FALSE.",
183183
"Audiences for experiment 'test_experiment_with_audience' collectively evaluated to FALSE.",
184-
"User 'test_user' does not meet the conditions to be in experiment '122227'."
184+
"User 'test_user' does not meet the conditions to be in experiment 'test_experiment_with_audience'."
185185
])
186186
expect(spy_logger).to have_received(:log)
187-
.once.with(Logger::INFO, "User 'test_user' does not meet the conditions to be in experiment '122227'.")
187+
.once.with(Logger::INFO, "User 'test_user' does not meet the conditions to be in experiment 'test_experiment_with_audience'.")
188188

189189
# should have checked forced variations
190190
expect(decision_service).to have_received(:get_whitelisted_variation_id).once
@@ -195,9 +195,9 @@
195195
it 'should return nil if the given experiment is not running' do
196196
variation_received, reasons = decision_service.get_variation(config, '100027', 'test_user')
197197
expect(variation_received).to eq(nil)
198-
expect(reasons).to eq(["Experiment '100027' is not running."])
198+
expect(reasons).to eq(["Experiment 'test_experiment_not_started' is not running."])
199199
expect(spy_logger).to have_received(:log)
200-
.once.with(Logger::INFO, "Experiment '100027' is not running.")
200+
.once.with(Logger::INFO, "Experiment 'test_experiment_not_started' is not running.")
201201

202202
# non-running experiments should short circuit whitelisting
203203
expect(decision_service).not_to have_received(:get_whitelisted_variation_id)
@@ -313,10 +313,10 @@
313313
variation_received, reasons = decision_service.get_variation(config, '111127', 'test_user')
314314
expect(variation_received).to eq('111129')
315315
expect(reasons).to eq([
316-
"Returning previously activated variation ID 111129 of experiment '111127' for user 'test_user' from user profile."
316+
"Returning previously activated variation ID 111129 of experiment 'test_experiment' for user 'test_user' from user profile."
317317
])
318318
expect(spy_logger).to have_received(:log).once
319-
.with(Logger::INFO, "Returning previously activated variation ID 111129 of experiment '111127' for user 'test_user' from user profile.")
319+
.with(Logger::INFO, "Returning previously activated variation ID 111129 of experiment 'test_experiment' for user 'test_user' from user profile.")
320320

321321
# saved user profiles should short circuit bucketing
322322
expect(decision_service.bucketer).not_to have_received(:bucket)

spec/project_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ def callback(_args); end
717717

718718
project_instance.activate('test_experiment', 'test_user')
719719

720-
expect(spy_logger).to have_received(:log).once.with(Logger::INFO, "Activating user 'test_user' in experiment '111127'.")
720+
expect(spy_logger).to have_received(:log).once.with(Logger::INFO, "Activating user 'test_user' in experiment 'test_experiment'.")
721721
end
722722

723723
it 'should log when an exception has occurred during dispatching the impression event' do
@@ -1647,7 +1647,7 @@ def callback(_args); end
16471647
allow(project_instance.decision_service).to receive(:get_variation_for_feature).and_return(decision_to_return)
16481648

16491649
expect(project_instance.is_feature_enabled('multi_variate_feature', 'test_user')).to be true
1650-
expect(spy_logger).to have_received(:log).once.with(Logger::INFO, "Activating user 'test_user' in experiment '122230'.")
1650+
expect(spy_logger).to have_received(:log).once.with(Logger::INFO, "Activating user 'test_user' in experiment 'test_experiment_multivariate'.")
16511651
expect(spy_logger).to have_received(:log).once.with(Logger::INFO, "Feature 'multi_variate_feature' is enabled for user 'test_user'.")
16521652
end
16531653

@@ -3906,7 +3906,7 @@ def callback(_args); end
39063906
"Starting to evaluate audience '11154' with conditions: [\"and\", [\"or\", [\"or\", {\"name\": \"browser_type\", \"type\": \"custom_attribute\", \"value\": \"firefox\"}]]].",
39073907
"Audience '11154' evaluated to UNKNOWN.",
39083908
"Audiences for experiment 'test_experiment_multivariate' collectively evaluated to FALSE.",
3909-
"User 'user1' does not meet the conditions to be in experiment '122230'.",
3909+
"User 'user1' does not meet the conditions to be in experiment 'test_experiment_multivariate'.",
39103910
"The user 'user1' is not bucketed into any of the experiments on the feature 'multi_variate_feature'.",
39113911
"Feature flag 'multi_variate_feature' is not used in a rollout."
39123912
],
@@ -3922,7 +3922,7 @@ def callback(_args); end
39223922
"Starting to evaluate audience '11154' with conditions: [\"and\", [\"or\", [\"or\", {\"name\": \"browser_type\", \"type\": \"custom_attribute\", \"value\": \"firefox\"}]]].",
39233923
"Audience '11154' evaluated to UNKNOWN.",
39243924
"Audiences for experiment 'test_experiment_multivariate' collectively evaluated to FALSE.",
3925-
"User 'user1' does not meet the conditions to be in experiment '122230'.",
3925+
"User 'user1' does not meet the conditions to be in experiment 'test_experiment_multivariate'.",
39263926
"The user 'user1' is not bucketed into any of the experiments on the feature 'multi_variate_feature'.",
39273927
"Feature flag 'multi_variate_feature' is not used in a rollout."
39283928
],
@@ -4255,7 +4255,7 @@ def callback(_args); end
42554255
"Starting to evaluate audience '11154' with conditions: [\"and\", [\"or\", [\"or\", {\"name\": \"browser_type\", \"type\": \"custom_attribute\", \"value\": \"firefox\"}]]].",
42564256
"Audience '11154' evaluated to UNKNOWN.",
42574257
"Audiences for experiment 'test_experiment_multivariate' collectively evaluated to FALSE.",
4258-
"User 'user1' does not meet the conditions to be in experiment '122230'.",
4258+
"User 'user1' does not meet the conditions to be in experiment 'test_experiment_multivariate'.",
42594259
"The user 'user1' is not bucketed into any of the experiments on the feature 'multi_variate_feature'.",
42604260
"Feature flag 'multi_variate_feature' is not used in a rollout."
42614261
],
@@ -4271,7 +4271,7 @@ def callback(_args); end
42714271
"Starting to evaluate audience '11154' with conditions: [\"and\", [\"or\", [\"or\", {\"name\": \"browser_type\", \"type\": \"custom_attribute\", \"value\": \"firefox\"}]]].",
42724272
"Audience '11154' evaluated to UNKNOWN.",
42734273
"Audiences for experiment 'test_experiment_multivariate' collectively evaluated to FALSE.",
4274-
"User 'user1' does not meet the conditions to be in experiment '122230'.",
4274+
"User 'user1' does not meet the conditions to be in experiment 'test_experiment_multivariate'.",
42754275
"The user 'user1' is not bucketed into any of the experiments on the feature 'multi_variate_feature'.",
42764276
"Feature flag 'multi_variate_feature' is not used in a rollout."
42774277
],

0 commit comments

Comments
 (0)