diff --git a/Gemfile b/Gemfile index 25fb430c2909a172e616303260ef89106e96191e..8c331321ff680520b0f91128abf3707d6aa6cd19 100644 --- a/Gemfile +++ b/Gemfile @@ -488,9 +488,9 @@ gem 'google-protobuf', '~> 3.15.8' gem 'toml-rb', '~> 1.0.0' # Feature toggles -gem 'flipper', '~> 0.17.1' -gem 'flipper-active_record', '~> 0.17.1' -gem 'flipper-active_support_cache_store', '~> 0.17.1' +gem 'flipper', '~> 0.21.0' +gem 'flipper-active_record', '~> 0.21.0' +gem 'flipper-active_support_cache_store', '~> 0.21.0' gem 'unleash', '~> 0.1.5' gem 'gitlab-experiment', '~> 0.5.4' diff --git a/Gemfile.lock b/Gemfile.lock index 62f5eb4d3a9dd541be7b12c09fe257ac33620295..310f824a4acfed80e954a52fed62e29c65fa54ba 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -372,13 +372,13 @@ GEM rake ffi-yajl (2.3.4) libyajl2 (~> 1.2) - flipper (0.17.1) - flipper-active_record (0.17.1) - activerecord (>= 4.2, < 7) - flipper (~> 0.17.1) - flipper-active_support_cache_store (0.17.1) - activesupport (>= 4.2, < 7) - flipper (~> 0.17.1) + flipper (0.21.0) + flipper-active_record (0.21.0) + activerecord (>= 5.0, < 7) + flipper (~> 0.21.0) + flipper-active_support_cache_store (0.21.0) + activesupport (>= 5.0, < 7) + flipper (~> 0.21.0) flowdock (0.7.1) httparty (~> 0.7) multi_json @@ -1454,9 +1454,9 @@ DEPENDENCIES faraday_middleware-aws-sigv4 (~> 0.3.0) fast_blank ffaker (~> 2.10) - flipper (~> 0.17.1) - flipper-active_record (~> 0.17.1) - flipper-active_support_cache_store (~> 0.17.1) + flipper (~> 0.21.0) + flipper-active_record (~> 0.21.0) + flipper-active_support_cache_store (~> 0.21.0) flowdock (~> 0.7) fog-aliyun (~> 0.3) fog-aws (~> 3.9) diff --git a/config/initializers/flipper.rb b/config/initializers/flipper.rb new file mode 100644 index 0000000000000000000000000000000000000000..be4f01f537dd5c86e50947dffeb774e1a51b9650 --- /dev/null +++ b/config/initializers/flipper.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +Rails.application.configure do + config.flipper.preload = false + config.flipper.memoizer = false +end diff --git a/lib/feature.rb b/lib/feature.rb index 87abd2689d06d6ff95a98ca15dc0075b4f4517ae..453ecc8255afb8bb5a2903082ab8e550737ddaed 100644 --- a/lib/feature.rb +++ b/lib/feature.rb @@ -18,6 +18,10 @@ class FlipperGate < Flipper::Adapters::ActiveRecord::Gate superclass.table_name = 'feature_gates' end + # To enable EE overrides + class ActiveSupportCacheStoreAdapter < Flipper::Adapters::ActiveSupportCacheStore + end + InvalidFeatureFlagError = Class.new(Exception) # rubocop:disable Lint/InheritException class << self @@ -167,7 +171,8 @@ def build_flipper_instance ActiveSupportCacheStoreAdapter.new( active_record_adapter, l2_cache_backend, - expires_in: 1.hour) + expires_in: 1.hour, + write_through: true) # Thread-local L1 cache: use a short timeout since we don't have a # way to expire this cache all at once diff --git a/lib/feature/active_support_cache_store_adapter.rb b/lib/feature/active_support_cache_store_adapter.rb deleted file mode 100644 index 431f1169a86a015f874e8006ec0f5b3dac74f5e4..0000000000000000000000000000000000000000 --- a/lib/feature/active_support_cache_store_adapter.rb +++ /dev/null @@ -1,36 +0,0 @@ -# frozen_string_literal: true - -# rubocop:disable Gitlab/NamespacedClass -# This class was already nested this way before moving to a separate file -class Feature - class ActiveSupportCacheStoreAdapter < Flipper::Adapters::ActiveSupportCacheStore - # This patch represents https://github.com/jnunemaker/flipper/pull/512. In - # Flipper 0.21.0 and later, we can remove this and just pass `write_through: - # true` to the constructor in `Feature.build_flipper_instance`. - - extend ::Gitlab::Utils::Override - - override :enable - def enable(feature, gate, thing) - result = @adapter.enable(feature, gate, thing) - @cache.write(key_for(feature.key), @adapter.get(feature), @write_options) - result - end - - override :disable - def disable(feature, gate, thing) - result = @adapter.disable(feature, gate, thing) - @cache.write(key_for(feature.key), @adapter.get(feature), @write_options) - result - end - - override :remove - def remove(feature) - result = @adapter.remove(feature) - @cache.delete(FeaturesKey) - @cache.write(key_for(feature.key), {}, @write_options) - result - end - end -end -# rubocop:disable Gitlab/NamespacedClass