Class: Unleash::MetricsReporter
- Inherits:
-
Object
- Object
- Unleash::MetricsReporter
- Defined in:
- lib/unleash/metrics_reporter.rb
Constant Summary collapse
- LONGEST_WITHOUT_A_REPORT =
600
Instance Attribute Summary collapse
-
#last_time ⇒ Object
Returns the value of attribute last_time.
Instance Method Summary collapse
- #generate_report ⇒ Object
-
#initialize ⇒ MetricsReporter
constructor
A new instance of MetricsReporter.
- #post ⇒ Object
Constructor Details
#initialize ⇒ MetricsReporter
Returns a new instance of MetricsReporter.
12 13 14 |
# File 'lib/unleash/metrics_reporter.rb', line 12 def initialize self.last_time = Time.now end |
Instance Attribute Details
#last_time ⇒ Object
Returns the value of attribute last_time.
10 11 12 |
# File 'lib/unleash/metrics_reporter.rb', line 10 def last_time @last_time end |
Instance Method Details
#generate_report ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/unleash/metrics_reporter.rb', line 16 def generate_report metrics = Unleash&.engine&.get_metrics() { 'platformName': RUBY_ENGINE, 'platformVersion': RUBY_VERSION, 'yggdrasilVersion': "0.13.3", 'specVersion': Unleash::CLIENT_SPECIFICATION_VERSION, 'appName': Unleash.configuration.app_name, 'instanceId': Unleash.configuration.instance_id, 'bucket': metrics || {} } end |
#post ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/unleash/metrics_reporter.rb', line 30 def post Unleash.logger.debug "post() Report" report = self.generate_report if report[:bucket].empty? && (Time.now - self.last_time < LONGEST_WITHOUT_A_REPORT) # and last time is less then 10 minutes... Unleash.logger.debug "Report not posted to server, as it would have been empty. (and has been empty for up to 10 min)" return end response = Unleash::Util::Http.post(Unleash.configuration.client_metrics_uri, report.to_json) if ['200', '202'].include? response.code Unleash.logger.debug "Report sent to unleash server successfully. Server responded with http code #{response.code}" else # :nocov: Unleash.logger.error "Error when sending report to unleash server. Server responded with http code #{response.code}." # :nocov: end end |