Class: Flipper::Adapters::Instrumented

Inherits:
SimpleDelegator
  • Object
show all
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

Instance Method Summary collapse

Methods included from Flipper::Adapter

#default_config, #import, included

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.


26
27
28
29
30
31
# File 'lib/flipper/adapters/instrumented.rb', line 26

def initialize(adapter, options = {})
  super(adapter)
  @adapter = adapter
  @name = :instrumented
  @instrumenter = options.fetch(:instrumenter, Instrumenters::Noop)
end

Instance Attribute Details

#instrumenterObject (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

#nameObject (readonly)

Public: The name of the adapter.



17
18
19
# File 'lib/flipper/adapters/instrumented.rb', line 17

def name
  @name
end

Instance Method Details

#add(feature) ⇒ Object

Public



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/flipper/adapters/instrumented.rb', line 46

def add(feature)
  payload = {
    operation: :add,
    adapter_name: @adapter.name,
    feature_name: feature.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) do |payload|
    payload[:result] = @adapter.add(feature)
  end
end

#clear(feature) ⇒ Object

Public



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/flipper/adapters/instrumented.rb', line 72

def clear(feature)
  payload = {
    operation: :clear,
    adapter_name: @adapter.name,
    feature_name: feature.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) do |payload|
    payload[:result] = @adapter.clear(feature)
  end
end

#disable(feature, gate, thing) ⇒ Object

Public



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/flipper/adapters/instrumented.rb', line 135

def disable(feature, gate, thing)
  payload = {
    operation: :disable,
    adapter_name: @adapter.name,
    feature_name: feature.name,
    gate_name: gate.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) do |payload|
    payload[:result] = @adapter.disable(feature, gate, thing)
  end
end

#enable(feature, gate, thing) ⇒ Object

Public



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/flipper/adapters/instrumented.rb', line 121

def enable(feature, gate, thing)
  payload = {
    operation: :enable,
    adapter_name: @adapter.name,
    feature_name: feature.name,
    gate_name: gate.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) do |payload|
    payload[:result] = @adapter.enable(feature, gate, thing)
  end
end

#featuresObject

Public



34
35
36
37
38
39
40
41
42
43
# File 'lib/flipper/adapters/instrumented.rb', line 34

def features
  payload = {
    operation: :features,
    adapter_name: @adapter.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) do |payload|
    payload[:result] = @adapter.features
  end
end

#get(feature) ⇒ Object

Public



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/flipper/adapters/instrumented.rb', line 85

def get(feature)
  payload = {
    operation: :get,
    adapter_name: @adapter.name,
    feature_name: feature.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) do |payload|
    payload[:result] = @adapter.get(feature)
  end
end

#get_allObject



109
110
111
112
113
114
115
116
117
118
# File 'lib/flipper/adapters/instrumented.rb', line 109

def get_all
  payload = {
    operation: :get_all,
    adapter_name: @adapter.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) do |payload|
    payload[:result] = @adapter.get_all
  end
end

#get_multi(features) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/flipper/adapters/instrumented.rb', line 97

def get_multi(features)
  payload = {
    operation: :get_multi,
    adapter_name: @adapter.name,
    feature_names: features.map(&:name),
  }

  @instrumenter.instrument(InstrumentationName, payload) do |payload|
    payload[:result] = @adapter.get_multi(features)
  end
end

#remove(feature) ⇒ Object

Public



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/flipper/adapters/instrumented.rb', line 59

def remove(feature)
  payload = {
    operation: :remove,
    adapter_name: @adapter.name,
    feature_name: feature.name,
  }

  @instrumenter.instrument(InstrumentationName, payload) do |payload|
    payload[:result] = @adapter.remove(feature)
  end
end