coverband-service-client 0.0.12.rc → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b21c24a8ca01191ebb807640f09555b360ba6f0333b86d6e0c109387832bb35a
4
- data.tar.gz: 7657f2a6942d2474d196f470c1fbaca8b069ae49619c483e8e0e2c1787b39410
3
+ metadata.gz: 6391e88b97c48592f2adcaa31d2870589fc5a370e23a9fa12dba5d9c5344016a
4
+ data.tar.gz: cabef455a4fbe75afa34d28a6f24686cd536bb1fded5745fd35987425a925512
5
5
  SHA512:
6
- metadata.gz: ef97e09b88610ae38f45295e650e8b79b5cdaf77e46d616753ffcc1aa98cb34f5f0267b30a1ca7dc3a859df55f9b4305b150e7412dc05ad1062504777be819d2
7
- data.tar.gz: c4cae237dd5fbf03da3ddb8061ee76cc597e5fcc44d45b6351d2a2fad646bf6f4e3ff035dd9dba803e4cb70c421bfeeea1b09544dcb4d837b9ad9135d7bec1cc
6
+ metadata.gz: 2d2e149104351ff97918e921875044d6d05cf1ce5d0fd5ca7456a09892d65b659c0d771b7a5d61353aa5985e78c6bb96b0af8bbe8d77781a640586a1873d9e3c
7
+ data.tar.gz: 8a44da13a736a3f47935b38d3a59591a62b31471559842bc6ac9cfab2fa2d6b5d3019a5fbb173bd3bced1c387c92d79588bb57b447a5c0fd986a442c0f79b6db
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coverband-service-client (0.0.12.rc)
4
+ coverband-service-client (0.0.12)
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
@@ -10,11 +10,12 @@ require 'securerandom'
10
10
  module Coverband
11
11
  COVERBAND_ENV = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || (defined?(Rails) ? Rails.env : 'unknown')
12
12
  COVERBAND_SERVICE_URL = ENV['COVERBAND_URL'] || 'https://coverband.io'
13
- COVERBAND_TIMEOUT = (COVERBAND_ENV == 'development') ? 5 : 1
13
+ COVERBAND_TIMEOUT = (COVERBAND_ENV == 'development') ? 5 : 2
14
14
  COVERBAND_ENABLE_DEV_MODE = ENV['COVERBAND_ENABLE_DEV_MODE'] || false
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) ||
@@ -39,14 +40,36 @@ module Coverband
39
40
  # * currently JSON, but likely better to move to something faster
40
41
  ###
41
42
  class Service < Base
42
- attr_reader :coverband_url, :process_type, :runtime_env, :hostname, :pid
43
+ attr_reader :coverband_url, :process_type, :runtime_env, :hostname, :pid, :stats
43
44
 
44
45
  def initialize(coverband_url, opts = {})
45
46
  super()
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 = []
53
+ initialize_stats
54
+ end
55
+
56
+ def initialize_stats
57
+ return unless ENV['COVERBAND_STATS_KEY']
58
+ return unless defined?(Dogapi::Client)
59
+
60
+ @stats = Dogapi::Client.new(ENV['COVERBAND_STATS_KEY'])
61
+ @app_name = defined?(Rails) ? Rails.application.class.module_parent.to_s : "unknown"
62
+ end
63
+
64
+ def report_timing(timing)
65
+ return unless @stats
66
+
67
+ @stats.emit_point(
68
+ 'coverband.save.time',
69
+ timing,
70
+ host: hostname,
71
+ device: "coverband_#{self.class.name.split("::").last}",
72
+ options: {tags: [runtime_env]})
50
73
  end
51
74
 
52
75
  def logger
@@ -110,7 +133,12 @@ module Coverband
110
133
  file_coverage: data
111
134
  }
112
135
  }
136
+
137
+ starting = Process.clock_gettime(Process::CLOCK_MONOTONIC) if @stats
113
138
  save_coverage(full_package)
139
+ ending = Process.clock_gettime(Process::CLOCK_MONOTONIC) if @stats
140
+ report_timing((ending - starting)) if @stats
141
+ retry_failed_reports
114
142
  end&.join
115
143
  end
116
144
 
@@ -120,20 +148,48 @@ module Coverband
120
148
 
121
149
  private
122
150
 
151
+ def retry_failed_reports
152
+ retries = []
153
+ @failed_coverage_reports.any? do
154
+ report_body = arr.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
+
123
172
  def save_coverage(data)
124
173
  if api_key.nil?
125
174
  puts "Coverband: Error: no Coverband API key was found!"
126
175
  return
127
176
  end
128
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)
129
186
  uri = URI("#{coverband_url}/api/collector")
130
- req = Net::HTTP::Post.new(uri,
187
+ req = ::Net::HTTP::Post.new(uri,
131
188
  'Content-Type' => 'application/json',
132
189
  'Coverband-Token' => api_key)
133
- req.body = { remote_uuid: SecureRandom.uuid, data: data }.to_json
134
-
190
+ req.body = coverage_body
135
191
  logger&.info "Coverband: saving (#{uri}) #{req.body}" if Coverband.configuration.verbose
136
- res = Net::HTTP.start(
192
+ res = ::Net::HTTP.start(
137
193
  uri.hostname,
138
194
  uri.port,
139
195
  open_timeout: COVERBAND_TIMEOUT,
@@ -143,19 +199,24 @@ module Coverband
143
199
  ) do |http|
144
200
  http.request(req)
145
201
  end
146
- rescue StandardError => e
147
- 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
148
205
  end
149
206
  end
150
207
 
151
208
  class PersistentService < Service
152
- attr_reader :http
209
+ attr_reader :http, :stats
153
210
 
154
211
  def initialize(coverband_url, opts = {})
155
212
  super
156
213
  initiate_http
157
214
  end
158
215
 
216
+ def recommended_timeout
217
+ puts Net::HTTP::Persistent.detect_idle_timeout URI("#{coverband_url}/api/collector")
218
+ end
219
+
159
220
  private
160
221
 
161
222
  def initiate_http
@@ -164,7 +225,13 @@ module Coverband
164
225
  @http.headers['Coverband-Token'] = api_key
165
226
  @http.open_timeout = COVERBAND_TIMEOUT
166
227
  @http.read_timeout = COVERBAND_TIMEOUT
167
- @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
168
235
  end
169
236
 
170
237
  def save_coverage(data)
@@ -269,7 +336,7 @@ end
269
336
  ENV['COVERBAND_DISABLE_AUTO_START'] = COVERBAND_ORIGINAL_START
270
337
  Coverband.configure do |config|
271
338
  # Use the Service Adapter
272
- if defined?(Net::HTTP::Persistent)
339
+ if Coverband::COVERBAND_PERSISTENT_HTTP && defined?(Net::HTTP::Persistent)
273
340
  config.store = Coverband::Adapters::PersistentService.new(Coverband::COVERBAND_SERVICE_URL)
274
341
  else
275
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'
4
+ VERSION = '0.0.12'
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
4
+ version: 0.0.12
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-15 00:00:00.000000000 Z
12
+ date: 2020-06-28 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: