Class: MetricsProcessor

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

Defined Under Namespace

Classes: FrequencyMap

Constant Summary collapse

GLOBAL_TARGET =
Target.new(identifier: "__global__cf_target", name: "Global Target").freeze

Instance Method Summary collapse

Instance Method Details

#closeObject



110
111
112
113
# File 'lib/ff/ruby/server/sdk/api/metrics_processor.rb', line 110

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

#init(connector, config, callback) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ff/ruby/server/sdk/api/metrics_processor.rb', line 48

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"

  @executor = Concurrent::FixedThreadPool.new(10)

  # Used for locking the evalution and target metrics maps before we clone them
  @metric_maps_mutex = Mutex.new
  @evaluation_metrics = FrequencyMap.new
  @target_metrics = Concurrent::Map.new

  # Keep track of targets that have already been sent to avoid sending them again
  @seen_targets = Concurrent::Map.new

  @max_buffer_size = config.buffer_size - 1

  # Max 100k targets per interval
  @max_targets_buffer_size = 100000

  @evaluation_warning_issued = Concurrent::AtomicBoolean.new
  @target_warning_issued = Concurrent::AtomicBoolean.new

  @callback.on_metrics_ready
end

#register_evaluation(target, feature_config, variation) ⇒ Object



115
116
117
118
119
120
# File 'lib/ff/ruby/server/sdk/api/metrics_processor.rb', line 115

def register_evaluation(target, feature_config, variation)
  register_evaluation_metric(feature_config, variation)
  if target
    register_target_metric(target)
  end
end

#startObject



100
101
102
103
# File 'lib/ff/ruby/server/sdk/api/metrics_processor.rb', line 100

def start
  @config.logger.debug "Starting metrics processor with request interval: " + @config.frequency.to_s
  start_async
end

#stopObject



105
106
107
108
# File 'lib/ff/ruby/server/sdk/api/metrics_processor.rb', line 105

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