Skip to content
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: get_optimizely_config API to get static experiments and features data #220

Merged
merged 12 commits into from
Dec 31, 2019

Conversation

zashraf1985
Copy link
Contributor

@zashraf1985 zashraf1985 commented Nov 30, 2019

Summary

Added a get_optimizely_config API which returns static experiments and features data.

Test plan

  1. Manually tested thoroughly
  2. Added Unit tests
  3. Full Stack Integration tests passed

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 99.054% when pulling e234f34 on zeeshan/get_optimizely_config into 6e84924 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 99.054% when pulling e234f34 on zeeshan/get_optimizely_config into 6e84924 on master.

@coveralls
Copy link

coveralls commented Nov 30, 2019

Coverage Status

Coverage decreased (-0.03%) to 99.494% when pulling e554d32 on zeeshan/get_optimizely_config into 80e8618 on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 99.054% when pulling e234f34 on zeeshan/get_optimizely_config into 6e84924 on master.

@zashraf1985 zashraf1985 removed their assignment Nov 30, 2019
# OptimizelyConfig Object Schema
# {
# 'experimentsMap' => {
# '111111' => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The examples are misleading as "id"-based map. Change them all to "key"-based map.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch. Fixed!. I copied them over from javascript-sdk. will fix it there too.

# 'revision' => '13',
# }
#
optimizely_config = OptimizelyConfig.new(project_config)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "unless is_valid" guard like other API calls, returning null when not ready.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

feature_variables_map = @project_config.feature_flags.reduce({}) do |result_map, feature|
result_map.update(feature['id'] => feature['variables'])
end
@project_config.experiments.reduce({}) do |experiments_map, experiment|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

experiments should include experiments dedicated to "groups" as well. It looks like this list does not include them. Check it out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does. Project Config already merged grouped experiments in @experments array. It contains all experiments except rollouts

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. Need to make a couple of changes.

@zashraf1985 zashraf1985 removed their assignment Dec 3, 2019
Copy link
Contributor

@oakbani oakbani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Made a couple of suggestions

@@ -523,6 +524,52 @@ def close
@event_processor.stop! if @event_processor.respond_to?(:stop!)
end

def get_optimizely_config # rubocop:disable Naming/AccessorMethodName
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of disabling it inline here. Please put in rubocop_todo.yml. Makes it easier to see all rule exceptions at one place.
You can even use this utility to auto generate todo file for you.

rubocop --auto-gen-config

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this particular rule can only be disabled for whole file using rubocop_todo which i think is not a good idea. What do you suggest ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I would choose to keep in the todo file. But you may keep it this way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't depend our code files on rubocop. Please add the rule in rubocop_todo.yml.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#

module Optimizely
class OptimizelyConfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a blocker as discussed offline, I would suggest that we should persist OptimizelyConfig response in this class. And each time config is called, it should expect a project config and we only generate new maps if the project ID or revision has changed, otherwise we can return the same response.

Datafile is unlikely to change so often. And we can save time from unnecessarily creating and merging so many maps to generate the same response again and again. Especially when the datafile is huge with many features/ experiments/ variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a great suggestion and i remember we discussed it offline as well. I did it this way because its explicitly mentioned in the documentation that a new object will be generated every time. But i agree, this makes more sense to me as well.
@jaeopt @mjc1283 .. What do you guys think about storing optimizelyconfig and creating a new one only if project config has a newer revision?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zashraf1985 @oakbani both Jae and Matt agree that we should add caching fo the OptimizelyConfig. Can you update the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomaszurkan-optimizely You are abolutely right. But its also decided to do it in two separate PRs and merge them one by one in to master. So this should be considered as the first PR without caching. Once this is merged, we will create another one for caching.

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@thomaszurkan-optimizely thomaszurkan-optimizely left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add caching of the config so that we are not regenerating it every time it is requested?

Copy link
Contributor

@mikeproeng37 mikeproeng37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, we can merge this in separately from the caching feature

@zashraf1985 zashraf1985 merged commit a0c89bf into master Dec 31, 2019
@oakbani oakbani deleted the zeeshan/get_optimizely_config branch August 19, 2020 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants