coverband-service-client 0.0.12.rc.1 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b93d9abe50ba1657318562b8fa04b645cfdd2fc22bca0f711cbde57b6d6b3c7
4
- data.tar.gz: 1918f4689b50c6bda5b51d2f578b13b4bf439d38fb3510318165152b9093f1d2
3
+ metadata.gz: c97032af48a5f514b402bc6a7e264e569cf3e48840c89f07ce3f6988fdc6268d
4
+ data.tar.gz: 81a94696c8e8a2063ad14c0f70cd7ec72d6eb3e764e4129be285d73f833c8622
5
5
  SHA512:
6
- metadata.gz: 33c461c2915ef4f9582fd8f87b5b2afa230076f1349e88ef7f66987cb1a8dda25d97c26983421ca52f900c3dd2d48d313e44dd69a8b15984a349dbe3fe4b3fd9
7
- data.tar.gz: 0ea1b378ae8044400d50ad33944881d27552b42296cae06ceda360617b30d26a9bb3614e6a81c10b0bd530bcf59ca10ef9be3fba928e4c98b2f22929c21f4a66
6
+ metadata.gz: f4c13d0a8be84242cc7ff8deec7e482dede3a7d7817fb9f059bc3a73b03eb8cb75f6cba0a73432227561b551a56580fc04651bffd3fe09f4eb84a09b6622ff7a
7
+ data.tar.gz: f95d13fc5b3897c79036e36534531ca4ce0cede25ae132f8425b0cb981e5f3c53af91a8557561df2f7c1617750da48638ccbc46130e9d74b66be436e29a68888
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coverband-service-client (0.0.12.rc.1)
4
+ coverband-service-client (0.0.13)
5
5
  coverband (~> 4.2.4)
6
6
 
7
7
  GEM
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+
5
+ ENV['COVERBAND_ENABLE_DEV_MODE'] = 'true'
6
+ ENV['COVERBAND_ENABLE_TEST_MODE'] = 'true'
7
+ ENV['PROCESS_TYPE'] = 'debug'
8
+ ENV['COVERBAND_REPORT_PERIOD'] = '30'
9
+ ENV['COVERBAND_API_KEY'] ||= 'set this'
10
+ ENV['COVERBAND_STATS_KEY'] ||='set this'
11
+
12
+ require "pry-byebug";
13
+ require "dogapi";
14
+ require "net/http/persistent";
15
+ # require "httplog";
16
+ require 'benchmark'
17
+
18
+ require_relative "../lib/coverband-service-client"
19
+
20
+ # HttpLog.configure do |config|
21
+ # config.url_SAFElist_pattern = /coverband/
22
+ # end
23
+
24
+ data = {
25
+ 'app/helpers/posts_helper.rb' => [1, nil]
26
+ }
27
+
28
+ collector = Coverband::Collectors::Coverage.instance
29
+ store = Coverband.configuration.store
30
+
31
+ # What is the recommended timeout against the target, from the lib
32
+ # puts store.recommended_timeout
33
+
34
+ Benchmark.bmbm do |x|
35
+ x.report("connection") do
36
+ 30.times do
37
+ store.save_report(data)
38
+ end
39
+ end
40
+ end
41
+
42
+ puts "done"
@@ -28,6 +28,14 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.add_development_dependency "bundler", "~> 2.0"
30
30
  spec.add_development_dependency "rake", "~> 13.0"
31
+
32
+ # For benchmarking stats
33
+ # spec.add_development_dependency "pry-byebug"
34
+ # spec.add_development_dependency "dogapi"
35
+ # spec.add_development_dependency "httplog"
36
+ # # to benchmark persistent connections
37
+ # spec.add_development_dependency "net-http-persistent"
38
+
31
39
  spec.add_development_dependency "minitest", "~> 5.0"
32
40
  spec.add_runtime_dependency "coverband", "~> 4.2.4"
33
41
  end
@@ -15,6 +15,7 @@ module Coverband
15
15
  COVERBAND_ENABLE_TEST_MODE = ENV['COVERBAND_ENABLE_TEST_MODE'] || false
16
16
  COVERBAND_PROCESS_TYPE = ENV['PROCESS_TYPE'] || 'unknown'
17
17
  COVERBAND_REPORT_PERIOD = (ENV['COVERBAND_REPORT_PERIOD'] || 600).to_i
18
+ COVERBAND_PERSISTENT_HTTP = ENV['COVERBAND_PERSISTENT_HTTP'] || false
18
19
 
19
20
  def self.service_disabled_dev_test_env?
20
21
  (COVERBAND_ENV == 'test' && !COVERBAND_ENABLE_TEST_MODE) ||
@@ -46,7 +47,9 @@ module Coverband
46
47
  @coverband_url = coverband_url
47
48
  @process_type = opts.fetch(:process_type) { $PROGRAM_NAME&.split('/')&.last || COVERBAND_PROCESS_TYPE }
48
49
  @hostname = opts.fetch(:hostname) { ENV["DYNO"] || Socket.gethostname.force_encoding('utf-8').encode }
50
+ @hostname = @hostname.gsub("'",'').gsub("’",'')
49
51
  @runtime_env = opts.fetch(:runtime_env) { COVERBAND_ENV }
52
+ @failed_coverage_reports = []
50
53
  initialize_stats
51
54
  end
52
55
 
@@ -55,6 +58,7 @@ module Coverband
55
58
  return unless defined?(Dogapi::Client)
56
59
 
57
60
  @stats = Dogapi::Client.new(ENV['COVERBAND_STATS_KEY'])
61
+ @app_name = defined?(Rails) ? Rails.application.class.module_parent.to_s : "unknown"
58
62
  end
59
63
 
60
64
  def report_timing(timing)
@@ -64,8 +68,8 @@ module Coverband
64
68
  'coverband.save.time',
65
69
  timing,
66
70
  host: hostname,
67
- env: runtime_env,
68
- client: "coverband_#{self.class.name.split("::").last}")
71
+ device: "coverband_#{self.class.name.split("::").last}",
72
+ options: {tags: [runtime_env]})
69
73
  end
70
74
 
71
75
  def logger
@@ -130,10 +134,11 @@ module Coverband
130
134
  }
131
135
  }
132
136
 
133
- starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
137
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC) if @stats
134
138
  save_coverage(full_package)
135
- ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
136
- report_timing((ending - starting))
139
+ ending = Process.clock_gettime(Process::CLOCK_MONOTONIC) if @stats
140
+ report_timing((ending - starting)) if @stats
141
+ retry_failed_reports
137
142
  end&.join
138
143
  end
139
144
 
@@ -143,20 +148,48 @@ module Coverband
143
148
 
144
149
  private
145
150
 
151
+ def retry_failed_reports
152
+ retries = []
153
+ @failed_coverage_reports.any? do
154
+ report_body = @failed_coverage_reports.pop
155
+ send_report_body(report_body)
156
+ rescue StandardError
157
+ retries << report_body
158
+ end
159
+ retries.each do |report_body|
160
+ add_retry_message(report_body)
161
+ end
162
+ end
163
+
164
+ def add_retry_message(report_body)
165
+ if @failed_coverage_reports.length > 5
166
+ logger&.info "Coverband: The errored reporting queue has reached 5. Subsequent reports will not be transmitted"
167
+ else
168
+ @failed_coverage_reports << report_body
169
+ end
170
+ end
171
+
146
172
  def save_coverage(data)
147
173
  if api_key.nil?
148
174
  puts "Coverband: Error: no Coverband API key was found!"
149
175
  return
150
176
  end
151
177
 
178
+ coverage_body = { remote_uuid: SecureRandom.uuid, data: data }.to_json
179
+ send_report_body(coverage_body)
180
+ rescue StandardError => e
181
+ add_retry_message(coverage_body)
182
+ logger&.info "Coverband: Error while saving coverage #{e}" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE
183
+ end
184
+
185
+ def send_report_body(coverage_body)
152
186
  uri = URI("#{coverband_url}/api/collector")
