coverband-service-client 0.0.11 → 0.0.12.rc

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: a0d326e9f18a89a72e6a251e92b1a2c4d99a44288c1e695570327675017e5328
4
- data.tar.gz: 83efe304d0dac5797b63ad4dea23516df89ab211a0aa5809554c9b3fce5dfa82
3
+ metadata.gz: b21c24a8ca01191ebb807640f09555b360ba6f0333b86d6e0c109387832bb35a
4
+ data.tar.gz: 7657f2a6942d2474d196f470c1fbaca8b069ae49619c483e8e0e2c1787b39410
5
5
  SHA512:
6
- metadata.gz: 3588eb3a0fc1c70afa925b61feaf92ee95b7169476e0008abac2ee83413a7ad0a02726876fda490089fb2008d17861f71cebd297dc78744de049fc62a82c2022
7
- data.tar.gz: ee29788c3d877f9cd0079615c30da437490cc3a4c6fb74ed7a0454d44b405ef041965c648b4e3d5162f775c13d8661165c578fa57993de090d39be253f34a139
6
+ metadata.gz: ef97e09b88610ae38f45295e650e8b79b5cdaf77e46d616753ffcc1aa98cb34f5f0267b30a1ca7dc3a859df55f9b4305b150e7412dc05ad1062504777be819d2
7
+ data.tar.gz: c4cae237dd5fbf03da3ddb8061ee76cc597e5fcc44d45b6351d2a2fad646bf6f4e3ff035dd9dba803e4cb70c421bfeeea1b09544dcb4d837b9ad9135d7bec1cc
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coverband-service-client (0.0.11)
4
+ coverband-service-client (0.0.12.rc)
5
5
  coverband (~> 4.2.4)
6
6
 
7
7
  GEM
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ require 'socket'
2
3
 
3
4
  COVERBAND_ORIGINAL_START = ENV['COVERBAND_DISABLE_AUTO_START']
4
5
  ENV['COVERBAND_DISABLE_AUTO_START'] = 'true'
@@ -35,15 +36,16 @@ module Coverband
35
36
  #
36
37
  # NOTES:
37
38
  # * uses net/http to avoid any dependencies
38
- # * currently JSON, but likely better to move to something simpler / faster
39
+ # * currently JSON, but likely better to move to something faster
39
40
  ###
40
41
  class Service < Base
41
- attr_reader :coverband_url, :process_type, :runtime_env
42
+ attr_reader :coverband_url, :process_type, :runtime_env, :hostname, :pid
42
43
 
43
44
  def initialize(coverband_url, opts = {})
44
45
  super()
45
46
  @coverband_url = coverband_url
46
- @process_type = opts.fetch(:process_type) { COVERBAND_PROCESS_TYPE }
47
+ @process_type = opts.fetch(:process_type) { $PROGRAM_NAME&.split('/')&.last || COVERBAND_PROCESS_TYPE }
48
+ @hostname = opts.fetch(:hostname) { ENV["DYNO"] || Socket.gethostname.force_encoding('utf-8').encode }
47
49
  @runtime_env = opts.fetch(:runtime_env) { COVERBAND_ENV }
48
50
  end
49
51
 
@@ -68,6 +70,9 @@ module Coverband
68
70
  ENV['COVERBAND_API_KEY'] || Coverband.configuration.api_key
69
71
  end
70
72
 
73
+ ###
74
+ # Fetch coverband coverage via the API
75
+ ###
71
76
  def coverage(local_type = nil, opts = {})
72
77
  local_type ||= opts.key?(:override_type) ? opts[:override_type] : type
73
78
  env_filter = opts.key?(:env_filter) ? opts[:env_filter] : 'production'
@@ -85,8 +90,11 @@ module Coverband
85
90
  def save_report(report)
86
91
  return if report.empty?
87
92
 
93
+ # We set here vs initialize to avoid setting on the primary process vs child processes
94
+ @pid ||= ::Process.pid
95
+
88
96
  # TODO: do we need dup
89
- # TODO: remove timestamps, server will track first_seen
97
+ # TODO: remove upstream timestamps, server will track first_seen
90
98
  Thread.new do
91
99
  data = expand_report(report.dup)
