class InfluxDBDataHarvester
InfluxdbDataHarvester sends rspec result data to a database (InfluxDB) Allows aggregating the results of Rspec tests in one location.
Attributes
database_client[R]
Public Class Methods
new(database: 'master', host: '127.0.0.1')
click to toggle source
# File lib/influxdb_data_harvester.rb, line 11 def initialize(database: 'master', host: '127.0.0.1') @database_client = InfluxDB::Client.new database: database, host: host, time_precision: 'u' end
Public Instance Methods
generate_payload(example, extra_data: nil, tags: nil)
click to toggle source
# File lib/influxdb_data_harvester.rb, line 17 def generate_payload(example, extra_data: nil, tags: nil) # Rspec status is populated when the rspec after hooks complete, wait until then Timeout.timeout(5) { sleep 0.0001 while example.execution_result.status.nil? } data = default_data(example) data[:values].merge! extra_data if extra_data data[:tags] = tags if tags data end
queue_send_data(example, series: 'test_results', extra_data: nil, tags: nil)
click to toggle source
# File lib/influxdb_data_harvester.rb, line 27 def queue_send_data(example, series: 'test_results', extra_data: nil, tags: nil) Concurrent::Promise.execute { send_data(example, series, extra_data: extra_data, tags: tags) } end
Private Instance Methods
default_data(example)
click to toggle source
# File lib/influxdb_data_harvester.rb, line 33 def default_data(example) { values: { duration: example.execution_result.run_time, result: example.execution_result.status.to_s, name: example.metadata[:full_description], source_environment: source_environment } } end
send_data(example, series, extra_data: nil, tags: nil)
click to toggle source
# File lib/influxdb_data_harvester.rb, line 42 def send_data(example, series, extra_data: nil, tags: nil) return if source_environment == 'bitbucket' data = generate_payload(example, extra_data: extra_data, tags: tags) @database_client.write_point(series, data) end
source_environment()
click to toggle source
# File lib/influxdb_data_harvester.rb, line 49 def source_environment ENV['source_environment'] ||= 'local' end