Class: Flipper::Instrumentation::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/flipper/instrumentation/subscriber.rb

Direct Known Subclasses

MetriksSubscriber, StatsdSubscriber

Constant Summary collapse

QUESTION_MARK =
"?".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, start, ending, transaction_id, payload) ⇒ Subscriber

Private: Initializes a new event processing instance.



10
11
12
13
14
15
16
17
# File 'lib/flipper/instrumentation/subscriber.rb', line 10

def initialize(name, start, ending, transaction_id, payload)
  @name = name
  @start = start
  @ending = ending
  @payload = payload
  @duration = ending - start
  @transaction_id = transaction_id
end

Class Method Details

.call(name, start, ending, transaction_id, payload) ⇒ Object

Public: Use this as the subscribed block.



5
6
7
# File 'lib/flipper/instrumentation/subscriber.rb', line 5

def self.call(name, start, ending, transaction_id, payload)
  new(name, start, ending, transaction_id, payload).update
end

Instance Method Details

#strip_trailing_question_mark(operation) ⇒ Object

Private



77
78
79
# File 'lib/flipper/instrumentation/subscriber.rb', line 77

def strip_trailing_question_mark(operation)
  operation.to_s.chomp(QUESTION_MARK)
end

#updateObject

Private



30
31
32
33
34
35
36
37
38
39
# File 'lib/flipper/instrumentation/subscriber.rb', line 30

def update
  operation_type = @name.split('.').first
  method_name = "update_#{operation_type}_metrics"

  if respond_to?(method_name)
    send(method_name)
  else
    puts "Could not update #{operation_type} metrics as #{self.class} did not respond to `#{method_name}`"
  end
end

#update_adapter_operation_metricsObject

Private



63
64
65
66
67
68
69
70
71
72
# File 'lib/flipper/instrumentation/subscriber.rb', line 63

def update_adapter_operation_metrics
  adapter_name = @payload[:adapter_name]
  operation = @payload[:operation]
  result = @payload[:result]
  value = @payload[:value]
  key = @payload[:key]


  update_timer "flipper.adapter.#{adapter_name}.#{operation}"
end

#update_counter(metric) ⇒ Object

Internal: Override in subclass.



25
26
27
# File 'lib/flipper/instrumentation/subscriber.rb', line 25

def update_counter(metric)
  raise 'not implemented'
end

#update_feature_operation_metricsObject

Private



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/flipper/instrumentation/subscriber.rb', line 42

def update_feature_operation_metrics
  feature_name = @payload[:feature_name]
  gate_name = @payload[:gate_name]
  operation = strip_trailing_question_mark(@payload[:operation])
  result = @payload[:result]
  thing = @payload[:thing]

  update_timer "flipper.feature_operation.#{operation}"

  if @payload[:operation] == :enabled?
    metric_name = if result
      "flipper.feature.#{feature_name}.enabled"
    else
      "flipper.feature.#{feature_name}.disabled"
    end

    update_counter metric_name
  end
end

#update_timer(metric) ⇒ Object

Internal: Override in subclass.



20
21
22
# File 'lib/flipper/instrumentation/subscriber.rb', line 20

def update_timer(metric)
  raise 'not implemented'
end