Skip to content

Commit b995c12

Browse files
committed
Properly deprecate instrumenter option
1 parent f605c86 commit b995c12

13 files changed

+55
-11
lines changed

lib/flipper.rb

+9
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ def instance=(flipper)
6868
:memoize=, :memoizing?,
6969
:sync, :sync_secret # For Flipper::Cloud. Will error for OSS Flipper.
7070

71+
# Public: Get or set the configured instrumenter.
7172
def_delegators :configuration, :instrumenter, :instrumenter=
73+
74+
# Public: Instrument a call using the configured instrumenter.
75+
#
76+
# Flipper.instrument(name, payload) do |payload|
77+
# payload[:result] = something
78+
# end
79+
#
7280
def_delegators :instrumenter, :instrument
7381

7482
# Public: Use this to register a group by name.
@@ -143,6 +151,7 @@ def groups_registry=(registry)
143151
end
144152
end
145153

154+
require 'flipper/deprecated_instrumenter'
146155
require 'flipper/actor'
147156
require 'flipper/adapter'
148157
require 'flipper/adapters/memoizable'

lib/flipper/adapters/instrumented.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Adapters
66
# operations.
77
class Instrumented < SimpleDelegator
88
include ::Flipper::Adapter
9+
include DeprecatedInstrumenter
910

1011
# Private: The name of instrumentation events.
1112
InstrumentationName = "adapter_operation.#{InstrumentationNamespace}".freeze
@@ -17,8 +18,9 @@ class Instrumented < SimpleDelegator
1718
#
1819
# adapter - Vanilla adapter instance to wrap.
1920
#
20-
def initialize(adapter)
21+
def initialize(adapter, options = {})
2122
super(adapter)
23+
deprecated_instrumenter_option options
2224
@adapter = adapter
2325
@name = :instrumented
2426
end

lib/flipper/adapters/sync.rb

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module Adapters
77
# rather than in the main thread only when reads happen.
88
class Sync
99
include ::Flipper::Adapter
10+
include DeprecatedInstrumenter
1011

1112
# Public: The name of the adapter.
1213
attr_reader :name
@@ -22,6 +23,7 @@ class Sync
2223
# interval - The Float or Integer number of seconds between syncs from
2324
# remote to local. Default value is set in IntervalSynchronizer.
2425
def initialize(local, remote, options = {})
26+
deprecated_instrumenter_option options
2527
@name = :sync
2628
@local = local
2729
@remote = remote

lib/flipper/adapters/sync/synchronizer.rb

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class Sync
88
# Public: Given a local and remote adapter, it can update the local to
99
# match the remote doing only the necessary enable/disable operations.
1010
class Synchronizer
11+
include DeprecatedInstrumenter
12+
1113
# Public: Initializes a new synchronizer.
1214
#
1315
# local - The Flipper adapter to get in sync with the remote.
@@ -16,6 +18,7 @@ class Synchronizer
1618
# options - The Hash of options.
1719
# :raise - Should errors be raised (default: true).
1820
def initialize(local, remote, options = {})
21+
deprecated_instrumenter_option options
1922
@local = local
2023
@remote = remote
2124
@raise = options.fetch(:raise, true)

lib/flipper/cloud/configuration.rb

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
module Flipper
1010
module Cloud
1111
class Configuration
12+
include DeprecatedInstrumenter
13+
1214
# The set of valid ways that syncing can happpen.
1315
VALID_SYNC_METHODS = Set[
1416
:poll,
@@ -58,6 +60,7 @@ class Configuration
5860
attr_accessor :sync_secret
5961

6062
def initialize(options = {})
63+
deprecated_instrumenter_option options
6164
@token = options.fetch(:token) { ENV["FLIPPER_CLOUD_TOKEN"] }
6265

6366
if @token.nil?

lib/flipper/configuration.rb

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module Flipper
22
class Configuration
3-
attr_accessor :instrumenter
4-
53
def initialize(options = {})
64
adapter { Flipper::Adapters::Memory.new }
75
default { Flipper.new(adapter) }
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Flipper
2+
# Private: Deprecation warnings for instrumenter option
3+
module DeprecatedInstrumenter
4+
def deprecated_instrumenter_option options
5+
if options.has_key?(:instrumenter)
6+
warn "The `:instrumenter` option is deprecated and has no effect. Set `Flipper.instrumenter` globally."
7+
warn caller[1]
8+
end
9+
end
10+
11+
def instrumenter
12+
warn "`#instrumenter` is deprecated. Use `Flipper.instrument` or `Flipper.instrumenter` instead."
13+
warn caller[0]
14+
15+
Flipper.instrumenter
16+
end
17+
end
18+
end

lib/flipper/dsl.rb

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module Flipper
44
class DSL
55
extend Forwardable
6+
include DeprecatedInstrumenter
67

78
# Private
89
attr_reader :adapter
@@ -15,6 +16,7 @@ class DSL
1516
# options - The Hash of options.
1617
# :memoize - Should adapter be wrapped by memoize adapter or not.
1718
def initialize(adapter, options = {})
19+
deprecated_instrumenter_option options
1820
memoize = options.fetch(:memoize, true)
1921
adapter = Adapters::Memoizable.new(adapter) if memoize
2022
@adapter = adapter

lib/flipper/feature.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
module Flipper
88
class Feature
9+
include DeprecatedInstrumenter
10+
911
# Private: The name of feature instrumentation events.
1012
InstrumentationName = "feature_operation.#{InstrumentationNamespace}".freeze
1113

@@ -23,7 +25,8 @@ class Feature
2325
# name - The Symbol or String name of the feature.
2426
# adapter - The adapter that will be used to store details about this feature.
2527
#
26-
def initialize(name, adapter)
28+
def initialize(name, adapter, options = {})
29+
deprecated_instrumenter_option options
2730
@name = name
2831
@key = name.to_s
2932
@adapter = adapter

lib/flipper/instrumenters/memory.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ def instrument(name, payload = {})
2626
@events << Event.new(name, payload, result)
2727
end
2828

29-
def self.subscribe(_name, _subscriber)
29+
def self.subscribe(_name, _callback = nil, &_block)
3030
# noop
3131
end
3232

33-
3433
def events_by_name(name)
3534
@events.select { |event| event.name == name }
3635
end

lib/flipper/instrumenters/noop.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def self.instrument(_name, payload = {})
55
yield payload if block_given?
66
end
77

8-
def self.subscribe(_name, _subscriber)
8+
def self.subscribe(_name, _callback = nil, &_block)
99
# noop
1010
end
1111
end

spec/flipper/adapters/sync/synchronizer_spec.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@
3232

3333
context "when raise disabled" do
3434
subject do
35-
options = {
36-
instrumenter: instrumenter,
37-
raise: false,
38-
}
35+
options = { raise: false }
3936
described_class.new(local, remote, options)
4037
end
4138

spec/spec_helper.rb

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
Flipper.configuration = nil
2828
end
2929

30+
config.after(:each) do
31+
# Remove all subscribers once AS::Notifications is loaded
32+
if defined?(ActiveSupport::Notifications)
33+
ActiveSupport::Notifications.unsubscribe /\.flipper$/
34+
end
35+
end
36+
37+
3038
config.disable_monkey_patching!
3139

3240
config.filter_run focus: true

0 commit comments

Comments
 (0)