coverband-service-client 0.0.2 → 0.0.3

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: 373190932f2c83d572f8d425fc31b69b370c1e10ade822afbbc5f4f08f9419f5
4
- data.tar.gz: d4739b9a741aa7295c132239363e3474bc0d23a4b2c39ee88b8bc53f5978fe0c
3
+ metadata.gz: 5d219bb2b70714142a0ff8e82b7257ced94f5c6151fdf2c2faf657ba6860c334
4
+ data.tar.gz: 00cdd6e48016c70b5a058ff93462ec8a3975c6b5a24ad4418b74d1f4d70d613c
5
5
  SHA512:
6
- metadata.gz: 455f17da5ba92d4be63f2cd332157283b8c000c1b0d7f4e4fd8b1009a09f69e8685661db9aaae8fb2560292b91cc22435fadc4618ae671534cda30e5b41cb4b3
7
- data.tar.gz: c8990a5ad84ea9051a15879125117ccb64fca8e7e520e68ee566e039ba27fc4fd071c9a92124eb71d426fd3b51e5f2a6cfaaaf03a257acc1f9a9a55f207f743f
6
+ metadata.gz: 5d10188e1d2ad65016cbdecbf0259f6ba6ef096a1379e64c739e298d9b73046a8f5d5f091ee015a0ae99fb9fde61a245e6aab218858aa73c38e11ab488c99e9a
7
+ data.tar.gz: 84a56afee2cf2c3b32f47a31f656caf23b0d3f3030a2b245536f912dd4edebc09e64b99e856198997efb93e16bb4b51d66d7eced5a1ecfb466cb9daa2a0c1904
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- coverband-service-client (0.0.2)
4
+ coverband-service-client (0.0.3)
5
5
  coverband (~> 4.2.4)
6
6
 
7
7
  GEM
@@ -3,6 +3,11 @@
3
3
  require 'coverband/service/client/version'
4
4
  require 'securerandom'
5
5
 
6
+ COVERBAND_ENV = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || (defined?(Rails) ? Rails.env : 'unknown')
7
+ COVERBAND_SERVICE_URL = ENV['COVERBAND_URL'] ||
8
+ ((COVERBAND_ENV == 'development') ? 'http://127.0.0.1:3456' : 'https://coverband-service.herokuapp.com')
9
+ # TODO: This id is still hard coded
10
+ COVERBAND_ID = ENV['COVERBAND_ID'] || 'coverband-service/coverband_service_demo'
6
11
  module Coverband
7
12
  module Adapters
8
13
  ###
@@ -19,8 +24,8 @@ module Coverband
19
24
  super()
20
25
  @coverband_url = coverband_url
21
26
  @process_type = opts.fetch(:process_type) { 'unknown' }
22
- @runtime_env = opts.fetch(:runtime_env) { Rails.env }
23
- @coverband_id = opts.fetch(:coverband_id) { 'coverband-service/coverband_service_demo' }
27
+ @runtime_env = opts.fetch(:runtime_env) { COVERBAND_ENV }
28
+ @coverband_id = opts.fetch(:coverband_id) { COVERBAND_ID }
24
29
  end
25
30
 
26
31
  def clear!
@@ -53,6 +58,7 @@ module Coverband
53
58
  end
54
59
 
55
60
  def save_report(report)
61
+ #puts caller.join(',')
56
62
  return if report.empty?
57
63
 
58
64
  # TODO: do we need dup
@@ -74,7 +80,7 @@ module Coverband
74
80
  end
75
81
 
76
82
  def raw_store
77
- raise 'not supported'
83
+ self
78
84
  end
79
85
 
80
86
  private
@@ -100,12 +106,69 @@ module Coverband
100
106
  end
101
107
  end
102
108
 
109
+ ###
110
+ # TODO: move to a subclass, but the railtie needs to allow setting
111
+ # so for now just overiding the class to report via net::http
112
+ ###
113
+ module Coverband
114
+ module Collectors
115
+ class ViewTracker
116
+ def report_views_tracked
117
+ reported_time = Time.now.to_i
118
+ if views_to_record.any?
119
+ relative_views = views_to_record.map! do |view|
120
+ roots.each do |root|
121
+ view = view.gsub(/#{root}/, '')
122
+ end
123
+ view
124
+ end
125
+ save_tracked_views(views: relative_views, reported_time: reported_time)
126
+ end
127
+ self.views_to_record = []
128
+ rescue StandardError => e
129
+ # we don't want to raise errors if Coverband can't reach redis.
130
+ # This is a nice to have not a bring the system down
131
+ logger&.error "Coverband: view_tracker failed to store, error #{e.class.name}"
132
+ end
133
+
134
+ private
135
+
136
+ def save_tracked_views(views:, reported_time:)
137
+ uri = URI("#{COVERBAND_SERVICE_URL}/api/collector")
138
+ req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json', 'Coverband-Token' => ENV['COVERBAND_API_KEY'])
139
+ data = {
140
+ coverband_id: COVERBAND_ID,
141
+ collection_type: 'view_tracker_delta',
142
+ collection_data: {
143
+ tags: {
144
+ runtime_env: COVERBAND_ENV
145
+ },
146
+ collection_time: reported_time,
147
+ tracked_views: views
148
+ }
149
+ }
150
+ puts "sending #{data}"
151
+ req.body = { remote_uuid: SecureRandom.uuid, data: data }.to_json
152
+ res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
153
+ http.request(req)
154
+ end
155
+ rescue StandardError => e
156
+ puts "Coverband: Error while saving coverage #{e}"
157
+ end
158
+ end
159
+ end
160
+ end
161
+
103
162
  Coverband.configure do |config|
104
163
  # toggle store type
105
- redis_url = ENV['REDIS_URL']
164
+
165
+ # redis_url = ENV['REDIS_URL']
106
166
  # Normal Coverband Setup
107
167
  # config.store = Coverband::Adapters::HashRedisStore.new(Redis.new(url: redis_url))
168
+
108
169
  # Use The Test Service Adapter
109
- coverband_service_url = ENV['COVERBAND_URL'] || 'http://127.0.0.1:3456'
110
- config.store = Coverband::Adapters::Service.new(coverband_service_url)
170
+ config.store = Coverband::Adapters::Service.new(COVERBAND_SERVICE_URL)
171
+
172
+ # default to tracking views true
173
+ config.track_views = ENV['COVERBAND_DISABLE_VIEW_TRACKER'] ? false : true
111
174
  end
@@ -1,7 +1,7 @@
1
1
  module Coverband
2
2
  module Service
3
3
  module Client
4
- VERSION = "0.0.2"
4
+ VERSION = '0.0.3'
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.2
4
+ version: 0.0.3
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-01-25 00:00:00.000000000 Z
12
+ date: 2020-02-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler