flipper 0.16.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.codeclimate.yml +1 -0
- data/.github/FUNDING.yml +1 -0
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/ci.yml +110 -0
- data/.github/workflows/examples.yml +105 -0
- data/.github/workflows/release.yml +54 -0
- data/.rspec +1 -0
- data/CLAUDE.md +87 -0
- data/Changelog.md +2 -215
- data/Dockerfile +1 -1
- data/Gemfile +28 -20
- data/README.md +72 -62
- data/Rakefile +13 -3
- data/benchmark/enabled_ips.rb +10 -0
- data/benchmark/enabled_multiple_actors_ips.rb +20 -0
- data/benchmark/enabled_profile.rb +20 -0
- data/benchmark/instrumentation_ips.rb +21 -0
- data/benchmark/typecast_ips.rb +27 -0
- data/docker-compose.yml +37 -34
- data/docs/DockerCompose.md +0 -1
- data/docs/README.md +1 -0
- data/docs/images/banner.jpg +0 -0
- data/docs/images/flipper_cloud.png +0 -0
- data/examples/api/basic.ru +18 -0
- data/examples/api/custom_memoized.ru +36 -0
- data/examples/api/memoized.ru +42 -0
- data/examples/basic.rb +1 -12
- data/examples/cloud/app.ru +12 -0
- data/examples/cloud/backoff_policy.rb +13 -0
- data/examples/cloud/basic.rb +22 -0
- data/examples/cloud/cloud_setup.rb +20 -0
- data/examples/cloud/forked.rb +36 -0
- data/examples/cloud/import.rb +17 -0
- data/examples/cloud/poll_interval/README.md +111 -0
- data/examples/cloud/poll_interval/client.rb +108 -0
- data/examples/cloud/poll_interval/server.rb +98 -0
- data/examples/cloud/threaded.rb +33 -0
- data/examples/configuring_default.rb +2 -5
- data/examples/dsl.rb +10 -35
- data/examples/enabled_for_actor.rb +10 -15
- data/examples/expressions.rb +237 -0
- data/examples/group.rb +3 -6
- data/examples/group_dynamic_lookup.rb +5 -19
- data/examples/group_with_members.rb +4 -14
- data/examples/importing.rb +1 -1
- data/examples/individual_actor.rb +2 -5
- data/examples/instrumentation.rb +2 -2
- data/examples/instrumentation_last_accessed_at.rb +38 -0
- data/examples/memoizing.rb +35 -0
- data/examples/mirroring.rb +59 -0
- data/examples/percentage_of_actors.rb +6 -16
- data/examples/percentage_of_actors_enabled_check.rb +7 -10
- data/examples/percentage_of_actors_group.rb +5 -18
- data/examples/percentage_of_time.rb +3 -6
- data/examples/strict.rb +18 -0
- data/exe/flipper +5 -0
- data/flipper-cloud.gemspec +19 -0
- data/flipper.gemspec +10 -7
- data/lib/flipper/actor.rb +10 -3
- data/lib/flipper/adapter.rb +50 -8
- data/lib/flipper/adapter_builder.rb +44 -0
- data/lib/flipper/adapters/actor_limit.rb +54 -0
- data/lib/flipper/adapters/cache_base.rb +161 -0
- data/lib/flipper/adapters/dual_write.rb +63 -0
- data/lib/flipper/adapters/failover.rb +85 -0
- data/lib/flipper/adapters/failsafe.rb +72 -0
- data/lib/flipper/adapters/http/client.rb +64 -7
- data/lib/flipper/adapters/http/error.rb +19 -1
- data/lib/flipper/adapters/http.rb +97 -43
- data/lib/flipper/adapters/instrumented.rb +47 -26
- data/lib/flipper/adapters/memoizable.rb +44 -40
- data/lib/flipper/adapters/memory.rb +75 -111
- data/lib/flipper/adapters/operation_logger.rb +22 -78
- data/lib/flipper/adapters/poll/poller.rb +2 -0
- data/lib/flipper/adapters/poll.rb +52 -0
- data/lib/flipper/adapters/pstore.rb +27 -17
- data/lib/flipper/adapters/read_only.rb +8 -41
- data/lib/flipper/adapters/strict.rb +45 -0
- data/lib/flipper/adapters/sync/feature_synchronizer.rb +14 -1
- data/lib/flipper/adapters/sync/interval_synchronizer.rb +2 -7
- data/lib/flipper/adapters/sync/synchronizer.rb +13 -6
- data/lib/flipper/adapters/sync.rb +23 -29
- data/lib/flipper/adapters/wrapper.rb +54 -0
- data/lib/flipper/cli.rb +314 -0
- data/lib/flipper/cloud/configuration.rb +271 -0
- data/lib/flipper/cloud/dsl.rb +27 -0
- data/lib/flipper/cloud/message_verifier.rb +95 -0
- data/lib/flipper/cloud/middleware.rb +63 -0
- data/lib/flipper/cloud/migrate.rb +71 -0
- data/lib/flipper/cloud/routes.rb +14 -0
- data/lib/flipper/cloud/telemetry/backoff_policy.rb +96 -0
- data/lib/flipper/cloud/telemetry/instrumenter.rb +22 -0
- data/lib/flipper/cloud/telemetry/metric.rb +39 -0
- data/lib/flipper/cloud/telemetry/metric_storage.rb +30 -0
- data/lib/flipper/cloud/telemetry/submitter.rb +100 -0
- data/lib/flipper/cloud/telemetry.rb +191 -0
- data/lib/flipper/cloud.rb +54 -0
- data/lib/flipper/configuration.rb +54 -7
- data/lib/flipper/dsl.rb +58 -47
- data/lib/flipper/engine.rb +102 -0
- data/lib/flipper/errors.rb +3 -21
- data/lib/flipper/export.rb +24 -0
- data/lib/flipper/exporter.rb +17 -0
- data/lib/flipper/exporters/json/export.rb +32 -0
- data/lib/flipper/exporters/json/v1.rb +33 -0
- data/lib/flipper/expression/builder.rb +73 -0
- data/lib/flipper/expression/constant.rb +25 -0
- data/lib/flipper/expression.rb +71 -0
- data/lib/flipper/expressions/all.rb +9 -0
- data/lib/flipper/expressions/any.rb +9 -0
- data/lib/flipper/expressions/boolean.rb +9 -0
- data/lib/flipper/expressions/comparable.rb +13 -0
- data/lib/flipper/expressions/equal.rb +9 -0
- data/lib/flipper/expressions/feature_enabled.rb +34 -0
- data/lib/flipper/expressions/greater_than.rb +9 -0
- data/lib/flipper/expressions/greater_than_or_equal_to.rb +9 -0
- data/lib/flipper/expressions/less_than.rb +9 -0
- data/lib/flipper/expressions/less_than_or_equal_to.rb +9 -0
- data/lib/flipper/expressions/not_equal.rb +9 -0
- data/lib/flipper/expressions/now.rb +9 -0
- data/lib/flipper/expressions/number.rb +9 -0
- data/lib/flipper/expressions/percentage.rb +9 -0
- data/lib/flipper/expressions/percentage_of_actors.rb +12 -0
- data/lib/flipper/expressions/property.rb +9 -0
- data/lib/flipper/expressions/random.rb +9 -0
- data/lib/flipper/expressions/string.rb +9 -0
- data/lib/flipper/expressions/time.rb +16 -0
- data/lib/flipper/feature.rb +95 -28
- data/lib/flipper/feature_check_context.rb +10 -6
- data/lib/flipper/gate.rb +13 -11
- data/lib/flipper/gate_values.rb +5 -18
- data/lib/flipper/gates/actor.rb +10 -17
- data/lib/flipper/gates/boolean.rb +1 -1
- data/lib/flipper/gates/expression.rb +75 -0
- data/lib/flipper/gates/group.rb +5 -7
- data/lib/flipper/gates/percentage_of_actors.rb +10 -13
- data/lib/flipper/gates/percentage_of_time.rb +1 -2
- data/lib/flipper/identifier.rb +17 -0
- data/lib/flipper/instrumentation/log_subscriber.rb +35 -8
- data/lib/flipper/instrumentation/statsd.rb +4 -2
- data/lib/flipper/instrumentation/statsd_subscriber.rb +2 -4
- data/lib/flipper/instrumentation/subscriber.rb +8 -5
- data/lib/flipper/instrumenters/memory.rb +6 -2
- data/lib/flipper/metadata.rb +8 -1
- data/lib/flipper/middleware/memoizer.rb +46 -27
- data/lib/flipper/middleware/setup_env.rb +13 -3
- data/lib/flipper/model/active_record.rb +23 -0
- data/lib/flipper/poller.rb +157 -0
- data/lib/flipper/serializers/gzip.rb +22 -0
- data/lib/flipper/serializers/json.rb +17 -0
- data/lib/flipper/spec/shared_adapter_specs.rb +122 -56
- data/lib/flipper/test/shared_adapter_test.rb +120 -52
- data/lib/flipper/test_help.rb +43 -0
- data/lib/flipper/typecast.rb +59 -18
- data/lib/flipper/types/actor.rb +19 -13
- data/lib/flipper/types/group.rb +12 -5
- data/lib/flipper/types/percentage.rb +1 -1
- data/lib/flipper/version.rb +11 -1
- data/lib/flipper.rb +71 -12
- data/lib/generators/flipper/setup_generator.rb +68 -0
- data/lib/generators/flipper/templates/initializer.rb +45 -0
- data/lib/generators/flipper/templates/update/migrations/01_create_flipper_tables.rb.erb +22 -0
- data/lib/generators/flipper/templates/update/migrations/02_change_flipper_gates_value_to_text.rb.erb +18 -0
- data/lib/generators/flipper/update_generator.rb +35 -0
- data/package-lock.json +41 -0
- data/package.json +10 -0
- data/spec/fixtures/environment.rb +1 -0
- data/spec/fixtures/flipper_pstore_1679087600.json +46 -0
- data/spec/flipper/actor_spec.rb +10 -2
- data/spec/flipper/adapter_builder_spec.rb +72 -0
- data/spec/flipper/adapter_spec.rb +52 -6
- data/spec/flipper/adapters/actor_limit_spec.rb +75 -0
- data/spec/flipper/adapters/dual_write_spec.rb +82 -0
- data/spec/flipper/adapters/failover_spec.rb +141 -0
- data/spec/flipper/adapters/failsafe_spec.rb +58 -0
- data/spec/flipper/adapters/http/client_spec.rb +61 -0
- data/spec/flipper/adapters/http_spec.rb +402 -65
- data/spec/flipper/adapters/instrumented_spec.rb +31 -13
- data/spec/flipper/adapters/memoizable_spec.rb +51 -33
- data/spec/flipper/adapters/memory_spec.rb +33 -5
- data/spec/flipper/adapters/operation_logger_spec.rb +38 -12
- data/spec/flipper/adapters/poll_spec.rb +41 -0
- data/spec/flipper/adapters/pstore_spec.rb +0 -2
- data/spec/flipper/adapters/read_only_spec.rb +32 -18
- data/spec/flipper/adapters/strict_spec.rb +64 -0
- data/spec/flipper/adapters/sync/feature_synchronizer_spec.rb +39 -1
- data/spec/flipper/adapters/sync/interval_synchronizer_spec.rb +4 -5
- data/spec/flipper/adapters/sync/synchronizer_spec.rb +87 -1
- data/spec/flipper/adapters/sync_spec.rb +17 -6
- data/spec/flipper/cli_spec.rb +217 -0
- data/spec/flipper/cloud/configuration_spec.rb +257 -0
- data/spec/flipper/cloud/dsl_spec.rb +90 -0
- data/spec/flipper/cloud/message_verifier_spec.rb +104 -0
- data/spec/flipper/cloud/middleware_spec.rb +307 -0
- data/spec/flipper/cloud/migrate_spec.rb +160 -0
- data/spec/flipper/cloud/telemetry/backoff_policy_spec.rb +107 -0
- data/spec/flipper/cloud/telemetry/metric_spec.rb +87 -0
- data/spec/flipper/cloud/telemetry/metric_storage_spec.rb +58 -0
- data/spec/flipper/cloud/telemetry/submitter_spec.rb +145 -0
- data/spec/flipper/cloud/telemetry_spec.rb +208 -0
- data/spec/flipper/cloud_spec.rb +186 -0
- data/spec/flipper/configuration_spec.rb +37 -3
- data/spec/flipper/dsl_spec.rb +67 -80
- data/spec/flipper/engine_spec.rb +374 -0
- data/spec/flipper/export_spec.rb +13 -0
- data/spec/flipper/exporter_spec.rb +16 -0
- data/spec/flipper/exporters/json/export_spec.rb +60 -0
- data/spec/flipper/exporters/json/v1_spec.rb +33 -0
- data/spec/flipper/expression/builder_spec.rb +248 -0
- data/spec/flipper/expression_spec.rb +188 -0
- data/spec/flipper/expressions/all_spec.rb +15 -0
- data/spec/flipper/expressions/any_spec.rb +15 -0
- data/spec/flipper/expressions/boolean_spec.rb +15 -0
- data/spec/flipper/expressions/equal_spec.rb +24 -0
- data/spec/flipper/expressions/greater_than_or_equal_to_spec.rb +28 -0
- data/spec/flipper/expressions/greater_than_spec.rb +28 -0
- data/spec/flipper/expressions/less_than_or_equal_to_spec.rb +28 -0
- data/spec/flipper/expressions/less_than_spec.rb +32 -0
- data/spec/flipper/expressions/not_equal_spec.rb +15 -0
- data/spec/flipper/expressions/now_spec.rb +11 -0
- data/spec/flipper/expressions/number_spec.rb +21 -0
- data/spec/flipper/expressions/percentage_of_actors_spec.rb +20 -0
- data/spec/flipper/expressions/percentage_spec.rb +15 -0
- data/spec/flipper/expressions/property_spec.rb +13 -0
- data/spec/flipper/expressions/random_spec.rb +9 -0
- data/spec/flipper/expressions/string_spec.rb +11 -0
- data/spec/flipper/expressions/time_spec.rb +29 -0
- data/spec/flipper/feature_check_context_spec.rb +18 -20
- data/spec/flipper/feature_spec.rb +461 -48
- data/spec/flipper/gate_spec.rb +0 -2
- data/spec/flipper/gate_values_spec.rb +2 -34
- data/spec/flipper/gates/actor_spec.rb +0 -2
- data/spec/flipper/gates/boolean_spec.rb +1 -3
- data/spec/flipper/gates/expression_spec.rb +190 -0
- data/spec/flipper/gates/group_spec.rb +2 -5
- data/spec/flipper/gates/percentage_of_actors_spec.rb +61 -7
- data/spec/flipper/gates/percentage_of_time_spec.rb +2 -4
- data/spec/flipper/identifier_spec.rb +12 -0
- data/spec/flipper/instrumentation/log_subscriber_spec.rb +24 -7
- data/spec/flipper/instrumentation/statsd_subscriber_spec.rb +26 -3
- 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 +199 -62
- data/spec/flipper/middleware/setup_env_spec.rb +23 -5
- data/spec/flipper/model/active_record_spec.rb +72 -0
- data/spec/flipper/poller_spec.rb +390 -0
- data/spec/flipper/registry_spec.rb +0 -1
- data/spec/flipper/serializers/gzip_spec.rb +13 -0
- data/spec/flipper/serializers/json_spec.rb +13 -0
- data/spec/flipper/typecast_spec.rb +121 -7
- data/spec/flipper/types/actor_spec.rb +63 -47
- data/spec/flipper/types/boolean_spec.rb +0 -1
- data/spec/flipper/types/group_spec.rb +24 -3
- 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/{integration_spec.rb → flipper_integration_spec.rb} +301 -59
- data/spec/flipper_spec.rb +123 -29
- data/spec/{helper.rb → spec_helper.rb} +23 -21
- data/spec/support/actor_names.yml +1 -0
- data/spec/support/descriptions.yml +1 -0
- data/spec/support/fail_on_output.rb +8 -0
- data/spec/support/fake_backoff_policy.rb +15 -0
- data/spec/support/skippable.rb +18 -0
- data/spec/support/spec_helpers.rb +53 -6
- data/test/adapters/actor_limit_test.rb +20 -0
- data/test/test_helper.rb +2 -1
- data/test_rails/generators/flipper/setup_generator_test.rb +69 -0
- data/test_rails/generators/flipper/update_generator_test.rb +96 -0
- data/test_rails/helper.rb +31 -0
- data/test_rails/system/test_help_test.rb +52 -0
- metadata +200 -82
- data/.rubocop.yml +0 -54
- data/.rubocop_todo.yml +0 -199
- 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 -114
- data/docs/api/README.md +0 -849
- data/docs/http/README.md +0 -35
- data/docs/read-only/README.md +0 -21
- data/examples/example_setup.rb +0 -8
- data/test/helper.rb +0 -11
data/.rubocop_todo.yml
DELETED
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
# This configuration was generated by
|
|
2
|
-
# `rubocop --auto-gen-config`
|
|
3
|
-
# on 2016-11-20 15:49:33 +0000 using RuboCop version 0.45.0.
|
|
4
|
-
# The point is for the user to remove these configuration records
|
|
5
|
-
# one by one as the offenses are removed from the code base.
|
|
6
|
-
# Note that changes in the inspected code, or installation of new
|
|
7
|
-
# versions of RuboCop, may require this file to be generated again.
|
|
8
|
-
|
|
9
|
-
require: rubocop-rspec
|
|
10
|
-
|
|
11
|
-
# Offense count: 2
|
|
12
|
-
Lint/AmbiguousRegexpLiteral:
|
|
13
|
-
Exclude:
|
|
14
|
-
- 'lib/flipper/instrumentation/metriks.rb'
|
|
15
|
-
- 'lib/flipper/instrumentation/statsd.rb'
|
|
16
|
-
|
|
17
|
-
# Offense count: 6
|
|
18
|
-
# Configuration parameters: AllowSafeAssignment.
|
|
19
|
-
Lint/AssignmentInCondition:
|
|
20
|
-
Exclude:
|
|
21
|
-
- 'lib/flipper/adapters/active_record.rb'
|
|
22
|
-
- 'lib/flipper/adapters/sequel.rb'
|
|
23
|
-
- 'lib/flipper/feature.rb'
|
|
24
|
-
- 'lib/flipper/gate_values.rb'
|
|
25
|
-
|
|
26
|
-
# Offense count: 1
|
|
27
|
-
Lint/Eval:
|
|
28
|
-
Exclude:
|
|
29
|
-
- 'flipper.gemspec'
|
|
30
|
-
|
|
31
|
-
# Offense count: 3
|
|
32
|
-
Lint/HandleExceptions:
|
|
33
|
-
Exclude:
|
|
34
|
-
- 'spec/flipper/adapters/mongo_spec.rb'
|
|
35
|
-
- 'test/adapters/mongo_test.rb'
|
|
36
|
-
- 'test/helper.rb'
|
|
37
|
-
|
|
38
|
-
# Offense count: 24
|
|
39
|
-
Lint/ShadowingOuterLocalVariable:
|
|
40
|
-
Exclude:
|
|
41
|
-
- 'lib/flipper/adapters/active_record.rb'
|
|
42
|
-
- 'lib/flipper/adapters/instrumented.rb'
|
|
43
|
-
- 'lib/flipper/adapters/sequel.rb'
|
|
44
|
-
- 'spec/flipper/api/v1/actions/actors_gate_spec.rb'
|
|
45
|
-
- 'spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb'
|
|
46
|
-
- 'spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb'
|
|
47
|
-
- 'spec/flipper/dsl_spec.rb'
|
|
48
|
-
- 'spec/flipper/feature_spec.rb'
|
|
49
|
-
- 'spec/flipper/types/group_spec.rb'
|
|
50
|
-
|
|
51
|
-
# Offense count: 26
|
|
52
|
-
Lint/UselessAssignment:
|
|
53
|
-
Exclude:
|
|
54
|
-
- 'lib/flipper/instrumentation/log_subscriber.rb'
|
|
55
|
-
- 'lib/flipper/instrumentation/subscriber.rb'
|
|
56
|
-
- 'lib/flipper/ui/actions/groups_gate.rb'
|
|
57
|
-
- 'spec/flipper/api/action_spec.rb'
|
|
58
|
-
- 'spec/flipper/dsl_spec.rb'
|
|
59
|
-
- 'spec/flipper/feature_spec.rb'
|
|
60
|
-
- 'spec/flipper/gates/group_spec.rb'
|
|
61
|
-
- 'spec/flipper/instrumentation/metriks_subscriber_spec.rb'
|
|
62
|
-
- 'spec/flipper/instrumentation/statsd_subscriber_spec.rb'
|
|
63
|
-
- 'spec/flipper_spec.rb'
|
|
64
|
-
- 'spec/flipper/middleware/memoizer_spec.rb'
|
|
65
|
-
- 'test/helper.rb'
|
|
66
|
-
|
|
67
|
-
# Offense count: 27
|
|
68
|
-
Metrics/AbcSize:
|
|
69
|
-
Max: 30
|
|
70
|
-
|
|
71
|
-
# Offense count: 1
|
|
72
|
-
# Configuration parameters: CountComments.
|
|
73
|
-
Metrics/BlockLength:
|
|
74
|
-
Max: 195
|
|
75
|
-
|
|
76
|
-
# Offense count: 4
|
|
77
|
-
# Configuration parameters: CountComments.
|
|
78
|
-
Metrics/ClassLength:
|
|
79
|
-
Max: 178
|
|
80
|
-
|
|
81
|
-
# Offense count: 39
|
|
82
|
-
# Configuration parameters: CountComments.
|
|
83
|
-
Metrics/MethodLength:
|
|
84
|
-
Max: 23
|
|
85
|
-
|
|
86
|
-
# Offense count: 65
|
|
87
|
-
# Configuration parameters: Max.
|
|
88
|
-
RSpec/ExampleLength:
|
|
89
|
-
Enabled: false
|
|
90
|
-
|
|
91
|
-
# Offense count: 2
|
|
92
|
-
# Configuration parameters: CustomTransform.
|
|
93
|
-
RSpec/FilePath:
|
|
94
|
-
Exclude:
|
|
95
|
-
- 'spec/flipper/adapters/pstore_spec.rb'
|
|
96
|
-
- 'spec/integration_spec.rb'
|
|
97
|
-
|
|
98
|
-
# Offense count: 91
|
|
99
|
-
RSpec/InstanceVariable:
|
|
100
|
-
Exclude:
|
|
101
|
-
- 'spec/flipper/adapters/operation_logger_spec.rb'
|
|
102
|
-
- 'spec/flipper/dsl_spec.rb'
|
|
103
|
-
- 'spec/flipper/feature_spec.rb'
|
|
104
|
-
- 'spec/flipper/instrumentation/log_subscriber_spec.rb'
|
|
105
|
-
- 'spec/flipper/ui/actions/add_feature_spec.rb'
|
|
106
|
-
- 'spec/flipper/ui/actions/features_spec.rb'
|
|
107
|
-
- 'spec/flipper/ui/decorators/feature_spec.rb'
|
|
108
|
-
- 'spec/flipper/ui/decorators/gate_spec.rb'
|
|
109
|
-
- 'spec/flipper/ui_spec.rb'
|
|
110
|
-
- 'spec/flipper_spec.rb'
|
|
111
|
-
- 'spec/integration_spec.rb'
|
|
112
|
-
|
|
113
|
-
# Offense count: 15
|
|
114
|
-
# Configuration parameters: IgnoreSymbolicNames.
|
|
115
|
-
RSpec/VerifiedDoubles:
|
|
116
|
-
Exclude:
|
|
117
|
-
- 'spec/flipper/api/v1/actions/features_spec.rb'
|
|
118
|
-
- 'spec/flipper/dsl_spec.rb'
|
|
119
|
-
- 'spec/flipper/feature_spec.rb'
|
|
120
|
-
- 'spec/flipper/types/group_spec.rb'
|
|
121
|
-
- 'spec/flipper_spec.rb'
|
|
122
|
-
- 'spec/integration_spec.rb'
|
|
123
|
-
|
|
124
|
-
# Offense count: 2
|
|
125
|
-
Style/AccessorMethodName:
|
|
126
|
-
Exclude:
|
|
127
|
-
- 'lib/flipper/adapters/memory.rb'
|
|
128
|
-
- 'lib/flipper/adapters/pstore.rb'
|
|
129
|
-
|
|
130
|
-
# Offense count: 7
|
|
131
|
-
Style/ConstantName:
|
|
132
|
-
Exclude:
|
|
133
|
-
- 'lib/flipper.rb'
|
|
134
|
-
- 'lib/flipper/adapters/dalli.rb'
|
|
135
|
-
- 'lib/flipper/adapters/memoizable.rb'
|
|
136
|
-
- 'lib/flipper/adapters/memory.rb'
|
|
137
|
-
- 'lib/flipper/adapters/mongo.rb'
|
|
138
|
-
- 'lib/flipper/adapters/pstore.rb'
|
|
139
|
-
- 'lib/flipper/adapters/redis.rb'
|
|
140
|
-
|
|
141
|
-
# Offense count: 3
|
|
142
|
-
Style/DoubleNegation:
|
|
143
|
-
Exclude:
|
|
144
|
-
- 'lib/flipper/adapters/memoizable.rb'
|
|
145
|
-
- 'lib/flipper/gates/boolean.rb'
|
|
146
|
-
- 'lib/flipper/typecast.rb'
|
|
147
|
-
|
|
148
|
-
# Offense count: 7
|
|
149
|
-
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
|
|
150
|
-
Style/FileName:
|
|
151
|
-
Exclude:
|
|
152
|
-
- 'lib/flipper-active_record.rb'
|
|
153
|
-
- 'lib/flipper-api.rb'
|
|
154
|
-
- 'lib/flipper-active_support_cache_store.rb'
|
|
155
|
-
- 'lib/flipper-cloud.rb'
|
|
156
|
-
- 'lib/flipper-dalli.rb'
|
|
157
|
-
- 'lib/flipper-mongo.rb'
|
|
158
|
-
- 'lib/flipper-redis.rb'
|
|
159
|
-
- 'lib/flipper-sequel.rb'
|
|
160
|
-
- 'lib/flipper-ui.rb'
|
|
161
|
-
|
|
162
|
-
# Offense count: 2
|
|
163
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
164
|
-
# SupportedStyles: format, sprintf, percent
|
|
165
|
-
Style/FormatString:
|
|
166
|
-
Exclude:
|
|
167
|
-
- 'lib/flipper/instrumentation/log_subscriber.rb'
|
|
168
|
-
|
|
169
|
-
# Offense count: 10
|
|
170
|
-
# Configuration parameters: MinBodyLength.
|
|
171
|
-
Style/GuardClause:
|
|
172
|
-
Exclude:
|
|
173
|
-
- 'lib/flipper/api/v1/actions/percentage_of_actors_gate.rb'
|
|
174
|
-
- 'lib/flipper/api/v1/actions/percentage_of_time_gate.rb'
|
|
175
|
-
- 'lib/flipper/gate_values.rb'
|
|
176
|
-
- 'lib/flipper/instrumentation/statsd_subscriber.rb'
|
|
177
|
-
- 'lib/flipper/instrumentation/subscriber.rb'
|
|
178
|
-
- 'lib/flipper/registry.rb'
|
|
179
|
-
- 'lib/flipper/typecast.rb'
|
|
180
|
-
|
|
181
|
-
# Offense count: 1
|
|
182
|
-
Style/IfInsideElse:
|
|
183
|
-
Exclude:
|
|
184
|
-
- 'lib/flipper/gates/actor.rb'
|
|
185
|
-
|
|
186
|
-
# Offense count: 1
|
|
187
|
-
Style/MethodMissing:
|
|
188
|
-
Exclude:
|
|
189
|
-
- 'lib/flipper/types/actor.rb'
|
|
190
|
-
|
|
191
|
-
Style/AccessorMethodName:
|
|
192
|
-
Exclude:
|
|
193
|
-
- 'lib/flipper/adapter.rb'
|
|
194
|
-
- 'lib/flipper/adapters/http.rb'
|
|
195
|
-
- 'lib/flipper/adapters/instrumented.rb'
|
|
196
|
-
- 'lib/flipper/adapters/memoizable.rb'
|
|
197
|
-
- 'lib/flipper/adapters/operation_logger.rb'
|
|
198
|
-
- 'lib/flipper/adapters/memory.rb'
|
|
199
|
-
- 'lib/flipper/adapters/pstore.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 3, 4, and 5.
|
|
8
|
-
* [ActiveSupportCacheStore adapter](https://github.com/jnunemaker/flipper/blob/master/docs/active_support_cache_store) - ActiveSupport::Cache::Store
|
|
9
|
-
* [Cassanity adapter](https://github.com/jnunemaker/flipper-cassanity)
|
|
10
|
-
* [Http adapter](https://github.com/jnunemaker/flipper/blob/master/docs/http)
|
|
11
|
-
* [memory adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/memory.rb) – great for tests
|
|
12
|
-
* [Moneta adapter](https://github.com/jnunemaker/flipper/blob/master/docs/moneta)
|
|
13
|
-
* [Mongo adapter](https://github.com/jnunemaker/flipper/blob/master/docs/mongo)
|
|
14
|
-
* [PStore adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/pstore.rb) – great for when a local file is enough
|
|
15
|
-
* [read-only adapter](https://github.com/jnunemaker/flipper/blob/master/docs/read-only)
|
|
16
|
-
* [Redis adapter](https://github.com/jnunemaker/flipper/blob/master/docs/redis)
|
|
17
|
-
* [Sequel adapter](https://github.com/jnunemaker/flipper/blob/master/docs/sequel)
|
|
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#3-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 20 individual people, I would recommend using a [group](https://github.com/jnunemaker/flipper/blob/master/docs/Gates.md#2-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 = Flipper.new(adapter)
|
|
11
|
-
flipper[:stats].enable # turn on
|
|
12
|
-
flipper[:stats].disable # turn off
|
|
13
|
-
flipper[:stats].enabled? # check
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
## 2. Group
|
|
17
|
-
|
|
18
|
-
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.
|
|
19
|
-
|
|
20
|
-
```ruby
|
|
21
|
-
# this registers a group
|
|
22
|
-
Flipper.register(:admins) do |actor|
|
|
23
|
-
actor.respond_to?(:admin?) && actor.admin?
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
flipper = Flipper.new(adapter)
|
|
27
|
-
|
|
28
|
-
flipper[:stats].enable flipper.group(:admins) # This registers a stats feature and turns it on for admins (which is anything that returns true from the registered block).
|
|
29
|
-
flipper[:stats].disable flipper.group(:admins) # turn off the stats feature for admins
|
|
30
|
-
|
|
31
|
-
person = Person.find(params[:id])
|
|
32
|
-
flipper[:stats].enabled? person # check if enabled, returns true if person.admin? is true
|
|
33
|
-
|
|
34
|
-
# you can also use shortcut methods. This also registers a stats feature and turns it on for admins.
|
|
35
|
-
flipper.enable_group :stats, :admins
|
|
36
|
-
person = Person.find(params[:id])
|
|
37
|
-
flipper[:stats].enabled? person # same as above. check if enabled, returns true if person.admin? is true
|
|
38
|
-
|
|
39
|
-
flipper.disable_group :stats, :admins
|
|
40
|
-
flipper[:stats].enable_group :admins
|
|
41
|
-
flipper[:stats].disable_group :admins
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
Here's a quick explanation of the above code block:
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
Flipper.register(:admins) do |actor|
|
|
48
|
-
actor.respond_to?(:admin?) && actor.admin?
|
|
49
|
-
end
|
|
50
|
-
```
|
|
51
|
-
- 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.
|
|
52
|
-
|
|
53
|
-
```
|
|
54
|
-
flipper[:stats].enable flipper.group(:admins)
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
- The above enables the stats feature to any object that returns true from the `:admins` proc.
|
|
58
|
-
|
|
59
|
-
```
|
|
60
|
-
person = Person.find(params[:id])
|
|
61
|
-
flipper[:stats].enabled? person # check if person is enabled, returns true if person.admin? is true
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
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.
|
|
65
|
-
|
|
66
|
-
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.
|
|
67
|
-
|
|
68
|
-
In your application code, you can do something like this now:
|
|
69
|
-
|
|
70
|
-
```
|
|
71
|
-
if flipper[:stats].enabled?(some_admin)
|
|
72
|
-
# do thing...
|
|
73
|
-
else
|
|
74
|
-
# do not do thing
|
|
75
|
-
end
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
## 3. Individual Actor
|
|
79
|
-
|
|
80
|
-
Turn feature on for individual thing. Think enable feature for someone to test or for a buddy. The only requirement for an individual actor is that it must respond to `flipper_id`.
|
|
81
|
-
|
|
82
|
-
```ruby
|
|
83
|
-
flipper = Flipper.new(adapter)
|
|
84
|
-
|
|
85
|
-
flipper[:stats].enable user
|
|
86
|
-
flipper[:stats].enabled? user # true
|
|
87
|
-
|
|
88
|
-
flipper[:stats].disable user
|
|
89
|
-
flipper[:stats].enabled? user # false
|
|
90
|
-
|
|
91
|
-
# you can enable anything, does not need to be user or person
|
|
92
|
-
flipper[:search].enable group
|
|
93
|
-
flipper[:search].enabled? group
|
|
94
|
-
|
|
95
|
-
# you can also use shortcut methods
|
|
96
|
-
flipper.enable_actor :search, user
|
|
97
|
-
flipper.disable_actor :search, user
|
|
98
|
-
flipper[:search].enable_actor user
|
|
99
|
-
flipper[:search].disable_actor user
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
The key is to make sure you do not enable two different types of objects for the same feature. Imagine that user has a `flipper_id` of 6 and group has a `flipper_id` of 6. Enabling search for user would automatically enable it for group, as they both have a `flipper_id` of 6.
|
|
103
|
-
|
|
104
|
-
The one exception to this rule is if you have globally unique `flipper_ids`, such as UUIDs. If your `flipper_ids` are unique globally in your entire system, enabling two different types should be safe. Another way around this is to prefix the `flipper_id` with the class name like this:
|
|
105
|
-
|
|
106
|
-
```ruby
|
|
107
|
-
class User
|
|
108
|
-
def flipper_id
|
|
109
|
-
"User;#{id}"
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
class Group
|
|
114
|
-
def flipper_id
|
|
115
|
-
"Group;#{id}"
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
## 4. Percentage of Actors
|
|
121
|
-
|
|
122
|
-
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.
|
|
123
|
-
|
|
124
|
-
```ruby
|
|
125
|
-
flipper = Flipper.new(adapter)
|
|
126
|
-
|
|
127
|
-
# returns a percentage of actors instance set to 10
|
|
128
|
-
percentage = flipper.actors(10)
|
|
129
|
-
|
|
130
|
-
# turn stats on for 10 percent of users in the system
|
|
131
|
-
flipper[:stats].enable percentage
|
|
132
|
-
|
|
133
|
-
# checks if actor's flipper_id is in the enabled percentage by hashing
|
|
134
|
-
# user.flipper_id.to_s to ensure enabled distribution is smooth
|
|
135
|
-
flipper[:stats].enabled? user
|
|
136
|
-
|
|
137
|
-
# you can also use shortcut methods
|
|
138
|
-
flipper.enable_percentage_of_actors :search, 10
|
|
139
|
-
flipper.disable_percentage_of_actors :search # sets to 0
|
|
140
|
-
flipper[:search].enable_percentage_of_actors 10
|
|
141
|
-
flipper[:search].disable_percentage_of_actors # sets to 0
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
## 5. Percentage of Time
|
|
145
|
-
|
|
146
|
-
Turn this on for a percentage of time. Think load testing new features behind the scenes and such.
|
|
147
|
-
|
|
148
|
-
```ruby
|
|
149
|
-
flipper = Flipper.new(adapter)
|
|
150
|
-
|
|
151
|
-
# get percentage of time instance set to 5
|
|
152
|
-
percentage = flipper.time(5)
|
|
153
|
-
|
|
154
|
-
# Register a feature called logging and turn it on for 5 percent of the time.
|
|
155
|
-
# This could be on during one request and off the next
|
|
156
|
-
# could even be on first time in request and off second time
|
|
157
|
-
flipper[:logging].enable percentage
|
|
158
|
-
flipper[:logging].enabled? # this will return true 5% of the time.
|
|
159
|
-
|
|
160
|
-
# you can also use shortcut methods
|
|
161
|
-
flipper.enable_percentage_of_time :search, 5 # registers a feature called "enable_percentage_of_time" and enables it 5% of the time
|
|
162
|
-
flipper.disable_percentage_of_time :search # sets to 0
|
|
163
|
-
flipper[:search].enable_percentage_of_time 5
|
|
164
|
-
flipper[:search].disable_percentage_of_time # sets to 0
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
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.
|
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.
|
data/docs/Optimization.md
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
# Optimization
|
|
2
|
-
|
|
3
|
-
## Memoizing Middleware
|
|
4
|
-
|
|
5
|
-
One optimization that flipper provides is a memoizing middleware. The memoizing middleware ensures that you only make one adapter call per feature per request. This means if you check the same feature over and over, it will only make one Mongo, Redis, or whatever call per feature for the length of the request.
|
|
6
|
-
|
|
7
|
-
You can use the middleware like so for Rails:
|
|
8
|
-
|
|
9
|
-
```ruby
|
|
10
|
-
# setup default instance (perhaps in config/initializer/flipper.rb)
|
|
11
|
-
Flipper.configure do |config|
|
|
12
|
-
config.default do
|
|
13
|
-
Flipper.new(...)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# This assumes you setup a default flipper instance using configure.
|
|
18
|
-
config.middleware.use Flipper::Middleware::Memoizer
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
**Note**: Be sure that the middleware is high enough up in your stack that all feature checks are wrapped.
|
|
22
|
-
|
|
23
|
-
**Also Note**: If you haven't setup a default instance, you can pass the instance to `SetupEnv` as `Memoizer` uses whatever is setup in the `env`:
|
|
24
|
-
|
|
25
|
-
```ruby
|
|
26
|
-
config.middleware.use Flipper::Middleware::SetupEnv, -> { Flipper.new(...) }
|
|
27
|
-
config.middleware.use Flipper::Middleware::Memoizer
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
### Options
|
|
31
|
-
|
|
32
|
-
The Memoizer middleware also supports a few options. Use either `preload` or `preload_all`, not both.
|
|
33
|
-
|
|
34
|
-
* **`:preload`** - An `Array` of feature names (`Symbol`) to preload for every request. Useful if you have features that are used on every endpoint. `preload` uses `Adapter#get_multi` to attempt to load the features in one network call instead of N+1 network calls.
|
|
35
|
-
```ruby
|
|
36
|
-
config.middleware.use Flipper::Middleware::Memoizer,
|
|
37
|
-
preload: [:stats, :search, :some_feature]
|
|
38
|
-
```
|
|
39
|
-
* **`:preload_all`** - A Boolean value (default: false) of whether or not all features should be preloaded. Using this results in a `preload_all` call with the result of `Adapter#get_all`. Any subsequent feature checks will be memoized and perform no network calls. I wouldn't recommend using this unless you have few features (< 100?) and nearly all of them are used on every request.
|
|
40
|
-
```ruby
|
|
41
|
-
config.middleware.use Flipper::Middleware::Memoizer,
|
|
42
|
-
preload_all: true
|
|
43
|
-
```
|
|
44
|
-
* **`:unless`** - A block that prevents preloading and memoization if it evaluates to true.
|
|
45
|
-
```ruby
|
|
46
|
-
# skip preloading and memoizing if path starts with /assets
|
|
47
|
-
config.middleware.use Flipper::Middleware::Memoizer,
|
|
48
|
-
unless: ->(request) { request.path.start_with?("/assets") }
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## Cache Adapters
|
|
52
|
-
|
|
53
|
-
Cache adapters allow you to cache adapter calls for longer than a single request and should be used alongside the memoization middleware to add another caching layer.
|
|
54
|
-
|
|
55
|
-
### Dalli
|
|
56
|
-
|
|
57
|
-
> Dalli is a high performance pure Ruby client for accessing memcached servers.
|
|
58
|
-
|
|
59
|
-
https://github.com/petergoldstein/dalli
|
|
60
|
-
|
|
61
|
-
Example using the Dalli cache adapter with the Memory adapter and a TTL of 600 seconds:
|
|
62
|
-
|
|
63
|
-
```ruby
|
|
64
|
-
dalli_client = Dalli::Client.new('localhost:11211')
|
|
65
|
-
memory_adapter = Flipper::Adapters::Memory.new
|
|
66
|
-
adapter = Flipper::Adapters::Dalli.new(memory_adapter, dalli_client, 600)
|
|
67
|
-
flipper = Flipper.new(adapter)
|
|
68
|
-
```
|
|
69
|
-
### RedisCache
|
|
70
|
-
|
|
71
|
-
Applications using [Redis](https://redis.io/) via the [redis-rb](https://github.com/redis/redis-rb) client can take advantage of the RedisCache adapter.
|
|
72
|
-
|
|
73
|
-
Initialize `RedisCache` with a flipper [adapter](https://github.com/jnunemaker/flipper/blob/master/docs/Adapters.md), a Redis client instance, and an optional TTL in seconds. TTL defaults to 3600 seconds.
|
|
74
|
-
|
|
75
|
-
Example using the RedisCache adapter with the Memory adapter and a TTL of 4800 seconds:
|
|
76
|
-
|
|
77
|
-
```ruby
|
|
78
|
-
require 'flipper/adapters/redis_cache'
|
|
79
|
-
|
|
80
|
-
redis = Redis.new(url: ENV['REDIS_URL'])
|
|
81
|
-
memory_adapter = Flipper::Adapters::Memory.new
|
|
82
|
-
adapter = Flipper::Adapters::RedisCache.new(memory_adapter, redis, 4800)
|
|
83
|
-
flipper = Flipper.new(adapter)
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### ActiveSupportCacheStore
|
|
87
|
-
|
|
88
|
-
Rails applications can cache Flipper calls in any [ActiveSupport::Cache::Store](http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html) implementation.
|
|
89
|
-
|
|
90
|
-
Add this line to your application's Gemfile:
|
|
91
|
-
|
|
92
|
-
gem 'flipper-active_support_cache_store'
|
|
93
|
-
|
|
94
|
-
And then execute:
|
|
95
|
-
|
|
96
|
-
$ bundle
|
|
97
|
-
|
|
98
|
-
Or install it yourself with:
|
|
99
|
-
|
|
100
|
-
$ gem install flipper-active_support_cache_store
|
|
101
|
-
|
|
102
|
-
Example using the ActiveSupportCacheStore adapter with ActiveSupport's [MemoryStore](http://api.rubyonrails.org/classes/ActiveSupport/Cache/MemoryStore.html), Flipper's [Memory adapter](https://github.com/jnunemaker/flipper/blob/master/lib/flipper/adapters/memory.rb), and a TTL of 5 minutes.
|
|
103
|
-
|
|
104
|
-
```ruby
|
|
105
|
-
require 'active_support/cache'
|
|
106
|
-
require 'flipper/adapters/active_support_cache_store'
|
|
107
|
-
|
|
108
|
-
memory_adapter = Flipper::Adapters::Memory.new
|
|
109
|
-
cache = ActiveSupport::Cache::MemoryStore.new
|
|
110
|
-
adapter = Flipper::Adapters::ActiveSupportCacheStore.new(memory_adapter, cache, expires_in: 5.minutes)
|
|
111
|
-
flipper = Flipper.new(adapter)
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
Setting `expires_in` is optional and will set an expiration time on Flipper cache keys. If specified, all flipper keys will use this `expires_in` over the `expires_in` passed to your ActiveSupport cache constructor.
|