Module: ElasticResults
- Defined in:
- lib/elastic_results.rb,
lib/elastic_results/rspec.rb,
lib/elastic_results/result.rb,
lib/elastic_results/version.rb,
lib/elastic_results/cucumber.rb,
lib/elastic_results/simplecov.rb
Overview
Our root namespace for all objects
Defined Under Namespace
Modules: Cucumber, RSpec, SimpleCov Classes: Result
Constant Summary collapse
- VERSION =
'1.0.2'
Class Attribute Summary collapse
-
.build_id ⇒ Object
Returns the value of attribute build_id.
-
.es_index_coverage ⇒ Object
Returns the value of attribute es_index_coverage.
-
.es_index_result ⇒ Object
Returns the value of attribute es_index_result.
-
.es_log ⇒ Object
Returns the value of attribute es_log.
-
.es_type_coverage ⇒ Object
Returns the value of attribute es_type_coverage.
-
.es_type_result ⇒ Object
Returns the value of attribute es_type_result.
-
.es_url ⇒ Object
Returns the value of attribute es_url.
-
.google_api_key ⇒ Object
Returns the value of attribute google_api_key.
-
.kibana_url ⇒ Object
Returns the value of attribute kibana_url.
-
.suite_name ⇒ Object
Returns the value of attribute suite_name.
-
.suite_type ⇒ Object
Returns the value of attribute suite_type.
-
.team_name ⇒ Object
Returns the value of attribute team_name.
-
.use_unsafe_index ⇒ Object
Returns the value of attribute use_unsafe_index.
Class Method Summary collapse
-
.client ⇒ Object
Memoized instance of the elasticsearch client.
-
.fails_url ⇒ Object
Returns a link to the failures.
-
.index(index, type, payload) ⇒ Object
Generic index function that knows when to use the elasticsearch API.
-
.index_coverage(payload) ⇒ Object
Given a payload store it as coverage data.
-
.index_result(payload) ⇒ Object
Given a payload store it as a test result.
-
.mapping_for(which) ⇒ Object
Return the mapping JSON for used in creating indicies the which paramter should map to to a filename in the setup folder.
-
.results_url ⇒ Object
Returns a link to the results.
-
.unsafe_index(index, type, payload) ⇒ Object
An “unsafe” index routine which uses Net:HTTP with SSL validation turned off.
-
.write_urls(filename = 'build_links.txt') ⇒ Object
Write out a tab deliminated file containing links to the build information.
Class Attribute Details
.build_id ⇒ Object
Returns the value of attribute build_id.
23 24 25 |
# File 'lib/elastic_results.rb', line 23 def build_id @build_id end |
.es_index_coverage ⇒ Object
Returns the value of attribute es_index_coverage.
18 19 20 |
# File 'lib/elastic_results.rb', line 18 def es_index_coverage @es_index_coverage end |
.es_index_result ⇒ Object
Returns the value of attribute es_index_result.
17 18 19 |
# File 'lib/elastic_results.rb', line 17 def es_index_result @es_index_result end |
.es_log ⇒ Object
Returns the value of attribute es_log.
21 22 23 |
# File 'lib/elastic_results.rb', line 21 def es_log @es_log end |
.es_type_coverage ⇒ Object
Returns the value of attribute es_type_coverage.
20 21 22 |
# File 'lib/elastic_results.rb', line 20 def es_type_coverage @es_type_coverage end |
.es_type_result ⇒ Object
Returns the value of attribute es_type_result.
19 20 21 |
# File 'lib/elastic_results.rb', line 19 def es_type_result @es_type_result end |
.es_url ⇒ Object
Returns the value of attribute es_url.
16 17 18 |
# File 'lib/elastic_results.rb', line 16 def es_url @es_url end |
.google_api_key ⇒ Object
Returns the value of attribute google_api_key.
24 25 26 |
# File 'lib/elastic_results.rb', line 24 def google_api_key @google_api_key end |
.kibana_url ⇒ Object
Returns the value of attribute kibana_url.
25 26 27 |
# File 'lib/elastic_results.rb', line 25 def kibana_url @kibana_url end |
.suite_name ⇒ Object
Returns the value of attribute suite_name.
14 15 16 |
# File 'lib/elastic_results.rb', line 14 def suite_name @suite_name end |
.suite_type ⇒ Object
Returns the value of attribute suite_type.
15 16 17 |
# File 'lib/elastic_results.rb', line 15 def suite_type @suite_type end |
.team_name ⇒ Object
Returns the value of attribute team_name.
22 23 24 |
# File 'lib/elastic_results.rb', line 22 def team_name @team_name end |
.use_unsafe_index ⇒ Object
Returns the value of attribute use_unsafe_index.
26 27 28 |
# File 'lib/elastic_results.rb', line 26 def use_unsafe_index @use_unsafe_index end |
Class Method Details
.client ⇒ Object
Memoized instance of the elasticsearch client
37 38 39 |
# File 'lib/elastic_results.rb', line 37 def self.client @@client ||= Elasticsearch::Client.new url: ElasticResults.es_url, log: ElasticResults.es_log end |
.fails_url ⇒ Object
Returns a link to the failures. shortened URL if possible otherwise the full URL from long_fails_url.
100 101 102 103 104 105 106 107 |
# File 'lib/elastic_results.rb', line 100 def self.fails_url if ElasticResults.google_api_key.nil? long_fails_url else require 'googl' Googl.shorten(long_fails_url, '127.0.0.1', ElasticResults.google_api_key).short_url end end |
.index(index, type, payload) ⇒ Object
Generic index function that knows when to use the elasticsearch API.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/elastic_results.rb', line 52 def self.index(index, type, payload) begin with_disabled_mocks { if ElasticResults.use_unsafe_index unsafe_index index, type, payload.to_hash else client.index index: index, type: type, body: payload.to_hash end } rescue Exception => ex puts "#{ex.} while storing results in Elasticsearch" end end |
.index_coverage(payload) ⇒ Object
Given a payload store it as coverage data
47 48 49 |
# File 'lib/elastic_results.rb', line 47 def self.index_coverage(payload) index ElasticResults.es_index_coverage, ElasticResults.es_type_coverage, payload end |
.index_result(payload) ⇒ Object
Given a payload store it as a test result
42 43 44 |
# File 'lib/elastic_results.rb', line 42 def self.index_result(payload) index ElasticResults.es_index_result, ElasticResults.es_type_result, payload end |
.mapping_for(which) ⇒ Object
Return the mapping JSON for used in creating indicies the which paramter should map to to a filename in the setup folder
31 32 33 34 |
# File 'lib/elastic_results.rb', line 31 def self.mapping_for(which) setup_folder = File.('./elastic_results/setup', File.dirname(__FILE__)) File.read("#{setup_folder}/#{which.to_s}.json") end |
.results_url ⇒ Object
Returns a link to the results. shortened URL if possible otherwise the full URL from long_results_url.
90 91 92 93 94 95 96 97 |
# File 'lib/elastic_results.rb', line 90 def self.results_url if ElasticResults.google_api_key.nil? long_results_url else require 'googl' Googl.shorten(long_results_url, '127.0.0.1', ElasticResults.google_api_key).short_url end end |
.unsafe_index(index, type, payload) ⇒ Object
An “unsafe” index routine which uses Net:HTTP with SSL validation turned off. Needed for when WebMock is in use as it breaks SSL cert validations.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/elastic_results.rb', line 70 def self.unsafe_index(index, type, payload) uri = URI.parse(ElasticResults.es_url) http = Net::HTTP.new(uri.host, uri.port) if ElasticResults.es_url =~ /https/ http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end request = Net::HTTP::Post.new("/#{index}/#{type}") request.body = payload.to_json response = http.request(request) end |
.write_urls(filename = 'build_links.txt') ⇒ Object
Write out a tab deliminated file containing links to the build information
85 86 87 |
# File 'lib/elastic_results.rb', line 85 def self.write_urls(filename = 'build_links.txt') File.open(filename, 'w') { |file| file.write("View failures in Kibana\t#{ElasticResults.fails_url}\t\nView all results in Kibana\t#{ElasticResults.results_url}\t") } end |