Class: MetricsProcessor

Inherits:
Closeable show all
Defined in:
lib/ff/ruby/server/sdk/api/metrics_processor.rb

Instance Method Summary collapse

Instance Method Details

#closeObject



73
74
75
76
# File 'lib/ff/ruby/server/sdk/api/metrics_processor.rb', line 73

def close
  stop
  @config.logger.debug "Closing metrics processor"
end

#init(connector, config, callback) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ff/ruby/server/sdk/api/metrics_processor.rb', line 12

def init(connector, config, callback)

  unless connector.kind_of?(Connector)
    raise "The 'connector' must be of '" + Connector.to_s + "' data type"
  end

  unless callback.kind_of?(MetricsCallback)
    raise "The 'callback' must be of '" + MetricsCallback.to_s + "' data type"
  end

  unless config.kind_of?(Config)
    raise "The 'config' must be of '" + Config.to_s + "' data type"
  end

  @config = config
  @callback = callback
  @connector = connector

  @sdk_type = "SDK_TYPE"
  @target_attribute = "target"
  @global_target_identifier = "__global__cf_target" # <--- This target identifier is used to aggregate and send data for all
  #                                             targets as a summary
  @ready = false
  @jar_version = Ff::Ruby::Server::Sdk::VERSION
  @server = "server"
  @sdk_version = "SDK_VERSION"
  @sdk_language = "SDK_LANGUAGE"
  @global_target_name = "Global Target"
  @feature_name_attribute = "featureName"
  @variation_identifier_attribute = "variationIdentifier"

  # Evaluation and target metrics
  @metric_maps_mutex = Mutex.new
  @evaluation_metrics = {}
  @target_metrics = {}
  @target_metrics_max_payload = 1000

  # Keep track of targets that have already been sent to avoid sending them again. We track a max 500K targets
  # to prevent unbounded growth.
  @seen_targets_mutex = Mutex.new
  @seen_targets = Set.new

  # Mutex to protect aggregation and sending metrics at the end of an interval
  @send_data_mutex = Mutex.new

  @callback.on_metrics_ready
end

#register_evaluation(target, feature_name, variation_identifier) ⇒ Object



78
79
80
81
82
83
# File 'lib/ff/ruby/server/sdk/api/metrics_processor.rb', line 78

def register_evaluation(target, feature_name, variation_identifier)
  register_evaluation_metric(feature_name, variation_identifier)
  if target
    register_target_metric(target)
  end
end

#startObject



60
61
62
63
64
65
66
67
# File 'lib/ff/ruby/server/sdk/api/metrics_processor.rb', line 60

def start
  @config.logger.debug "Starting metrics processor with request interval: #{@config.frequency}"
  if @running
    @config.logger.warn "Metrics processor is already running."
  else
    start_async
  end
end

#stopObject



68
69
70
71
# File 'lib/ff/ruby/server/sdk/api/metrics_processor.rb', line 68

def stop
  @config.logger.debug "Stopping metrics processor"
  stop_async
end