-
Notifications
You must be signed in to change notification settings - Fork 27
feat: Duplicate experiment key issue with multi feature flag #282
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
Changes from 16 commits
a7c6212
20a58a0
0134661
a5b8636
a3645bd
ba3a009
16a2dce
009a86e
450fded
eecae46
729a70b
6ed69a1
cc2af3f
8bc63dd
2aca129
697e13d
326b771
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -54,10 +54,12 @@ class DatafileProjectConfig < ProjectConfig | |||||
| attr_reader :feature_variable_key_map | ||||||
| attr_reader :group_id_map | ||||||
| attr_reader :rollout_id_map | ||||||
| attr_reader :rollout_experiment_key_map | ||||||
| attr_reader :rollout_experiment_id_map | ||||||
| attr_reader :variation_id_map | ||||||
| attr_reader :variation_id_to_variable_usage_map | ||||||
| attr_reader :variation_key_map | ||||||
| attr_reader :variation_id_map_by_experiment_id | ||||||
| attr_reader :variation_key_map_by_experiment_id | ||||||
|
|
||||||
| def initialize(datafile, logger, error_handler) | ||||||
| # ProjectConfig init method to fetch and set project config data | ||||||
|
|
@@ -117,9 +119,11 @@ def initialize(datafile, logger, error_handler) | |||||
| @audience_id_map = @audience_id_map.merge(generate_key_map(@typed_audiences, 'id')) unless @typed_audiences.empty? | ||||||
| @variation_id_map = {} | ||||||
| @variation_key_map = {} | ||||||
| @variation_id_map_by_experiment_id = {} | ||||||
| @variation_key_map_by_experiment_id = {} | ||||||
| @variation_id_to_variable_usage_map = {} | ||||||
| @variation_id_to_experiment_map = {} | ||||||
| @experiment_key_map.each_value do |exp| | ||||||
| @experiment_id_map.each_value do |exp| | ||||||
| # Excludes experiments from rollouts | ||||||
| variations = exp.fetch('variations') | ||||||
| variations.each do |variation| | ||||||
|
|
@@ -129,13 +133,13 @@ def initialize(datafile, logger, error_handler) | |||||
| end | ||||||
| @rollout_id_map = generate_key_map(@rollouts, 'id') | ||||||
| # split out the experiment key map for rollouts | ||||||
| @rollout_experiment_key_map = {} | ||||||
| @rollout_experiment_id_map = {} | ||||||
| @rollout_id_map.each_value do |rollout| | ||||||
| exps = rollout.fetch('experiments') | ||||||
| @rollout_experiment_key_map = @rollout_experiment_key_map.merge(generate_key_map(exps, 'key')) | ||||||
| @rollout_experiment_id_map = @rollout_experiment_id_map.merge(generate_key_map(exps, 'id')) | ||||||
| end | ||||||
| @all_experiments = @experiment_key_map.merge(@rollout_experiment_key_map) | ||||||
| @all_experiments.each do |key, exp| | ||||||
| @all_experiments = @experiment_id_map.merge(@rollout_experiment_id_map) | ||||||
| @all_experiments.each do |id, exp| | ||||||
| variations = exp.fetch('variations') | ||||||
| variations.each do |variation| | ||||||
| variation_id = variation['id'] | ||||||
|
|
@@ -145,8 +149,10 @@ def initialize(datafile, logger, error_handler) | |||||
|
|
||||||
| @variation_id_to_variable_usage_map[variation_id] = generate_key_map(variation_variables, 'id') | ||||||
| end | ||||||
| @variation_id_map[key] = generate_key_map(variations, 'id') | ||||||
| @variation_key_map[key] = generate_key_map(variations, 'key') | ||||||
| @variation_id_map[exp['key']] = generate_key_map(variations, 'id') | ||||||
| @variation_key_map[exp['key']] = generate_key_map(variations, 'key') | ||||||
| @variation_id_map_by_experiment_id[id] = generate_key_map(variations, 'id') | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need it by experiment id? i assume variation ids are unique? if yes, then a simple map with variation ids as keys and variations as values would suffice? It was probably required in case of variation keys because keys can be reused across the experiments and you needed to specify which experiment to look into, but for variation id, i am not sure if experiment info is needed at all? |
||||||
| @variation_key_map_by_experiment_id[id] = generate_key_map(variations, 'key') | ||||||
|
Comment on lines
+152
to
+155
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These variable names are really confusing. Looking at
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's talk offline. |
||||||
| end | ||||||
| @feature_flag_key_map = generate_key_map(@feature_flags, 'key') | ||||||
| @experiment_feature_map = {} | ||||||
|
|
@@ -213,6 +219,21 @@ def get_experiment_from_key(experiment_key) | |||||
| nil | ||||||
| end | ||||||
|
|
||||||
| def get_experiment_from_id(experiment_id) | ||||||
| # Retrieves experiment ID for a given key | ||||||
| # | ||||||
| # experiment_id - String id representing the experiment | ||||||
| # | ||||||
| # Returns Experiment or nil if not found | ||||||
|
|
||||||
| experiment = @experiment_id_map[experiment_id] | ||||||
| return experiment if experiment | ||||||
|
|
||||||
| @logger.log Logger::ERROR, "Experiment id '#{experiment_id}' is not in datafile." | ||||||
| @error_handler.handle_error InvalidExperimentError | ||||||
| nil | ||||||
| end | ||||||
|
|
||||||
| def get_experiment_key(experiment_id) | ||||||
| # Retrieves experiment key for a given ID. | ||||||
| # | ||||||
|
|
@@ -281,6 +302,52 @@ def get_variation_from_id(experiment_key, variation_id) | |||||
| nil | ||||||
| end | ||||||
|
|
||||||
| def get_variation_from_id_by_experiment_id(experiment_id, variation_id) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can variation ids duplicate across experiments? why do we need
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes as far as I know variation Ids are unique but I was following this method |
||||||
| # Get variation given experiment ID and variation ID | ||||||
| # | ||||||
| # experiment_id - ID representing parent experiment of variation | ||||||
| # variation_id - ID of the variation | ||||||
| # | ||||||
| # Returns the variation or nil if not found | ||||||
|
|
||||||
| variation_id_map_by_experiment_id = @variation_id_map_by_experiment_id[experiment_id] | ||||||
| if variation_id_map_by_experiment_id | ||||||
| variation = variation_id_map_by_experiment_id[variation_id] | ||||||
| return variation if variation | ||||||
|
|
||||||
| @logger.log Logger::ERROR, "Variation id '#{variation_id}' is not in datafile." | ||||||
| @error_handler.handle_error InvalidVariationError | ||||||
| return nil | ||||||
| end | ||||||
|
|
||||||
| @logger.log Logger::ERROR, "Experiment id '#{experiment_id}' is not in datafile." | ||||||
| @error_handler.handle_error InvalidExperimentError | ||||||
| nil | ||||||
| end | ||||||
|
|
||||||
| def get_variation_id_from_key_by_experiment_id(experiment_id, variation_key) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense because |
||||||
| # Get variation given experiment ID and variation key | ||||||
| # | ||||||
| # experiment_id - ID representing parent experiment of variation | ||||||
| # variation_key - Key of the variation | ||||||
| # | ||||||
| # Returns the variation or nil if not found | ||||||
|
|
||||||
| variation_key_map_by_experiment_id = @variation_key_map_by_experiment_id[experiment_id] | ||||||
|
||||||
| variation_key_map_by_experiment_id = @variation_key_map_by_experiment_id[experiment_id] | |
| variation_key_map = @variation_key_map_by_experiment_id[experiment_id] |
same name as the map will be confusing
Outdated
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.
| variation = variation_key_map_by_experiment_id[variation_key] | |
| variation = variation_key_map[variation_key] |
Outdated
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.
fix this comment
Outdated
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 will be helpful to keep both experiment_id and experiment_key in the log
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.
Cant use experiment key here as we are no longer sending key in get_whitelisted_variations instead we are sending the ID. If the given ID is wrong we cannot get an experiment and hence we can not get the 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.
keep experiment_key in log
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 agree with @jaeopt on this. Also adding experiment_id can actually help too
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.
Having both will be helpful, but for consistency with all other SDKs, let's stick to "key" only in logs and messages