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.


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

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.



15
16
17
# File 'lib/flipper/adapters/instrumented.rb', line 15

def instrumenter
  @instrumenter
end

#nameObject (readonly)

Public: The name of the adapter.



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

def name
  @name
end

Instance Method Details

#add(feature) ⇒ Object

Public



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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