92
100
  full_package = {
@@ -95,7 +103,9 @@ module Coverband
95
103
  tags: {
96
104
  process_type: process_type,
97
105
  app_loading: type == Coverband::EAGER_TYPE,
98
- runtime_env: runtime_env
106
+ runtime_env: runtime_env,
107
+ pid: pid,
108
+ hostname: hostname,
99
109
  },
100
110
  file_coverage: data
101
111
  }
@@ -113,6 +123,7 @@ module Coverband
113
123
  def save_coverage(data)
114
124
  if api_key.nil?
115
125
  puts "Coverband: Error: no Coverband API key was found!"
126
+ return
116
127
  end
117
128
 
118
129
  uri = URI("#{coverband_url}/api/collector")
@@ -136,6 +147,50 @@ module Coverband
136
147
  logger&.info "Coverband: Error while saving coverage #{e}" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE
137
148
  end
138
149
  end
150
+
151
+ class PersistentService < Service
152
+ attr_reader :http
153
+
154
+ def initialize(coverband_url, opts = {})
155
+ super
156
+ initiate_http
157
+ end
158
+
159
+ private
160
+
161
+ def initiate_http
162
+ @http = Net::HTTP::Persistent.new name: 'coverband_persistent'
163
+ @http.headers['Content-Type'] = 'application/json'
164
+ @http.headers['Coverband-Token'] = api_key
165
+ @http.open_timeout = COVERBAND_TIMEOUT
166
+ @http.read_timeout = COVERBAND_TIMEOUT
167
+ @http.ssl_timeout = COVERBAND_TIMEOUT
168
+ end
169
+
170
+ def save_coverage(data)
171
+ persistent_attempts = 0
172
+ begin
173
+ if api_key.nil?
174
+ puts "Coverband: Error: no Coverband API key was found!"
175
+ return
176
+ end
177
+
178
+ post_uri = URI("#{coverband_url}/api/collector")
179
+ post = Net::HTTP::Post.new post_uri.path
180
+ body = { remote_uuid: SecureRandom.uuid, data: data }.to_json
181
+ post.body = body
182
+ logger&.info "Coverband: saving (#{post_uri}) #{body}" if Coverband.configuration.verbose
183
+ res = http.request post_uri, post
184
+ rescue Net::HTTP::Persistent::Error => e
185
+ persistent_attempts += 1
186
+ http.shutdown
187
+ initiate_http
188
+ retry if persistent_attempts < 2
189
+ end
190
+ rescue StandardError => e
191
+ logger&.info "Coverband: Error while saving coverage #{e}" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE
192
+ end
193
+ end
139
194
  end
140
195
 
141
196
  module Service
@@ -213,8 +268,12 @@ end
213
268
 
214
269
  ENV['COVERBAND_DISABLE_AUTO_START'] = COVERBAND_ORIGINAL_START
215
270
  Coverband.configure do |config|
216
- # Use The Test Service Adapter
217
- config.store = Coverband::Adapters::Service.new(Coverband::COVERBAND_SERVICE_URL)
271
+ # Use the Service Adapter
272
+ if defined?(Net::HTTP::Persistent)
273
+ config.store = Coverband::Adapters::PersistentService.new(Coverband::COVERBAND_SERVICE_URL)
274
+ else
275
+ config.store = Coverband::Adapters::Service.new(Coverband::COVERBAND_SERVICE_URL)
276
+ end
218
277
 
219
278
  # default to tracking views true
220
279
  config.track_views = if ENV['COVERBAND_DISABLE_VIEW_TRACKER']
@@ -1,7 +1,7 @@
1
1
  module Coverband
2
2
  module Service
3
3
  module Client
4
- VERSION = '0.0.11'
4
+ VERSION = '0.0.12.rc'
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.11
4
+ version: 0.0.12.rc
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-05-26 00:00:00.000000000 Z
12
+ date: 2020-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -106,9 +106,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ">="
109
+ - - ">"
110
110
  - !ruby/object:Gem::Version
111
- version: '0'
111
+ version: 1.3.1
112
112
  requirements: []
113
113
  rubygems_version: 3.0.3
114
114
  signing_key: