Class: Flipper::Adapters::Instrumented

Inherits:
Object
  • 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. Used by flipper dsl to provide instrumentatin for flipper.

Constant Summary collapse

InstrumentationName =

Private: The name of instrumentation events.

"adapter_operation.#{InstrumentationNamespace}"

Instance Attribute Summary collapse

Instance Method Summary collapse

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
# File 'lib/flipper/adapters/instrumented.rb', line 26

def initialize(adapter, options = {})
  @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



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

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

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

#clear(feature) ⇒ Object

Public



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

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

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

#disable(feature, gate, thing) ⇒ Object

Public



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/flipper/adapters/instrumented.rb', line 111

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

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

#enable(feature, gate, thing) ⇒ Object

Public



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

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

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

#featuresObject

Public



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

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

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

#get(feature) ⇒ Object

Public



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

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

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

#remove(feature) ⇒ Object

Public



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

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

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