flipper 0.21.0 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -0
- data/.github/workflows/ci.yml +23 -18
- data/.github/workflows/examples.yml +67 -0
- data/.rspec +1 -0
- data/Changelog.md +87 -2
- data/Dockerfile +1 -1
- data/Gemfile +4 -3
- data/README.md +16 -67
- data/docker-compose.yml +37 -34
- data/docs/README.md +1 -0
- data/docs/images/banner.jpg +0 -0
- data/examples/api/basic.ru +19 -0
- data/examples/api/custom_memoized.ru +37 -0
- data/examples/api/memoized.ru +43 -0
- data/examples/instrumentation_last_accessed_at.rb +37 -0
- data/lib/flipper/actor.rb +4 -0
- data/lib/flipper/adapters/dual_write.rb +9 -15
- data/lib/flipper/adapters/failover.rb +83 -0
- data/lib/flipper/adapters/failsafe.rb +76 -0
- data/lib/flipper/adapters/http/client.rb +11 -1
- data/lib/flipper/adapters/http/error.rb +19 -1
- data/lib/flipper/adapters/memoizable.rb +8 -16
- data/lib/flipper/adapters/pstore.rb +2 -5
- data/lib/flipper/adapters/sync/interval_synchronizer.rb +1 -6
- data/lib/flipper/adapters/sync/synchronizer.rb +2 -1
- data/lib/flipper/adapters/sync.rb +9 -15
- data/lib/flipper/dsl.rb +4 -2
- data/lib/flipper/errors.rb +0 -17
- data/lib/flipper/instrumenters/memory.rb +6 -2
- data/lib/flipper/middleware/memoizer.rb +3 -13
- data/lib/flipper/railtie.rb +21 -12
- data/lib/flipper/types/actor.rb +8 -2
- data/lib/flipper/types/group.rb +8 -1
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/actor_spec.rb +10 -2
- data/spec/flipper/adapter_spec.rb +0 -2
- data/spec/flipper/adapters/dual_write_spec.rb +0 -2
- data/spec/flipper/adapters/failover_spec.rb +129 -0
- data/spec/flipper/adapters/failsafe_spec.rb +58 -0
- data/spec/flipper/adapters/http_spec.rb +39 -3
- data/spec/flipper/adapters/instrumented_spec.rb +0 -2
- data/spec/flipper/adapters/memoizable_spec.rb +0 -2
- data/spec/flipper/adapters/memory_spec.rb +0 -3
- data/spec/flipper/adapters/operation_logger_spec.rb +0 -2
- data/spec/flipper/adapters/pstore_spec.rb +0 -2
- data/spec/flipper/adapters/read_only_spec.rb +0 -1
- data/spec/flipper/adapters/sync/feature_synchronizer_spec.rb +0 -1
- data/spec/flipper/adapters/sync/interval_synchronizer_spec.rb +4 -5
- data/spec/flipper/adapters/sync/synchronizer_spec.rb +0 -1
- data/spec/flipper/adapters/sync_spec.rb +0 -2
- data/spec/flipper/configuration_spec.rb +0 -1
- data/spec/flipper/dsl_spec.rb +13 -4
- data/spec/flipper/feature_check_context_spec.rb +0 -2
- data/spec/flipper/feature_spec.rb +0 -1
- data/spec/flipper/gate_spec.rb +0 -2
- data/spec/flipper/gate_values_spec.rb +0 -1
- data/spec/flipper/gates/actor_spec.rb +0 -2
- data/spec/flipper/gates/boolean_spec.rb +0 -2
- data/spec/flipper/gates/group_spec.rb +0 -2
- data/spec/flipper/gates/percentage_of_actors_spec.rb +0 -2
- data/spec/flipper/gates/percentage_of_time_spec.rb +0 -2
- data/spec/flipper/identifier_spec.rb +0 -1
- data/spec/flipper/instrumentation/log_subscriber_spec.rb +0 -1
- data/spec/flipper/instrumentation/statsd_subscriber_spec.rb +0 -1
- data/spec/flipper/instrumenters/memory_spec.rb +18 -1
- data/spec/flipper/instrumenters/noop_spec.rb +14 -8
- data/spec/flipper/middleware/memoizer_spec.rb +0 -23
- data/spec/flipper/middleware/setup_env_spec.rb +0 -2
- data/spec/flipper/railtie_spec.rb +37 -33
- data/spec/flipper/registry_spec.rb +0 -1
- data/spec/flipper/typecast_spec.rb +0 -1
- data/spec/flipper/types/actor_spec.rb +0 -1
- data/spec/flipper/types/boolean_spec.rb +0 -1
- data/spec/flipper/types/group_spec.rb +0 -1
- data/spec/flipper/types/percentage_of_actors_spec.rb +0 -1
- data/spec/flipper/types/percentage_of_time_spec.rb +0 -1
- data/spec/flipper/types/percentage_spec.rb +0 -1
- data/spec/flipper_integration_spec.rb +0 -1
- data/spec/flipper_spec.rb +0 -1
- data/spec/{helper.rb → spec_helper.rb} +4 -2
- data/spec/support/spec_helpers.rb +2 -6
- metadata +18 -13
- data/docs/Adapters.md +0 -124
- data/docs/Caveats.md +0 -4
- data/docs/Gates.md +0 -167
- data/docs/Instrumentation.md +0 -27
- data/docs/Optimization.md +0 -137
- data/docs/api/README.md +0 -884
- data/docs/http/README.md +0 -36
- data/docs/read-only/README.md +0 -24
@@ -1,63 +1,60 @@
|
|
1
|
-
require 'helper'
|
2
1
|
require 'rails'
|
3
2
|
require 'flipper/railtie'
|
4
3
|
|
5
4
|
RSpec.describe Flipper::Railtie do
|
6
5
|
let(:application) do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
)
|
11
|
-
app.config.eager_load = false
|
12
|
-
app.config.logger = ActiveSupport::Logger.new($stdout)
|
13
|
-
app.run_load_hooks!
|
6
|
+
Class.new(Rails::Application).create(railties: [Flipper::Railtie]) do
|
7
|
+
config.eager_load = false
|
8
|
+
end
|
14
9
|
end
|
15
10
|
|
16
11
|
before do
|
17
|
-
|
12
|
+
ActiveSupport::Dependencies.autoload_paths = ActiveSupport::Dependencies.autoload_paths.dup
|
13
|
+
ActiveSupport::Dependencies.autoload_once_paths = ActiveSupport::Dependencies.autoload_once_paths.dup
|
18
14
|
end
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
16
|
+
let(:config) { application.config.flipper }
|
17
|
+
|
18
|
+
subject { application.initialize! }
|
24
19
|
|
25
20
|
describe 'initializers' do
|
26
21
|
it 'sets defaults' do
|
27
|
-
|
28
|
-
expect(
|
29
|
-
expect(
|
22
|
+
subject # initialize
|
23
|
+
expect(config.env_key).to eq("flipper")
|
24
|
+
expect(config.memoize).to be(true)
|
25
|
+
expect(config.preload).to be(true)
|
30
26
|
end
|
31
27
|
|
32
28
|
it "configures instrumentor on default instance" do
|
33
|
-
subject
|
34
|
-
|
29
|
+
subject # initialize
|
35
30
|
expect(Flipper.instance.instrumenter).to eq(ActiveSupport::Notifications)
|
36
31
|
end
|
37
32
|
|
38
33
|
it 'uses Memoizer middleware if config.memoize = true' do
|
39
|
-
|
34
|
+
initializer { config.memoize = true }
|
35
|
+
expect(subject.middleware).to include(Flipper::Middleware::Memoizer)
|
40
36
|
end
|
41
37
|
|
42
38
|
it 'does not use Memoizer middleware if config.memoize = false' do
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
expect(subject.middleware.last).not_to eq(Flipper::Middleware::Memoizer)
|
39
|
+
initializer { config.memoize = false }
|
40
|
+
expect(subject.middleware).not_to include(Flipper::Middleware::Memoizer)
|
47
41
|
end
|
48
42
|
|
49
43
|
it 'passes config to memoizer' do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
expect(Flipper::Middleware::Memoizer).to receive(:new).with(application.routes,
|
57
|
-
env_key: 'my_flipper', preload: [:stats, :search], if: nil
|
58
|
-
)
|
44
|
+
initializer do
|
45
|
+
config.update(
|
46
|
+
env_key: 'my_flipper',
|
47
|
+
preload: [:stats, :search]
|
48
|
+
)
|
49
|
+
end
|
59
50
|
|
60
|
-
subject
|
51
|
+
expect(subject.middleware).to include(Flipper::Middleware::Memoizer)
|
52
|
+
middleware = subject.middleware.detect { |m| m.klass == Flipper::Middleware::Memoizer }
|
53
|
+
expect(middleware.args[0]).to eq({
|
54
|
+
env_key: config.env_key,
|
55
|
+
preload: config.preload,
|
56
|
+
if: nil
|
57
|
+
})
|
61
58
|
end
|
62
59
|
|
63
60
|
it "defines #flipper_id on AR::Base" do
|
@@ -66,4 +63,11 @@ RSpec.describe Flipper::Railtie do
|
|
66
63
|
expect(ActiveRecord::Base.ancestors).to include(Flipper::Identifier)
|
67
64
|
end
|
68
65
|
end
|
66
|
+
|
67
|
+
# Add app initializer in the same order as config/initializers/*
|
68
|
+
def initializer(&block)
|
69
|
+
application.initializer 'spec', before: :load_config_initializers do
|
70
|
+
block.call
|
71
|
+
end
|
72
|
+
end
|
69
73
|
end
|
data/spec/flipper_spec.rb
CHANGED
@@ -9,18 +9,20 @@ require 'bundler'
|
|
9
9
|
|
10
10
|
Bundler.setup(:default)
|
11
11
|
|
12
|
-
require '
|
12
|
+
require 'debug'
|
13
13
|
require 'webmock/rspec'
|
14
14
|
WebMock.disable_net_connect!(allow_localhost: true)
|
15
15
|
|
16
16
|
require 'flipper'
|
17
|
-
require 'flipper/ui'
|
18
17
|
require 'flipper/api'
|
18
|
+
require 'flipper/spec/shared_adapter_specs'
|
19
|
+
require 'flipper/ui'
|
19
20
|
|
20
21
|
Dir[FlipperRoot.join('spec/support/**/*.rb')].sort.each { |f| require f }
|
21
22
|
|
22
23
|
RSpec.configure do |config|
|
23
24
|
config.before(:example) do
|
25
|
+
Flipper::Cloud::Registry.default.clear if defined?(Flipper::Cloud)
|
24
26
|
Flipper.unregister_groups
|
25
27
|
Flipper.configuration = nil
|
26
28
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'ice_age'
|
2
2
|
require 'json'
|
3
3
|
require 'rack/test'
|
4
4
|
|
@@ -31,7 +31,7 @@ module SpecHelpers
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def api_error_code_reference_url
|
34
|
-
'https://
|
34
|
+
'https://flippercloud.io/docs/api#error-code-reference'
|
35
35
|
end
|
36
36
|
|
37
37
|
def api_not_found_response
|
@@ -58,10 +58,6 @@ module SpecHelpers
|
|
58
58
|
}
|
59
59
|
end
|
60
60
|
|
61
|
-
def with_modified_env(options, &block)
|
62
|
-
ClimateControl.modify(options, &block)
|
63
|
-
end
|
64
|
-
|
65
61
|
def silence
|
66
62
|
# Store the original stderr and stdout in order to restore them later
|
67
63
|
original_stderr = $stderr
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.25.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -19,6 +19,8 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- ".codeclimate.yml"
|
21
21
|
- ".github/workflows/ci.yml"
|
22
|
+
- ".github/workflows/examples.yml"
|
23
|
+
- ".rspec"
|
22
24
|
- CODE_OF_CONDUCT.md
|
23
25
|
- Changelog.md
|
24
26
|
- Dockerfile
|
@@ -27,16 +29,12 @@ files:
|
|
27
29
|
- README.md
|
28
30
|
- Rakefile
|
29
31
|
- docker-compose.yml
|
30
|
-
- docs/Adapters.md
|
31
|
-
- docs/Caveats.md
|
32
32
|
- docs/DockerCompose.md
|
33
|
-
- docs/
|
34
|
-
- docs/Instrumentation.md
|
35
|
-
- docs/Optimization.md
|
36
|
-
- docs/api/README.md
|
37
|
-
- docs/http/README.md
|
33
|
+
- docs/README.md
|
38
34
|
- docs/images/banner.jpg
|
39
|
-
-
|
35
|
+
- examples/api/basic.ru
|
36
|
+
- examples/api/custom_memoized.ru
|
37
|
+
- examples/api/memoized.ru
|
40
38
|
- examples/basic.rb
|
41
39
|
- examples/configuring_default.rb
|
42
40
|
- examples/dsl.rb
|
@@ -47,6 +45,7 @@ files:
|
|
47
45
|
- examples/importing.rb
|
48
46
|
- examples/individual_actor.rb
|
49
47
|
- examples/instrumentation.rb
|
48
|
+
- examples/instrumentation_last_accessed_at.rb
|
50
49
|
- examples/memoizing.rb
|
51
50
|
- examples/percentage_of_actors.rb
|
52
51
|
- examples/percentage_of_actors_enabled_check.rb
|
@@ -57,6 +56,8 @@ files:
|
|
57
56
|
- lib/flipper/actor.rb
|
58
57
|
- lib/flipper/adapter.rb
|
59
58
|
- lib/flipper/adapters/dual_write.rb
|
59
|
+
- lib/flipper/adapters/failover.rb
|
60
|
+
- lib/flipper/adapters/failsafe.rb
|
60
61
|
- lib/flipper/adapters/http.rb
|
61
62
|
- lib/flipper/adapters/http/client.rb
|
62
63
|
- lib/flipper/adapters/http/error.rb
|
@@ -109,6 +110,8 @@ files:
|
|
109
110
|
- spec/flipper/actor_spec.rb
|
110
111
|
- spec/flipper/adapter_spec.rb
|
111
112
|
- spec/flipper/adapters/dual_write_spec.rb
|
113
|
+
- spec/flipper/adapters/failover_spec.rb
|
114
|
+
- spec/flipper/adapters/failsafe_spec.rb
|
112
115
|
- spec/flipper/adapters/http_spec.rb
|
113
116
|
- spec/flipper/adapters/instrumented_spec.rb
|
114
117
|
- spec/flipper/adapters/memoizable_spec.rb
|
@@ -149,7 +152,7 @@ files:
|
|
149
152
|
- spec/flipper/types/percentage_spec.rb
|
150
153
|
- spec/flipper_integration_spec.rb
|
151
154
|
- spec/flipper_spec.rb
|
152
|
-
- spec/
|
155
|
+
- spec/spec_helper.rb
|
153
156
|
- spec/support/descriptions.yml
|
154
157
|
- spec/support/fake_udp_socket.rb
|
155
158
|
- spec/support/spec_helpers.rb
|
@@ -177,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
180
|
- !ruby/object:Gem::Version
|
178
181
|
version: '0'
|
179
182
|
requirements: []
|
180
|
-
rubygems_version: 3.
|
183
|
+
rubygems_version: 3.1.2
|
181
184
|
signing_key:
|
182
185
|
specification_version: 4
|
183
186
|
summary: Feature flipper for ANYTHING
|
@@ -186,6 +189,8 @@ test_files:
|
|
186
189
|
- spec/flipper/actor_spec.rb
|
187
190
|
- spec/flipper/adapter_spec.rb
|
188
191
|
- spec/flipper/adapters/dual_write_spec.rb
|
192
|
+
- spec/flipper/adapters/failover_spec.rb
|
193
|
+
- spec/flipper/adapters/failsafe_spec.rb
|
189
194
|
- spec/flipper/adapters/http_spec.rb
|
190
195
|
- spec/flipper/adapters/instrumented_spec.rb
|
191
196
|
- spec/flipper/adapters/memoizable_spec.rb
|
@@ -226,7 +231,7 @@ test_files:
|
|
226
231
|
- spec/flipper/types/percentage_spec.rb
|
227
232
|
- spec/flipper_integration_spec.rb
|
228
233
|
- spec/flipper_spec.rb
|
229
|
-
- spec/
|
234
|
+
- spec/spec_helper.rb
|
230
235
|
- spec/support/descriptions.yml
|
231
236
|
- spec/support/fake_udp_socket.rb
|
232
237
|
- spec/support/spec_helpers.rb
|
data/docs/Adapters.md
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
# Adapters
|
2
|
-
|
3
|
-
I plan on supporting the adapters in the flipper repo. Other adapters are welcome, so please let me know if you create one.
|
4
|
-
|
5
|
-
## Officially Supported
|
6
|
-
|
7
|
-
* [ActiveRecord adapter](https://github.com/jnunemaker/flipper/blob/master/docs/active_record) - Rails 5 and 6.
|
8
|
-
* [Sequel adapter](https://github.com/jnunemaker/flipper/blob/master/docs/sequel)
|
9
|
-
* [Redis adapter](https://github.com/jnunemaker/flipper/blob/master/docs/redis)
|
10
|
-
* [Mongo adapter](https://github.com/jnunemaker/flipper/blob/master/docs/mongo)
|
11
|
-
* [PStore adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/pstore.rb) – great for when a local file is enough
|
12
|
-
* [Http adapter](https://github.com/jnunemaker/flipper/blob/master/docs/http) - great for using with `Flipper::Api`
|
13
|
-
* [Moneta adapter](https://github.com/jnunemaker/flipper/blob/master/docs/moneta) - great for a variety of data stores
|
14
|
-
* [ActiveSupportCacheStore adapter](https://github.com/jnunemaker/flipper/blob/master/docs/active_support_cache_store) - great for Rails caching
|
15
|
-
* [Memory adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/memory.rb) – great for tests
|
16
|
-
* [Read-only adapter](https://github.com/jnunemaker/flipper/blob/master/docs/read-only) - great for preventing writes from production console
|
17
|
-
* [Rollout adapter](rollout/README.md) - great for switching from rollout to flipper
|
18
|
-
|
19
|
-
## Community Supported
|
20
|
-
|
21
|
-
* [Active Record 3 adapter](https://github.com/blueboxjesse/flipper-activerecord)
|
22
|
-
* [Consul adapter](https://github.com/gdavison/flipper-consul)
|
23
|
-
|
24
|
-
## Roll Your Own
|
25
|
-
|
26
|
-
The basic API for an adapter is this:
|
27
|
-
|
28
|
-
* `features` - Get the set of known features.
|
29
|
-
* `add(feature)` - Add a feature to the set of known features.
|
30
|
-
* `remove(feature)` - Remove a feature from the set of known features.
|
31
|
-
* `clear(feature)` - Clear all gate values for a feature.
|
32
|
-
* `get(feature)` - Get all gate values for a feature.
|
33
|
-
* `enable(feature, gate, thing)` - Enable a gate for a thing.
|
34
|
-
* `disable(feature, gate, thing)` - Disable a gate for a thing.
|
35
|
-
* `get_multi(features)` - Get all gate values for several features at once. Implementation is optional. If none provided, default implementation performs N+1 `get` calls where N is the number of elements in the features parameter.
|
36
|
-
* `get_all` - Get all gate values for all features at once. Implementation is optional. If none provided, default implementation performs two calls, one to `features` to get the names of all features and one to `get_multi` with the feature names from the first call.
|
37
|
-
|
38
|
-
If you would like to make your own adapter, there are shared adapter specs (RSpec) and tests (MiniTest) that you can use to verify that you have everything working correctly.
|
39
|
-
|
40
|
-
### RSpec
|
41
|
-
For example, here is what the in-memory adapter spec looks like:
|
42
|
-
|
43
|
-
`spec/flipper/adapters/memory_spec.rb`
|
44
|
-
|
45
|
-
```ruby
|
46
|
-
require 'helper'
|
47
|
-
|
48
|
-
# The shared specs are included with the flipper gem so you can use them in
|
49
|
-
# separate adapter specific gems.
|
50
|
-
require 'flipper/spec/shared_adapter_specs'
|
51
|
-
|
52
|
-
describe Flipper::Adapters::Memory do
|
53
|
-
|
54
|
-
# an instance of the new adapter you are trying to create
|
55
|
-
subject { described_class.new }
|
56
|
-
|
57
|
-
# include the shared specs that the subject must pass
|
58
|
-
it_should_behave_like 'a flipper adapter'
|
59
|
-
end
|
60
|
-
```
|
61
|
-
|
62
|
-
### MiniTest
|
63
|
-
|
64
|
-
Here is what an in-memory adapter MiniTest looks like:
|
65
|
-
|
66
|
-
`test/adapters/memory_test.rb`
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
require 'test_helper'
|
70
|
-
|
71
|
-
class MemoryTest < MiniTest::Test
|
72
|
-
prepend SharedAdapterTests
|
73
|
-
|
74
|
-
def setup
|
75
|
-
# Any code here will run before each test
|
76
|
-
@adapter = Flipper::Adapters::Memory.new
|
77
|
-
end
|
78
|
-
|
79
|
-
def teardown
|
80
|
-
# Any code here will run after each test
|
81
|
-
end
|
82
|
-
end
|
83
|
-
```
|
84
|
-
1. Create a file under `test/adapters` that inherits from MiniTest::Test.
|
85
|
-
|
86
|
-
2. `prepend SharedAdapterTests`.
|
87
|
-
|
88
|
-
3. Initialize an instance variable `@adapter` referencing an instance of the adapter.
|
89
|
-
|
90
|
-
4. Add any code to run before each test in a `setup` method and any code to run after each test in a `teardown` method.
|
91
|
-
|
92
|
-
A good place to start when creating your own adapter is to copy one of the adapters mentioned above and replace the client specific code with whatever client you are attempting to adapt.
|
93
|
-
|
94
|
-
I would also recommend setting `fail_fast = true` in your RSpec configuration as that will just give you one failure at a time to work through. It is also handy to have the shared adapter spec file open.
|
95
|
-
|
96
|
-
## Swapping Adapters
|
97
|
-
|
98
|
-
If you find yourself using one adapter and would like to swap to another, you can do that! Flipper adapters support importing another adapter's data. This will wipe the adapter you are wanting to swap to, if it isn't already clean, so please be careful.
|
99
|
-
|
100
|
-
```ruby
|
101
|
-
# Say you are using redis...
|
102
|
-
redis_adapter = Flipper::Adapters::Redis.new(Redis.new)
|
103
|
-
redis_flipper = Flipper.new(redis_adapter)
|
104
|
-
|
105
|
-
# And redis has some stuff enabled...
|
106
|
-
redis_flipper.enable(:search)
|
107
|
-
redis_flipper.enable_percentage_of_time(:verbose_logging, 5)
|
108
|
-
redis_flipper.enable_percentage_of_actors(:new_feature, 5)
|
109
|
-
redis_flipper.enable_actor(:issues, Flipper::Actor.new('1'))
|
110
|
-
redis_flipper.enable_actor(:issues, Flipper::Actor.new('2'))
|
111
|
-
redis_flipper.enable_group(:request_tracing, :staff)
|
112
|
-
|
113
|
-
# And you would like to switch to active record...
|
114
|
-
ar_adapter = Flipper::Adapters::ActiveRecord.new
|
115
|
-
ar_flipper = Flipper.new(ar_adapter)
|
116
|
-
|
117
|
-
# NOTE: This wipes active record clean and copies features/gates from redis into active record.
|
118
|
-
ar_flipper.import(redis_flipper)
|
119
|
-
|
120
|
-
# active record is now identical to redis.
|
121
|
-
ar_flipper.features.each do |feature|
|
122
|
-
pp feature: feature.key, values: feature.gate_values
|
123
|
-
end
|
124
|
-
```
|
data/docs/Caveats.md
DELETED
@@ -1,4 +0,0 @@
|
|
1
|
-
# Caveats
|
2
|
-
|
3
|
-
1. The [individual actor gate](https://github.com/jnunemaker/flipper/blob/master/docs/Gates.md#2-individual-actor) is typically not designed for hundreds or thousands of actors to be enabled. This is an explicit choice to make it easier to batch load data from the adapters instead of performing individual checks for actors over and over. If you need to enable something for more than 100 individual actors, I would recommend using a [group](https://github.com/jnunemaker/flipper/blob/master/docs/Gates.md#5-group).
|
4
|
-
2. The `disable` method exists only to clear something that is enabled. If the thing you are disabling is not enabled, the disable is pointless. This means that if you enable one group an actor is in and disable another group, the feature will be enabled for the actor. ([related issue](https://github.com/jnunemaker/flipper/issues/71))
|
data/docs/Gates.md
DELETED
@@ -1,167 +0,0 @@
|
|
1
|
-
# Gates
|
2
|
-
|
3
|
-
Out of the box several types of enabling are supported. They are checked in this order:
|
4
|
-
|
5
|
-
## 1. Boolean
|
6
|
-
|
7
|
-
All on or all off. Think top level things like `:stats`, `:search`, `:logging`, etc. Also, an easy way to release a new feature as once a feature is boolean enabled it is on for every situation.
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
Flipper.enable :stats # turn on
|
11
|
-
Flipper.disable :stats # turn off
|
12
|
-
Flipper.enabled? :stats # check
|
13
|
-
```
|
14
|
-
|
15
|
-
## 2. Individual Actor
|
16
|
-
|
17
|
-
Turn feature on for individual thing. Think enable feature for someone to test or for a buddy.
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
Flipper.enable_actor :stats, user
|
21
|
-
Flipper.enabled? :stats, user # true
|
22
|
-
|
23
|
-
Flipper.disable_actor :stats, user
|
24
|
-
Flipper.enabled? :stats, user # false
|
25
|
-
|
26
|
-
# you can enable anything, does not need to be user or person
|
27
|
-
Flipper.enable_actor :search, organization
|
28
|
-
Flipper.enabled? :search, organization
|
29
|
-
|
30
|
-
# you can also save a reference to a specific feature
|
31
|
-
feature = Flipper[:search]
|
32
|
-
|
33
|
-
feature.enable_actor user
|
34
|
-
feature.enabled? user # true
|
35
|
-
feature.disable_actor user
|
36
|
-
```
|
37
|
-
|
38
|
-
The only requirement for an individual actor is that it must have a unique `flipper_id`. Include the `Flipper::Identifier` module for a default implementation which combines the class name and `id` (e.g. `User;6`).
|
39
|
-
|
40
|
-
```ruby
|
41
|
-
class User < Struct.new(:id)
|
42
|
-
include Flipper::Identifier
|
43
|
-
end
|
44
|
-
|
45
|
-
User.new(5).flipper_id # => "User;5"
|
46
|
-
```
|
47
|
-
|
48
|
-
You can also define your own implementation:
|
49
|
-
|
50
|
-
```
|
51
|
-
class Organization < Struct.new(:uuid)
|
52
|
-
def flipper_id
|
53
|
-
uuid
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
Organization.new("DEB3D850-39FB-444B-A1E9-404A990FDBE0").flipper_id
|
58
|
-
# => "DEB3D850-39FB-444B-A1E9-404A990FDBE0"
|
59
|
-
```
|
60
|
-
|
61
|
-
Just make sure each type of object has a unique `flipper_id`.
|
62
|
-
|
63
|
-
## 3. Percentage of Actors
|
64
|
-
|
65
|
-
Turn this on for a percentage of actors (think user, member, account, group, whatever). Consistently on or off for this user as long as percentage increases. Think slow rollout of a new feature to a percentage of things.
|
66
|
-
|
67
|
-
```ruby
|
68
|
-
# turn stats on for 10 percent of users in the system
|
69
|
-
Flipper.enable :stats, Flipper.actors(10)
|
70
|
-
# or
|
71
|
-
Flipper.enable_percentage_of_actors :stats, 10
|
72
|
-
|
73
|
-
# checks if actor's flipper_id is in the enabled percentage by hashing
|
74
|
-
# user.flipper_id.to_s to ensure enabled distribution is smooth
|
75
|
-
Flipper.enabled? :stats, user
|
76
|
-
|
77
|
-
Flipper.disable_percentage_of_actors :search # sets to 0
|
78
|
-
# or
|
79
|
-
Flipper.disable :stats, Flipper.actors(0)
|
80
|
-
|
81
|
-
# you can also save a reference to a specific feature
|
82
|
-
feature = Flipper[:search]
|
83
|
-
feature.enable_percentage_of_actors 10
|
84
|
-
feature.enabled? user
|
85
|
-
feature.disable_percentage_of_actors # sets to 0
|
86
|
-
```
|
87
|
-
|
88
|
-
## 4. Percentage of Time
|
89
|
-
|
90
|
-
Turn this on for a percentage of time. Think load testing new features behind the scenes and such.
|
91
|
-
|
92
|
-
```ruby
|
93
|
-
# Register a feature called logging and turn it on for 5 percent of the time.
|
94
|
-
# This could be on during one request and off the next
|
95
|
-
# could even be on first time in request and off second time
|
96
|
-
Flipper.enable_percentage_of_time :logging, 5
|
97
|
-
|
98
|
-
Flipper.enabled? :logging # this will return true 5% of the time.
|
99
|
-
|
100
|
-
Flipper.disable_percentage_of_time :logging # sets to 0
|
101
|
-
|
102
|
-
# you can also save a reference to a specific feature
|
103
|
-
feature = Flipper[:search]
|
104
|
-
feature.enable_percentage_of_time, 5
|
105
|
-
feature.enabled?
|
106
|
-
feature.disable_percentage_of_time
|
107
|
-
```
|
108
|
-
|
109
|
-
Timeness is not a good idea for enabling new features in the UI. Most of the time you want a feature on or off for a user, but there are definitely times when I have found percentage of time to be very useful.
|
110
|
-
|
111
|
-
## 5. Group
|
112
|
-
|
113
|
-
Turn on feature based on the return value of block. Super flexible way to turn on a feature for multiple things (users, people, accounts, etc.) as long as the thing returns true when passed to the block.
|
114
|
-
|
115
|
-
```ruby
|
116
|
-
# this registers a group
|
117
|
-
Flipper.register(:admins) do |actor|
|
118
|
-
actor.respond_to?(:admin?) && actor.admin?
|
119
|
-
end
|
120
|
-
|
121
|
-
Flipper.enable_group :stats, :admins # This registers a stats feature and turns it on for admins (which is anything that returns true from the registered block).
|
122
|
-
Flipper.disable_group :stats, :admins # turn off the stats feature for admins
|
123
|
-
|
124
|
-
person = Person.find(params[:id])
|
125
|
-
Flipper.enabled? :stats, person # check if enabled, returns true if person.admin? is true
|
126
|
-
|
127
|
-
|
128
|
-
# you can also use shortcut methods. This also registers a stats feature and turns it on for admins.
|
129
|
-
feature = Flipper[:search]
|
130
|
-
feature.enable_group :admins
|
131
|
-
feature.enabled? person
|
132
|
-
feature.disable_group :admins
|
133
|
-
```
|
134
|
-
|
135
|
-
Here's a quick explanation of the above code block:
|
136
|
-
|
137
|
-
```ruby
|
138
|
-
Flipper.register(:admins) do |actor|
|
139
|
-
actor.respond_to?(:admin?) && actor.admin?
|
140
|
-
end
|
141
|
-
```
|
142
|
-
- The above first registers a group called `admins` which essentially saves a [Proc](http://www.eriktrautman.com/posts/ruby-explained-blocks-procs-and-lambdas-aka-closures) to be called later. The `actor` is an instance of the `Flipper::Types::Actor` that wraps the thing being checked against and `actor.thing` is the original object being checked.
|
143
|
-
|
144
|
-
```ruby
|
145
|
-
Flipper.enable_group :stats, :admins
|
146
|
-
```
|
147
|
-
|
148
|
-
- The above enables the stats feature to any object that returns true from the `:admins` proc.
|
149
|
-
|
150
|
-
```ruby
|
151
|
-
person = Person.find(params[:id])
|
152
|
-
Flipper.enabled? :stats, person # check if person is enabled, returns true if person.admin? is true
|
153
|
-
```
|
154
|
-
|
155
|
-
When the `person` object is passed to the `enabled?` method, it is then passed into the proc. If the proc returns true, the entire statement returns true and so `Flipper[:stats].enabled? person` returns true. Whatever logic follows this conditional check is then executed.
|
156
|
-
|
157
|
-
There is no requirement that the thing yielded to the block be a user model or whatever. It can be anything you want, therefore it is a good idea to check that the thing passed into the group block actually responds to what you are trying to do in the `register` proc.
|
158
|
-
|
159
|
-
In your application code, you can do something like this now:
|
160
|
-
|
161
|
-
```ruby
|
162
|
-
if Flipper.enabled? :stats, some_admin
|
163
|
-
# do thing...
|
164
|
-
else
|
165
|
-
# do not do thing
|
166
|
-
end
|
167
|
-
```
|
data/docs/Instrumentation.md
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# Instrumentation
|
2
|
-
|
3
|
-
Flipper comes with automatic instrumentation. By default these work with ActiveSupport::Notifications, but only require the pieces of ActiveSupport that are needed and only do so if you actually attempt to require the instrumentation files listed below.
|
4
|
-
|
5
|
-
To use the log subscriber:
|
6
|
-
|
7
|
-
```ruby
|
8
|
-
# Gemfile
|
9
|
-
gem "activesupport"
|
10
|
-
|
11
|
-
# config/initializers/flipper.rb (or wherever you want it)
|
12
|
-
require "flipper/instrumentation/log_subscriber"
|
13
|
-
```
|
14
|
-
|
15
|
-
To use the statsd instrumentation:
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
# Gemfile
|
19
|
-
gem "activesupport"
|
20
|
-
gem "statsd-ruby"
|
21
|
-
|
22
|
-
# config/initializers/flipper.rb (or wherever you want it)
|
23
|
-
require "flipper/instrumentation/statsd"
|
24
|
-
Flipper::Instrumentation::StatsdSubscriber.client = Statsd.new # or whatever your statsd instance is
|
25
|
-
```
|
26
|
-
|
27
|
-
You can also do whatever you want with the instrumented events. Check out [this example](https://github.com/jnunemaker/flipper/blob/master/examples/instrumentation.rb) for more.
|