Skip to content

Commit 0abc6f0

Browse files
[FSSDK-11578] Ruby: Update impression event handling and send notification for global holdout (#376)
* [FSSDK-11578] Ruby: Update impression event handling and send notification for global holdout * Fix lint issues * Fix lint issue * Fix lint and test case errors * Update the "get_holdouts_for_flag" comment
1 parent 7f7f988 commit 0abc6f0

File tree

6 files changed

+812
-564
lines changed

6 files changed

+812
-564
lines changed

lib/optimizely.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ def is_feature_enabled(feature_flag_key, user_id, attributes = nil)
633633
if decision.is_a?(Optimizely::DecisionService::Decision)
634634
variation = decision['variation']
635635
feature_enabled = variation['featureEnabled']
636-
if decision.source == Optimizely::DecisionService::DECISION_SOURCES['FEATURE_TEST']
636+
if decision.source == Optimizely::DecisionService::DECISION_SOURCES['FEATURE_TEST'] || decision.source == Optimizely::DecisionService::DECISION_SOURCES['HOLDOUT']
637637
source_string = Optimizely::DecisionService::DECISION_SOURCES['FEATURE_TEST']
638638
source_info = {
639639
experiment_key: decision.experiment['key'],

lib/optimizely/config/datafile_project_config.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ def initialize(datafile, logger, error_handler)
212212
return unless @holdouts && !@holdouts.empty?
213213

214214
@holdouts.each do |holdout|
215+
next unless holdout['status'] == 'Running'
216+
215217
holdout_key = holdout['key']
216218
holdout_id = holdout['id']
217219

@@ -633,16 +635,17 @@ def rollout_experiment?(experiment_id)
633635
@rollout_experiment_id_map.key?(experiment_id)
634636
end
635637

636-
def get_holdouts_for_flag(flag_key)
638+
def get_holdouts_for_flag(flag_id)
637639
# Helper method to get holdouts from an applied feature flag
638640
#
639-
# flag_key - Key of the feature flag
641+
# flag_id - (REQUIRED) ID of the feature flag
642+
# This parameter is required and should not be null/nil
640643
#
641644
# Returns the holdouts that apply for a specific flag
642645

643646
return [] if @holdouts.nil? || @holdouts.empty?
644647

645-
@flag_holdouts_map[flag_key] || []
648+
@flag_holdouts_map[flag_id] || []
646649
end
647650

648651
def get_holdout(holdout_id)

lib/optimizely/decision_service.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def get_variation_for_feature(project_config, feature_flag, user_context, decide
167167
# user_context - Optimizely user context instance
168168
#
169169
# Returns DecisionResult struct.
170-
holdouts = project_config.get_holdouts_for_flag(feature_flag['key'])
170+
holdouts = project_config.get_holdouts_for_flag(feature_flag['id'])
171171

172172
if holdouts && !holdouts.empty?
173173
# Has holdouts - use get_decision_for_flag which checks holdouts first
@@ -194,7 +194,8 @@ def get_decision_for_flag(feature_flag, user_context, project_config, decide_opt
194194
user_id = user_context.user_id
195195

196196
# Check holdouts
197-
holdouts = project_config.get_holdouts_for_flag(feature_flag['key'])
197+
holdouts = project_config.get_holdouts_for_flag(feature_flag['id'])
198+
198199
holdouts.each do |holdout|
199200
holdout_decision = get_variation_for_holdout(holdout, user_context, project_config)
200201
reasons.push(*holdout_decision.reasons)
@@ -275,7 +276,7 @@ def get_variation_for_holdout(holdout, user_context, project_config)
275276
variation, bucket_reasons = @bucketer.bucket(project_config, holdout, bucketing_id, user_id)
276277
decide_reasons.push(*bucket_reasons)
277278

278-
if variation
279+
if variation && !variation['key'].nil? && !variation['key'].empty?
279280
message = "The user '#{user_id}' is bucketed into variation '#{variation['key']}' of holdout '#{holdout['key']}'."
280281
@logger.log(Logger::INFO, message)
281282
decide_reasons.push(message)

0 commit comments

Comments
 (0)