-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat(OptimizelyConfig): Add new fields to OptimizelyConfig #285
Conversation
lib/optimizely/optimizely_config.rb
Outdated
optly_typed_audiences = [] | ||
|
||
@project_config.audiences.each do |old_audience| | ||
next unless old_audience['id'] != '$opt_dummy_audience' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure, this is the right assumption. it may come in the middle of the array.
lib/optimizely/optimizely_config.rb
Outdated
optly_typed_audiences.push( | ||
'id' => type_audience['id'], | ||
'name' => type_audience['name'], | ||
'conditions' => type_audience['conditions'].to_json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be string
lib/optimizely/optimizely_config.rb
Outdated
config = { | ||
'sdk_key' => @project_config.sdk_key, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sdkKey
lib/optimizely/optimizely_config.rb
Outdated
'attributes' => get_attributes_list(@project_config.attributes), | ||
'audiences' => @audiences, | ||
'events' => get_events_list(@project_config.events), | ||
'environment_key' => @project_config.environment_key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be camelcase.
lib/optimizely/optimizely_config.rb
Outdated
} | ||
) | ||
end | ||
end | ||
|
||
def get_attributes_list(attributes) | ||
attributes.reduce([]) do |attributes_list, attribute| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
map
makes more sense here as you are transforming an array to another array
lib/optimizely/optimizely_config.rb
Outdated
end | ||
|
||
def get_events_list(events) | ||
events.reduce([]) do |events_list, event| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use map
here instead of reduce
lib/optimizely/optimizely_config.rb
Outdated
end | ||
|
||
def lookup_name_from_id(audience_id, audiences_map) | ||
name = audiences_map[audience_id] || audience_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check if only audiences_map[audience_id] || audience_id
works?
name | ||
end | ||
|
||
def stringify_conditions(conditions, audiences_map) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code looks complex. It will be great if you can add detailed comments inside the method with each branch condition.
lib/optimizely/optimizely_config.rb
Outdated
end | ||
|
||
def replace_ids_with_names(conditions, audiences_map) | ||
if !conditions.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT! Could use ternary operator here?
lib/optimizely/optimizely_config.rb
Outdated
experiments.each do |experiment| | ||
optly_exp = { | ||
'id' => experiment['id'], | ||
'key' => experiment['key'], | ||
'variationsMap' => get_variation_map(feature_id, experiment, feature_variables_map), | ||
'audiences' => replace_ids_with_names(experiment.fetch('audienceConditions', []), audiences_id_map) || '' | ||
} | ||
delivery_rules.push(optly_exp) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could use experiment.map
and directly assign to delivery_rules
lib/optimizely/optimizely_config.rb
Outdated
@audiences = [] | ||
type_audiences = @project_config.typed_audiences | ||
optly_typed_audiences = [] | ||
id_lookup_dict = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it holds audiences only, if yes, the name should reflect that.
lib/optimizely/optimizely_config.rb
Outdated
type_audiences = @project_config.typed_audiences | ||
optly_typed_audiences = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whats the difference between type_audiences
and optly_typed_audiences
. It should be clear from the variable names that why there are two arrays being used. Actually you dont even need to use type_audiences
one. You can use #project_config.typed_audiences
directly to loop below. optly_typed_audiences
does not sound consistent with others as no other variable are prefixed with optly
. You should use typed_audiences
to hold temp audiences and directly reference @project_config.typed_audiences
to loop through the original array.
lib/optimizely/optimizely_config.rb
Outdated
experiments_key_map = {} | ||
experiments_id_map.each do |_, experiment| | ||
experiments_key_map[experiment['key']] = experiment | ||
end | ||
experiments_key_map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could probably use reduce here?
A passing continuous integration (CI) can be helpful for reviews, but I will check to see if there is anything I can help with. |
lib/optimizely/optimizely_config.rb
Outdated
'featureEnabled' => variation['featureEnabled'], | ||
'variablesMap' => get_merged_variables_map(variation, feature_id, feature_variables_map) | ||
} | ||
# variation_object['featureEnabled'] = variation['featureEnabled'] if @project_config.feature_experiment?(experiment['id']) || @project_config.rollout_experiment?(experiment['id']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like doing so will help with rubocop
.
|
|
This seems to quiet |
FEATURE_ENABLED is a known issue @msohailhussain . This appears to be the only thing wrong in the FSC. |
Looks good--nice job with passing the PR tests. |
Fullstack-prod-suite seems stuck in travis. Another push may wake it up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Added a few more minor comments. Preapproving based on the assumption that those comments will be addressed before merging
lib/optimizely/optimizely_config.rb
Outdated
audience_id_lookup_dict[typed_audience['id']] = typed_audience['id'] | ||
end | ||
|
||
@project_config.audiences.each do |old_audience| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: Why name it old_audience
. why cant you just call it audience
?
@@ -111,10 +161,107 @@ def get_features_map(all_experiments_map) | |||
'value' => variable['defaultValue'] | |||
} | |||
) | |||
end | |||
end, | |||
'experimentRules' => feature['experimentIds'].reduce([]) do |experiments_map, experiment_id| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use map
here. you are transforming array into an array here, not reducing to a value or object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
A couple of comments about deprecation suggested.
config = { | ||
'sdkKey' => @project_config.sdk_key, | ||
'datafile' => @project_config.datafile, | ||
'experimentsMap' => experiments_map_object, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a note about key-conflict issue on top of 'experimentsMap':
// This experimentsMap is for experiments of legacy projects only.
// For flag projects, experiment keys are not guaranteed to be unique
// across multiple flags, so this map may not include all experiments
// when keys conflict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a period at the end of the first sentence - "This experimentsMap is for experiments of legacy projects only"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecation message should be changed
lib/optimizely/optimizely_config.rb
Outdated
# This experimentsMap is for experiments of legacy projects only. | ||
# For flag projects, experiment keys are not guaranteed to be unique | ||
# across multiple flags, so this map may not include all experiments | ||
# when keys conflict. Use experimentRules and deliveryRules instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message should be chanaged to:
"This experimentsMap is deprecated. Use experimentRules and deliveryRules instead."
The one at top level ("experimentsMap" in OptimizleyConfig) looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
The following new public properties are added to OptimizelyConfig:
Test plan
All FSC tests OPTIMIZELY_CONFIG_V2 tests should pass.
https://travis-ci.com/github/optimizely/fullstack-sdk-compatibility-suite/builds/235036023