153
- req = Net::HTTP::Post.new(uri,
187
+ req = ::Net::HTTP::Post.new(uri,
154
188
  'Content-Type' => 'application/json',
155
189
  'Coverband-Token' => api_key)
156
- req.body = { remote_uuid: SecureRandom.uuid, data: data }.to_json
157
-
190
+ req.body = coverage_body
158
191
  logger&.info "Coverband: saving (#{uri}) #{req.body}" if Coverband.configuration.verbose
159
- res = Net::HTTP.start(
192
+ res = ::Net::HTTP.start(
160
193
  uri.hostname,
161
194
  uri.port,
162
195
  open_timeout: COVERBAND_TIMEOUT,
@@ -166,8 +199,9 @@ module Coverband
166
199
  ) do |http|
167
200
  http.request(req)
168
201
  end
169
- rescue StandardError => e
170
- logger&.info "Coverband: Error while saving coverage #{e}" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE
202
+ if res.code.to_i >= 500
203
+ add_retry_message(coverage_body)
204
+ end
171
205
  end
172
206
  end
173
207
 
@@ -179,6 +213,10 @@ module Coverband
179
213
  initiate_http
180
214
  end
181
215
 
216
+ def recommended_timeout
217
+ puts Net::HTTP::Persistent.detect_idle_timeout URI("#{coverband_url}/api/collector")
218
+ end
219
+
182
220
  private
183
221
 
184
222
  def initiate_http
@@ -187,7 +225,13 @@ module Coverband
187
225
  @http.headers['Coverband-Token'] = api_key
188
226
  @http.open_timeout = COVERBAND_TIMEOUT
189
227
  @http.read_timeout = COVERBAND_TIMEOUT
190
- @http.ssl_timeout = COVERBAND_TIMEOUT
228
+ # the two below seem inconsistent in terms of how they are set
229
+ # leaving off for now
230
+ # @http.ssl_timeout = COVERBAND_TIMEOUT
231
+ # @http.write_timeout = COVERBAND_TIMEOUT
232
+ # default is 5-10 seconds but we report ever few min, heroku kills them
233
+ # before our reporting period... ;(
234
+ # @http.idle_timeout = 1000
191
235
  end
192
236
 
193
237
  def save_coverage(data)
@@ -292,7 +336,7 @@ end
292
336
  ENV['COVERBAND_DISABLE_AUTO_START'] = COVERBAND_ORIGINAL_START
293
337
  Coverband.configure do |config|
294
338
  # Use the Service Adapter
295
- if defined?(Net::HTTP::Persistent)
339
+ if Coverband::COVERBAND_PERSISTENT_HTTP && defined?(Net::HTTP::Persistent)
296
340
  config.store = Coverband::Adapters::PersistentService.new(Coverband::COVERBAND_SERVICE_URL)
297
341
  else
298
342
  config.store = Coverband::Adapters::Service.new(Coverband::COVERBAND_SERVICE_URL)
@@ -1,7 +1,7 @@
1
1
  module Coverband
2
2
  module Service
3
3
  module Client
4
- VERSION = '0.0.12.rc.1'
4
+ VERSION = '0.0.13'
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coverband-service-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12.rc.1
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Mayer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-06-20 00:00:00.000000000 Z
12
+ date: 2020-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -84,6 +84,7 @@ files:
84
84
  - Rakefile
85
85
  - bin/console
86
86
  - bin/setup
87
+ - bin/stats
87
88
  - changelog.md
88
89
  - coverband-service-client.gemspec
89
90
  - lib/coverband-service-client.rb
@@ -106,9 +107,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
107
  version: '0'
107
108
  required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  requirements:
109
- - - ">"
110
+ - - ">="
110
111
  - !ruby/object:Gem::Version
111
- version: 1.3.1
112
+ version: '0'
112
113
  requirements: []
113
114
  rubygems_version: 3.0.3
114
115
  signing_key: