8000 feat: added "enabled" field to decision metadata structure by zashraf1985 · Pull Request #275 · optimizely/ruby-sdk · GitHub
[go: up one dir, main page]

Skip to content

feat: added "enabled" field to decision metadata structure #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/optimizely.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def activate(experiment_key, user_id, attributes = nil)
# Create and dispatch impression event
experiment = config.get_experiment_from_key(experiment_key)
send_impression(
config, experiment, variation_key, '', experiment_key,
config, experiment, variation_key, '', experiment_key, true,
Optimizely::DecisionService::DECISION_SOURCES['EXPERIMENT'], user_id, attributes
)

Expand Down Expand Up @@ -321,18 +321,18 @@ def is_feature_enabled(feature_flag_key, user_id, attributes = nil)
}
# Send event if Decision came from a feature test.
send_impression(
config, decision.experiment, variation['key'], feature_flag_key, decision.experiment['key'], source_string, user_id, attributes
config, decision.experiment, variation['key'], feature_flag_key, decision.experiment['key'], feature_enabled, source_string, user_id, attributes
)
elsif decision.source == Optimizely::DecisionService::DECISION_SOURCES['ROLLOUT'] && config.send_flag_decisions
send_impression(
config, decision.experiment, variation['key'], feature_flag_key, decision.experiment['key'], source_string, user_id, attributes
config, decision.experiment, variation['key'], feature_flag_key, decision.experiment['key'], feature_enabled, source_string, user_id, attributes
)
end
end

if decision.nil? && config.send_flag_decisions
send_impression(
config, nil, '', feature_flag_key, '', source_string, user_id, attributes
config, nil, '', feature_flag_key, '', feature_enabled, source_string, user_id, attributes
)
end

Expand Down Expand Up @@ -879,7 +879,7 @@ def validate_instantiation_options
raise InvalidInputError, 'event_dispatcher'
end

def send_impression(config, experiment, variation_key, flag_key, rule_key, rule_type, user_id, attributes = nil)
def send_impression(config, experiment, variation_key, flag_key, rule_key, enabled, rule_type, user_id, attributes = nil)
if experiment.nil?
experiment = {
'id' => '',
Expand All @@ -903,7 +903,8 @@ def send_impression(config, experiment, variation_key, flag_key, rule_key, rule_
flag_key: flag_key,
rule_key: rule_key,
rule_type: rule_type,
variation_key: variation_key
variation_key: variation_key,
enabled: enabled
}

user_event = UserEventFactory.create_impression_event(config, experiment, variation_id, metadata, user_id, attributes)
Expand Down
27 changes: 18 additions & 9 deletions spec/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ class InvalidErrorHandler; end
flag_key: '',
rule_key: 'test_experiment',
rule_type: 'experiment',
variation_key: 'control'
variation_key: 'control',
enabled: true
}
}],
events: [{
Expand Down Expand Up @@ -232,7 +233,8 @@ class InvalidErrorHandler; end
flag_key: '',
rule_key: 'test_experiment_with_audience',
rule_type: 'experiment',
variation_key: 'control_with_audience'
variation_key: 'control_with_audience',
enabled: true
}

variation_to_return = project_config.get_variation_from_id('test_experiment_with_audience', '122228')
Expand Down Expand Up @@ -307,7 +309,8 @@ class InvalidErrorHandler; end
flag_key: '',
rule_key: 'typed_audience_experiment',
rule_type: 'experiment',
variation_key: variation_to_return['key']
variation_key: variation_to_return['key'],
enabled: true
}

allow(@project_typed_audience_instance.decision_service.bucketer).to receive(:bucket).and_return(variation_to_return)
Expand Down Expand Up @@ -342,7 +345,8 @@ class InvalidErrorHandler; end
flag_key: '',
rule_key: 'typed_audience_experiment',
rule_type: 'experiment',
variation_key: variation_to_return['key']
variation_key: variation_to_return['key'],
enabled: true
}

allow(@project_typed_audience_instance.decision_service.bucketer).to receive(:bucket).and_return(variation_to_return)
Expand Down Expand Up @@ -399,7 +403,8 @@ class InvalidErrorHandler; end
flag_key: '',
rule_key: 'audience_combinations_experiment',
rule_type: 'experiment',
variation_key: variation_to_return['key']
variation_key: variation_to_return['key'],
enabled: true
}

allow(@project_typed_audience_instance.decision_service.bucketer).to receive(:bucket).and_return(variation_to_return)
Expand Down Expand Up @@ -459,7 +464,8 @@ class InvalidErrorHandler; end
flag_key: '',
rule_key: 'test_experiment_with_audience',
rule_type: 'experiment',
variation_key: 'control_with_audience'
variation_key: 'control_with_audience',
enabled: true
}

variation_to_return = project_config.get_variation_from_id('test_experiment_with_audience', '122228')
Expand Down Expand Up @@ -504,7 +510,8 @@ class InvalidErrorHandler; end
flag_key: '',
rule_key: 'test_experiment_with_audience',
rule_type: 'experiment',
variation_key: 'control_with_audience'
variation_key: 'control_with_audience',
enabled: true
}

variation_to_return = project_config.get_variation_from_id('test_experiment_with_audience', '122228')
Expand Down Expand Up @@ -546,7 +553,8 @@ class InvalidErrorHandler; end
flag_key: '',
rule_key: 'test_experiment_with_audience',
rule_type: 'experiment',
variation_key: 'variation_with_audience'
variation_key: 'variation_with_audience',
enabled: true
}

allow(project_instance.decision_service.bucketer).to receive(:bucket).and_return(variation_to_return)
Expand Down Expand Up @@ -718,7 +726,8 @@ def callback(_args); end
flag_key: '',
rule_key: 'test_experiment_with_audience',
rule_type: 'experiment',
variation_key: 'variation_with_audience'
variation_key: 'variation_with_audience',
enabled: true
}

allow(project_instance.event_dispatcher).to receive(:dispatch_event).with(instance_of(Optimizely::Event))
Expand Down
0