class Flipper::Instrumentation::Subscriber

Constants

QUESTION_MARK

Public Class Methods

call(name, start, ending, transaction_id, payload) click to toggle source

Public: Use this as the subscribed block.

# 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
new(name, start, ending, transaction_id, payload) click to toggle source

Private: Initializes a new event processing instance.

# 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

Public Instance Methods

strip_trailing_question_mark(operation) click to toggle source

Private

# File lib/flipper/instrumentation/subscriber.rb, line 78
def strip_trailing_question_mark(operation)
  operation.to_s.chomp(QUESTION_MARK)
end
update() click to toggle source

Private

# 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_metrics() click to toggle source

Private

# File lib/flipper/instrumentation/subscriber.rb, line 65
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) click to toggle source

Internal: Override in subclass.

# File lib/flipper/instrumentation/subscriber.rb, line 25
def update_counter(_metric)
  raise 'not implemented'
end
update_feature_operation_metrics() click to toggle source

Private

# File lib/flipper/instrumentation/subscriber.rb, line 43
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) click to toggle source

Internal: Override in subclass.

# File lib/flipper/instrumentation/subscriber.rb, line 20
def update_timer(_metric)
  raise 'not implemented'
end