Merge pull request #10059 from colinux/improve-flipper
Tech: réduit l'impact de Flipper sur la base
This commit is contained in:
commit
9280ccc23d
7 changed files with 89 additions and 21 deletions
1
Gemfile
1
Gemfile
|
@ -33,6 +33,7 @@ gem 'dotenv-rails', require: 'dotenv/rails-now' # dotenv should always be loaded
|
||||||
gem 'dry-monads'
|
gem 'dry-monads'
|
||||||
gem 'flipper'
|
gem 'flipper'
|
||||||
gem 'flipper-active_record'
|
gem 'flipper-active_record'
|
||||||
|
gem 'flipper-active_support_cache_store'
|
||||||
gem 'flipper-ui'
|
gem 'flipper-ui'
|
||||||
gem 'fugit'
|
gem 'fugit'
|
||||||
gem 'geocoder'
|
gem 'geocoder'
|
||||||
|
|
|
@ -237,6 +237,9 @@ GEM
|
||||||
flipper-active_record (1.2.2)
|
flipper-active_record (1.2.2)
|
||||||
activerecord (>= 4.2, < 8)
|
activerecord (>= 4.2, < 8)
|
||||||
flipper (~> 1.2.2)
|
flipper (~> 1.2.2)
|
||||||
|
flipper-active_support_cache_store (1.2.2)
|
||||||
|
activesupport (>= 4.2, < 8)
|
||||||
|
flipper (~> 1.2.2)
|
||||||
flipper-ui (1.2.2)
|
flipper-ui (1.2.2)
|
||||||
erubi (>= 1.0.0, < 2.0.0)
|
erubi (>= 1.0.0, < 2.0.0)
|
||||||
flipper (~> 1.2.2)
|
flipper (~> 1.2.2)
|
||||||
|
@ -833,6 +836,7 @@ DEPENDENCIES
|
||||||
factory_bot
|
factory_bot
|
||||||
flipper
|
flipper
|
||||||
flipper-active_record
|
flipper-active_record
|
||||||
|
flipper-active_support_cache_store
|
||||||
flipper-ui
|
flipper-ui
|
||||||
fugit
|
fugit
|
||||||
geo_coord
|
geo_coord
|
||||||
|
|
|
@ -561,10 +561,11 @@ class Procedure < ApplicationRecord
|
||||||
procedure.update!(defaut_groupe_instructeur: new_defaut_groupe)
|
procedure.update!(defaut_groupe_instructeur: new_defaut_groupe)
|
||||||
|
|
||||||
Flipper.features.each do |feature|
|
Flipper.features.each do |feature|
|
||||||
if feature_enabled?(feature.key)
|
next if feature.enabled? # don't clone features globally enabled
|
||||||
|
next unless feature_enabled?(feature.key)
|
||||||
|
|
||||||
Flipper.enable(feature.key, procedure)
|
Flipper.enable(feature.key, procedure)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
procedure
|
procedure
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
# This setup is primarily for first deployment, because consequently
|
# This setup is primarily for first deployment, because consequently
|
||||||
# we can add new features from the Web UI. However when the new DB is created
|
# we can add new features from the Web UI. However when the new DB is created
|
||||||
# this will immediately migrate the default features to be controlled.
|
# this will immediately migrate the default features to be controlled.
|
||||||
|
#
|
||||||
|
require 'flipper/adapters/active_record'
|
||||||
|
require 'flipper/adapters/active_support_cache_store'
|
||||||
|
|
||||||
def setup_features(features)
|
def setup_features(features)
|
||||||
features.each do |feature|
|
existing = Flipper.preload(features).map { _1.name.to_sym }
|
||||||
if !Flipper.exist?(feature)
|
missing = features - existing
|
||||||
# Disable feature by default
|
|
||||||
Flipper.disable(feature)
|
missing.each do |feature|
|
||||||
end
|
# Feature is disabled by default
|
||||||
|
Flipper.add(feature.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -14,13 +19,17 @@ end
|
||||||
features = [
|
features = [
|
||||||
:administrateur_web_hook,
|
:administrateur_web_hook,
|
||||||
:api_particulier,
|
:api_particulier,
|
||||||
:dossier_pdf_vide,
|
:attestation_v2,
|
||||||
:hide_instructeur_email,
|
:blocking_pending_correction,
|
||||||
:procedure_routage_api,
|
|
||||||
:groupe_instructeur_api_hack,
|
|
||||||
:cojo_type_de_champ,
|
:cojo_type_de_champ,
|
||||||
|
:dossier_pdf_vide,
|
||||||
|
:engagement_juridique_type_de_champ,
|
||||||
|
:export_order_by_revision,
|
||||||
|
:expression_reguliere_type_de_champ,
|
||||||
|
:groupe_instructeur_api_hack,
|
||||||
|
:hide_instructeur_email,
|
||||||
:sva,
|
:sva,
|
||||||
:blocking_pending_correction
|
:switch_domain
|
||||||
]
|
]
|
||||||
|
|
||||||
def database_exists?
|
def database_exists?
|
||||||
|
@ -35,3 +44,19 @@ ActiveSupport.on_load(:active_record) do
|
||||||
setup_features(features)
|
setup_features(features)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Flipper.configure do |config|
|
||||||
|
config.adapter do
|
||||||
|
Flipper::Adapters::ActiveSupportCacheStore.new(
|
||||||
|
Flipper::Adapters::ActiveRecord.new,
|
||||||
|
ActiveSupport::Cache::MemoryStore.new,
|
||||||
|
expires_in: 10.seconds
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Rails.application.configure do
|
||||||
|
# don't preload features for /assets/* but do for everything else
|
||||||
|
config.flipper.preload = -> (request) { !request.path.start_with?('/assets/', '/ping') }
|
||||||
|
config.flipper.strict = Rails.env.development?
|
||||||
|
end
|
||||||
|
|
29
lib/tasks/deployment/20240301223646_clean_old_gates2024.rake
Normal file
29
lib/tasks/deployment/20240301223646_clean_old_gates2024.rake
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
namespace :after_party do
|
||||||
|
desc 'Deployment task: clean_old_gates2024'
|
||||||
|
task clean_old_gates2024: :environment do
|
||||||
|
puts "Running deploy task 'clean_old_gates2024'"
|
||||||
|
|
||||||
|
keys = [
|
||||||
|
'admin_affect_experts_to_avis',
|
||||||
|
'chorus',
|
||||||
|
'disable_label_optional_champ_2023_06_29',
|
||||||
|
'expert_not_allowed_to_invite',
|
||||||
|
'instructeur_bypass_email_login_token',
|
||||||
|
'multi_line_routing',
|
||||||
|
'opendata',
|
||||||
|
'procedure_conditional',
|
||||||
|
'procedure_routage_api',
|
||||||
|
'rerouting',
|
||||||
|
'routing_rules',
|
||||||
|
'zonage'
|
||||||
|
]
|
||||||
|
|
||||||
|
Flipper::Adapters::ActiveRecord::Gate.where(feature_key: keys).delete_all
|
||||||
|
Flipper::Adapters::ActiveRecord::Feature.where(key: keys).delete_all
|
||||||
|
|
||||||
|
# Update task as completed. If you remove the line below, the task will
|
||||||
|
# run with every deploy (or every time you call after_party:run).
|
||||||
|
AfterParty::TaskRecord
|
||||||
|
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||||
|
end
|
||||||
|
end
|
|
@ -871,21 +871,33 @@ describe Procedure do
|
||||||
describe 'feature flag' do
|
describe 'feature flag' do
|
||||||
context 'with a feature flag enabled' do
|
context 'with a feature flag enabled' do
|
||||||
before do
|
before do
|
||||||
Flipper.enable(:procedure_routage_api, procedure)
|
Flipper.enable(:dossier_pdf_vide, procedure)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should enable feature' do
|
it 'should enable feature' do
|
||||||
expect(subject.feature_enabled?(:procedure_routage_api)).to be true
|
expect(subject.feature_enabled?(:dossier_pdf_vide)).to be true
|
||||||
|
expect(Flipper.feature(:dossier_pdf_vide).enabled_gate_names).to include(:actor)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with feature flag is fully enabled' do
|
||||||
|
before do
|
||||||
|
Flipper.enable(:dossier_pdf_vide)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not clone feature for actor' do
|
||||||
|
expect(subject.feature_enabled?(:dossier_pdf_vide)).to be true
|
||||||
|
expect(Flipper.feature(:dossier_pdf_vide).enabled_gate_names).not_to include(:actor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a feature flag disabled' do
|
context 'with a feature flag disabled' do
|
||||||
before do
|
before do
|
||||||
Flipper.disable(:procedure_routage_api, procedure)
|
Flipper.disable(:dossier_pdf_vide, procedure)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should not enable feature' do
|
it 'should not enable feature' do
|
||||||
expect(subject.feature_enabled?(:procedure_routage_api)).to be false
|
expect(subject.feature_enabled?(:dossier_pdf_vide)).to be false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -121,10 +121,6 @@ RSpec.configure do |config|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each, type: Proc.new { |type| type != :system }) do
|
|
||||||
Flipper.instance = Flipper.new(Flipper::Adapters::Memory.new)
|
|
||||||
end
|
|
||||||
|
|
||||||
config.include ActiveSupport::Testing::TimeHelpers
|
config.include ActiveSupport::Testing::TimeHelpers
|
||||||
config.include Shoulda::Matchers::ActiveRecord, type: :model
|
config.include Shoulda::Matchers::ActiveRecord, type: :model
|
||||||
config.include Shoulda::Matchers::ActiveModel, type: :model
|
config.include Shoulda::Matchers::ActiveModel, type: :model
|
||||||
|
|
Loading…
Add table
Reference in a new issue