-
-
Notifications
You must be signed in to change notification settings - Fork 420
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
Configure adapters on require #502
Conversation
@jnunemaker per our text conversation, I'm trying to figure out a way to initialize the cache adapters with sensible defaults, and it's a little challenging with the adapters that wrap other adapters, namely the caching-related ones. Here's a couple ideas to work around this issue: Configuration for store vs cacheA lot (but not all) of the adapters fall into one of two camps: storage or cache. If If we added # flipper-active_record.rb
Flipper.configure do |config|
config.store { Flipper::ActiveRecord::Adapter.new }
end # flipper-dalli.rb
Flipper.configure do |config|
config.cache do |store| # the adapter configured by calling `config.store { }`
Flipper::Cache::Dali.new(store, Dalli::Client.new('localhost:11211'), 600)
end
end The current # flipper-cloud.rb
Flipper.configure do |config|
config.default do |adapter| # `store` wrapped with `cache`
Flipper::Cloud.new(…, adapter)
end
end If you wanted to get really aggressive with this route, I think it could make sense to rename the adapters that fall into store vs cache:
All adapters would maintain their same interfaces. Any renamed classes could be aliased to their current constant names with deprecation warnings to maintain backward compatibility. Middleware-ishThe adapters that don't wrap (which I was calling storage adapters above) are really the only ones that are exclusive. It seems like the rest can be nested in whichever way makes sense for the application. So maybe it's not "storage vs cache", but closer to a Rack middleware concept, where there's a single storage adapter, and then middleware that wrap it. # flipper-active_record.rb
Flipper.configure do |config|
config.store { Flipper::ActiveRecord::Adapter.new }
end # flipper-dalli.rb
Flipper.configure do |config|
config.use do |adapter|
Flipper::Cache::Dali.new(adapter, Dalli::Client.new('localhost:11211'), 600)
end
end The main difference between # flipper-cloud.rb
Flipper.configure do |config|
config.default do |adapter| `store` wrapped with any other adapters configured via `#use`
Flipper::Cloud.new(…, adapter)
end
end Thoughts on this? Any preference? Or any other ideas? |
This is exciting! I think I'd need to see a few examples to be able to decide on API for this. Like maybe what each of these wold look like:
Random thoughts:
|
* origin/master: Move redis-namespace to gemfile Fix ci yaml token usage Remove body debugging Fix failures due to body change Add response body to error to debug Set FLIPPER_CLOUD_TOKEN when running examples Run examples with GitHub Actions Simplify example setup with bundler/setup Use `Flipper` instead of `Flipper.instance` Use `enable_percentage_of_time` Use `Flipper.enabed?` Use `enable_percentage_of_actors` Use `enable_group` Update typo lib/flipper/configuration.rb Remove Memory setup from README Default to using Memory adapter
@jnunemaker I messed around with a few different incantations of changing how the configuration works, and I don't really like any of them. So I'm thinking I want to let it simmer for a while, skip default configuration for the cache adapters for now, and maybe make another attempt later. They're advanced usage anyway, so I don't think it's a problem to require manual configuration. This is ready for your review. |
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.
Looks great. Thanks for updating the docs too. The initializers being commented out was the only question I had. Was the intent to show not to do it by default and that you'd need to uncomment for it to work?
docs/active_record/README.md
Outdated
adapter = Flipper::Adapters::ActiveRecord.new | ||
flipper = Flipper.new(adapter) | ||
# profit... | ||
# require 'flipper/adapters/active_record' |
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 this be commented out?
Yes, that was what I was thinking. Thoughts on how to better communicate that? |
Add Flipper::Identifier with default flipper_id method
Maybe just bold the "if you want to customize" part and/or put a comment at the top of the block that says if you want to customize? |
Or a comment that says uncomment this either in the code snippet or before it. I'd like to think it is obvious that you need to uncomment, but you never know. Haha |
* origin/master: Add cloud recommendation
For most use cases, a user should just be able to require an adapter and have it configure itself with sensible defaults. They can still override the default configuration, but this will make it just a little easer to get started.
These are going to be harder because they need to wrap another adapter. Ideally the would just get the current default, and replace it with a wrapped adapter:
dalliactive_support_cache_storecloudEdit: Skipping cache adapters for now.
And overall:
This is related to #500 for improving the onboarding experience.