Class: Flipper::Adapters::Instrumented
- Inherits:
-
Object
- Object
- Flipper::Adapters::Instrumented
- Includes:
- Flipper::Adapter
- Defined in:
- lib/flipper/adapters/instrumented.rb
Overview
Internal: Adapter that wraps another adapter and instruments all adapter operations.
Constant Summary collapse
- InstrumentationName =
Private: The name of instrumentation events.
"adapter_operation.#{InstrumentationNamespace}".freeze
Instance Attribute Summary collapse
-
#instrumenter ⇒ Object
readonly
Private: What is used to instrument all the things.
Instance Method Summary collapse
-
#add(feature) ⇒ Object
Public.
-
#clear(feature) ⇒ Object
Public.
-
#disable(feature, gate, thing) ⇒ Object
Public.
-
#enable(feature, gate, thing) ⇒ Object
Public.
- #export(format: :json, version: 1) ⇒ Object
-
#features ⇒ Object
Public.
-
#get(feature) ⇒ Object
Public.
- #get_all ⇒ Object
- #get_multi(features) ⇒ Object
- #import(source) ⇒ Object
-
#initialize(adapter, options = {}) ⇒ Instrumented
constructor
Internal: Initializes a new adapter instance.
-
#remove(feature) ⇒ Object
Public.
Methods included from Flipper::Adapter
#default_config, included, #name, #read_only?
Constructor Details
#initialize(adapter, options = {}) ⇒ Instrumented
Internal: Initializes a new adapter instance.
adapter - Vanilla adapter instance to wrap.
options - The Hash of options.
:instrumenter - What to use to instrument all the things.
23 24 25 26 |
# File 'lib/flipper/adapters/instrumented.rb', line 23 def initialize(adapter, = {}) @adapter = adapter @instrumenter = .fetch(:instrumenter, Instrumenters::Noop) end |
Instance Attribute Details
#instrumenter ⇒ Object (readonly)
Private: What is used to instrument all the things.
14 15 16 |
# File 'lib/flipper/adapters/instrumented.rb', line 14 def instrumenter @instrumenter end |
Instance Method Details
#add(feature) ⇒ Object
Public
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/flipper/adapters/instrumented.rb', line 41 def add(feature) default_payload = { operation: :add, adapter_name: @adapter.name, feature_name: feature.name, } @instrumenter.instrument(InstrumentationName, default_payload) do |payload| payload[:result] = @adapter.add(feature) end end |
#clear(feature) ⇒ Object
Public
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/flipper/adapters/instrumented.rb', line 67 def clear(feature) default_payload = { operation: :clear, adapter_name: @adapter.name, feature_name: feature.name, } @instrumenter.instrument(InstrumentationName, default_payload) do |payload| payload[:result] = @adapter.clear(feature) end end |
#disable(feature, gate, thing) ⇒ Object
Public
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/flipper/adapters/instrumented.rb', line 131 def disable(feature, gate, thing) default_payload = { operation: :disable, adapter_name: @adapter.name, feature_name: feature.name, gate_name: gate.name, thing_value: thing.value, } @instrumenter.instrument(InstrumentationName, default_payload) do |payload| payload[:result] = @adapter.disable(feature, gate, thing) end end |
#enable(feature, gate, thing) ⇒ Object
Public
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/flipper/adapters/instrumented.rb', line 116 def enable(feature, gate, thing) default_payload = { operation: :enable, adapter_name: @adapter.name, feature_name: feature.name, gate_name: gate.name, thing_value: thing.value, } @instrumenter.instrument(InstrumentationName, default_payload) do |payload| payload[:result] = @adapter.enable(feature, gate, thing) end end |
#export(format: :json, version: 1) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/flipper/adapters/instrumented.rb', line 156 def export(format: :json, version: 1) default_payload = { operation: :export, adapter_name: @adapter.name, format: format, version: version, } @instrumenter.instrument(InstrumentationName, default_payload) do |payload| payload[:result] = @adapter.export(format: format, version: version) end end |
#features ⇒ Object
Public
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/flipper/adapters/instrumented.rb', line 29 def features default_payload = { operation: :features, adapter_name: @adapter.name, } @instrumenter.instrument(InstrumentationName, default_payload) do |payload| payload[:result] = @adapter.features end end |
#get(feature) ⇒ Object
Public
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/flipper/adapters/instrumented.rb', line 80 def get(feature) default_payload = { operation: :get, adapter_name: @adapter.name, feature_name: feature.name, } @instrumenter.instrument(InstrumentationName, default_payload) do |payload| payload[:result] = @adapter.get(feature) end end |
#get_all ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/flipper/adapters/instrumented.rb', line 104 def get_all default_payload = { operation: :get_all, adapter_name: @adapter.name, } @instrumenter.instrument(InstrumentationName, default_payload) do |payload| payload[:result] = @adapter.get_all end end |
#get_multi(features) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/flipper/adapters/instrumented.rb', line 92 def get_multi(features) default_payload = { operation: :get_multi, adapter_name: @adapter.name, feature_names: features.map(&:name), } @instrumenter.instrument(InstrumentationName, default_payload) do |payload| payload[:result] = @adapter.get_multi(features) end end |
#import(source) ⇒ Object
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/flipper/adapters/instrumented.rb', line 145 def import(source) default_payload = { operation: :import, adapter_name: @adapter.name, } @instrumenter.instrument(InstrumentationName, default_payload) do |payload| payload[:result] = @adapter.import(source) end end |
#remove(feature) ⇒ Object
Public
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/flipper/adapters/instrumented.rb', line 54 def remove(feature) default_payload = { operation: :remove, adapter_name: @adapter.name, feature_name: feature.name, } @instrumenter.instrument(InstrumentationName, default_payload) do |payload| payload[:result] = @adapter.remove(feature) end end |