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

When preload_all is enabled, disabled features don't show up in the flipper-ui #324

Closed
geetotes opened this issue Jan 5, 2018 · 4 comments
Closed

Comments

@geetotes
Copy link

@geetotes geetotes commented Jan 5, 2018

I'm using Rails 5 and my config/initializers/flipper.rb looks like this:

require 'flipper'
require 'flipper/adapters/active_record'
require 'flipper/adapters/active_support_cache_store'

Flipper.configure do |config|
  config.default do
    adapter = Flipper::Adapters::ActiveRecord.new
    cached_adapter = Flipper::Adapters::ActiveSupportCacheStore.new(
      adapter,
      Rails.cache,
      expires_in: 10.seconds
    )
    Flipper.new(cached_adapter)
  end
end

require 'flipper/middleware/memoizer'
Rails.configuration.middleware.use Flipper::Middleware::Memoizer, preload_all: true

When using the preload_all: true option, Flipper features are loaded with this query:
Flipper::Adapters::ActiveRecord::Gate Load (2.5ms) SELECT `flipper_gates`.* FROM `flipper_gates` INNER JOIN flipper_features ON flipper_features.key = flipper_gates.feature_key

Unfortunately, disabled features don't show up in this list, so when I visit the flipper-ui, my disabled features don't appear in the list of features available at the /features route.

When I remove preload_all from my Memoizer options, I see my disabled features in flipper-ui

@jnunemaker
Copy link
Owner

@jnunemaker jnunemaker commented Jan 5, 2018

@geetotes hi! Nothing comes to mind. What version of flipper, flipper-ui and flipper-active_record are you on? Could you print out your middleware stack (bin/rails middleware I think)? Also, what version of rails?

The only other thing I can think is that the UI also includes the memoizer. Shouldn't hurt anything as it does no preloading. Some other debugging data that could help would be selecting all the rows from the flipper_features and flipper_gates tables so I could try to re-create your problem.

@geetotes
Copy link
Author

@geetotes geetotes commented Jan 5, 2018

Hi @jnunemaker!

I'm running Rails 5.1.4. From my gemfile.lock:

    flipper (0.11.0)
    flipper-active_record (0.11.0)
      flipper (~> 0.11.0)
    flipper-active_support_cache_store (0.11.0)
      flipper (~> 0.11.0)
    flipper-ui (0.11.0)
      flipper (~> 0.11.0)
activerecord (5.1.4)

Here's my middleware stack:

use Webpacker::DevServerProxy
use Rack::Sendfile
use ActionDispatch::Static
use ActionDispatch::Executor
use ActiveSupport::Cache::Strategy::LocalCache::Middleware
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use ActionDispatch::RemoteIp
use Sprockets::Rails::QuietAssets
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use WebConsole::Middleware
use ActionDispatch::DebugExceptions
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::Migration::CheckPending
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
use Warden::Manager
use Versionist::Middleware
use Rack::Deflater
use Flipper::Middleware::Memoizer
use OmniAuth::Strategies::Facebook
use OmniAuth::Strategies::Twitter
use OmniAuth::Strategies::GoogleOauth2
run Romwod::Application.routes

I think the UI is also including the memoizer, but it is also doing the preloading.

mysql> select * from flipper_features;
+----+-----------------------+---------------------+---------------------+
| id | key                   | created_at          | updated_at          |
+----+-----------------------+---------------------+---------------------+
|  1 | amazon_enabled        | 2018-01-04 01:50:48 | 2018-01-04 01:50:48 |
|  2 | paypal_enabled        | 2018-01-05 02:41:54 | 2018-01-05 02:41:54 |
|  3 | ach_enabled           | 2018-01-05 02:42:08 | 2018-01-05 02:42:08 |
|  4 | fb_login_enabled      | 2018-01-05 02:42:34 | 2018-01-05 02:42:34 |
|  5 | google_login_enabled  | 2018-01-05 02:42:47 | 2018-01-05 02:42:47 |
|  6 | twitter_login_enabled | 2018-01-05 02:43:10 | 2018-01-05 02:43:10 |
|  7 | dis_test              | 2018-01-05 18:31:25 | 2018-01-05 18:31:25 |
|  8 | hello                 | 2018-01-05 18:50:31 | 2018-01-05 18:50:31 |
+----+-----------------------+---------------------+---------------------+
mysql> select * from flipper_gates;
+----+-----------------------+---------+-------+---------------------+---------------------+
| id | feature_key           | key     | value | created_at          | updated_at          |
+----+-----------------------+---------+-------+---------------------+---------------------+
|  3 | paypal_enabled        | boolean | true  | 2018-01-05 02:41:56 | 2018-01-05 02:41:56 |
|  8 | ach_enabled           | boolean | true  | 2018-01-05 03:27:59 | 2018-01-05 03:27:59 |
|  9 | amazon_enabled        | boolean | true  | 2018-01-05 03:28:21 | 2018-01-05 03:28:21 |
| 11 | fb_login_enabled      | boolean | true  | 2018-01-05 04:04:32 | 2018-01-05 04:04:32 |
| 12 | twitter_login_enabled | boolean | true  | 2018-01-05 18:31:06 | 2018-01-05 18:31:06 |
| 13 | google_login_enabled  | boolean | true  | 2018-01-05 18:31:13 | 2018-01-05 18:31:13 |
| 15 | hello                 | boolean | true  | 2018-01-05 18:50:41 | 2018-01-05 18:50:41 |
+----+-----------------------+---------+-------+---------------------+---------------------+

The way that join statement is set up with preload_all, it doesn't include the dis_test feature, which is disabled.

@jnunemaker
Copy link
Owner

@jnunemaker jnunemaker commented Jan 5, 2018

Oh right! Probably need a left join or whatever. Awesome. Thanks for pointing it out. If anyone wants to take a stab at that feel free. I’ll try to in the next few days as I have some holiday free time.

@geetotes
Copy link
Author

@geetotes geetotes commented Jan 8, 2018

Thanks @jnunemaker!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.