Add Feature Flags support to DEV (#7996)

* Create tables for Flipper gem

* Enable Flipper gem

* Remove concurrent ruby from Gemfile

* Add Flipper UI

* Codeland landing page

* Remove codeland controller and sample page

* Remove oops

* Rename Flipper-UI endpoint

* Wrap Flipper in a FeatureFlag module

* [deploy] Lock node to 12.16 (#8057)

Co-authored-by: Mac Siri <krairit.siri@gmail.com>
This commit is contained in:
Josh Puetz 2020-05-26 15:26:33 -05:00 committed by GitHub
parent 0976132425
commit 1a1b5b544e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 80 additions and 0 deletions

View file

@ -44,6 +44,9 @@ gem "fastly", "~> 2.5" # Client library for the Fastly acceleration system
gem "feedjira", "~> 3.1" # A feed fetching and parsing library
gem "field_test", "~> 0.3" # A/B testing
gem "figaro", "~> 1.2" # Simple, Heroku-friendly Rails app configuration using ENV and a single YAML file
gem "flipper", "~> 0.17.2" # Feature flipping / flags for Ruby
gem "flipper-active_record", "~> 0.17.2" # Store Flipper flags in ActiveRecord
gem "flipper-ui", "~> 0.17.2"
gem "fog-aws", "~> 3.6" # 'fog' gem to support Amazon Web Services
gem "front_matter_parser", "~> 0.2" # Parse a front matter from syntactically correct strings or files
gem "gemoji", "~> 4.0.0.rc2" # Character information and metadata for standard and custom emoji

View file

@ -323,6 +323,15 @@ GEM
thor (>= 0.14.0, < 2)
fix-db-schema-conflicts (3.0.3)
rubocop (>= 0.38.0)
flipper (0.17.2)
flipper-active_record (0.17.2)
activerecord (>= 4.2, < 7)
flipper (~> 0.17.2)
flipper-ui (0.17.2)
erubi (>= 1.0.0, < 2.0.0)
flipper (~> 0.17.2)
rack (>= 1.4, < 3)
rack-protection (>= 1.5.3, < 2.1.0)
fog-aws (3.6.4)
fog-core (~> 2.1)
fog-json (~> 1.1)
@ -891,6 +900,9 @@ DEPENDENCIES
field_test (~> 0.3)
figaro (~> 1.2)
fix-db-schema-conflicts (~> 3.0)
flipper (~> 0.17.2)
flipper-active_record (~> 0.17.2)
flipper-ui (~> 0.17.2)
fog-aws (~> 3.6)
front_matter_parser (~> 0.2)
gemoji (~> 4.0.0.rc2)

View file

@ -0,0 +1,7 @@
module FeatureFlag
extend self # rubocop:disable Style/ModuleFunction
def enabled?(feature_name, *args)
Flipper[feature_name].enabled?(*args)
end
end

View file

@ -462,6 +462,10 @@ class User < ApplicationRecord
RateLimitChecker.new(self)
end
def flipper_id
"User:#{id}"
end
private
def estimate_default_language

View file

@ -0,0 +1,15 @@
Flipper.configure do |config|
config.default do
# pick an adapter, this uses memory, any will do
adapter = Flipper::Adapters::ActiveRecord.new
# pass adapter to handy DSL instance
Flipper.new(adapter)
end
end
Flipper::UI.configure do |config|
# Provide guidance on format for user ids
config.actors.title = "Actor (ex: User:123)"
config.actors.description = "ex: User:123"
end

View file

@ -42,6 +42,7 @@ Rails.application.routes.draw do
authenticate :user, ->(user) { user.has_role?(:tech_admin) } do
mount Blazer::Engine, at: "blazer"
mount Flipper::UI.app(Flipper), at: "feature_flags"
end
resources :articles, only: %i[index show update]

View file

@ -0,0 +1,22 @@
class CreateFlipperTables < ActiveRecord::Migration[5.2]
def self.up
create_table :flipper_features do |t|
t.string :key, null: false
t.timestamps null: false
end
add_index :flipper_features, :key, unique: true
create_table :flipper_gates do |t|
t.string :feature_key, null: false
t.string :key, null: false
t.string :value
t.timestamps null: false
end
add_index :flipper_gates, [:feature_key, :key, :value], unique: true
end
def self.down
drop_table :flipper_gates
drop_table :flipper_features
end
end

View file

@ -506,6 +506,22 @@ ActiveRecord::Schema.define(version: 2020_05_25_125611) do
t.index ["participant_type", "participant_id", "experiment"], name: "index_field_test_memberships_on_participant", unique: true
end
create_table "flipper_features", force: :cascade do |t|
t.datetime "created_at", null: false
t.string "key", null: false
t.datetime "updated_at", null: false
t.index ["key"], name: "index_flipper_features_on_key", unique: true
end
create_table "flipper_gates", force: :cascade do |t|
t.datetime "created_at", null: false
t.string "feature_key", null: false
t.string "key", null: false
t.datetime "updated_at", null: false
t.string "value"
t.index ["feature_key", "key", "value"], name: "index_flipper_gates_on_feature_key_and_key_and_value", unique: true
end
create_table "follows", id: :serial, force: :cascade do |t|
t.boolean "blocked", default: false, null: false
t.datetime "created_at"