coverband 5.2.6.rc.4 → 5.2.6.rc.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +3 -1
- data/README.md +26 -23
- data/changes.md +5 -0
- data/lib/coverband/adapters/base.rb +1 -1
- data/lib/coverband/configuration.rb +1 -1
- data/lib/coverband/reporters/web.rb +5 -0
- data/lib/coverband/utils/file_hasher.rb +1 -1
- data/lib/coverband/version.rb +1 -1
- data/lib/coverband.rb +5 -0
- data/test/coverband/collectors/route_tracker_test.rb +1 -1
- data/test/coverband/collectors/translation_tracker_test.rb +1 -1
- data/test/coverband/utils/file_hasher_test.rb +5 -5
- data/test/test_helper.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '038d579fb6a17cf39e836bdf1918f3535de5a774337a782c20b8b4f15021bace'
|
4
|
+
data.tar.gz: b1c8a6310809f17bcead1dceef71679bc768a392cd0682daf7c668343a898f86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d8ed302f5e3715fc3f4649364743223dcc8a2e7f07112603800cf03302ed64a8f63e3c993993baaeccd99290667b5ec48b0714cf1b564c8cf24db8c60ad1e47
|
7
|
+
data.tar.gz: 2ba722322a9219b3a4ab369ee0f337152151b0301e42f444ac4d9f9866cf1399687ceb2549ae9bb33781661d63b692e07d9b10b7a3c4287638f2ffaed844621c
|
data/.github/workflows/main.yml
CHANGED
@@ -22,11 +22,13 @@ jobs:
|
|
22
22
|
# ruby: [2.3, 2.4, 2.5, 2.6, 2.7, "3.0", "3.1", jruby]
|
23
23
|
# need to add support for multiple gemfiles
|
24
24
|
ruby: ["2.7", "3.0", "3.1", "3.2"]
|
25
|
-
redis-version: [4, 5, 6]
|
25
|
+
redis-version: [4, 5, 6, 7]
|
26
26
|
runs-on: ${{ matrix.os }}-latest
|
27
27
|
steps:
|
28
28
|
- uses: actions/checkout@v3
|
29
29
|
- uses: supercharge/redis-github-action@1.2.0
|
30
|
+
with:
|
31
|
+
redis-version: ${{ matrix.redis-version }}
|
30
32
|
- uses: ruby/setup-ruby@v1
|
31
33
|
with:
|
32
34
|
ruby-version: ${{ matrix.ruby }}
|
data/README.md
CHANGED
@@ -18,13 +18,13 @@
|
|
18
18
|
<a href="/CODE_OF_CONDUCT.md">Code of Conduct</a>
|
19
19
|
</p>
|
20
20
|
|
21
|
-
A gem to measure production code usage, showing a counter for the number of times each line of code
|
21
|
+
A gem to measure production code usage, showing a counter for the number of times each line of code is executed. Coverband allows easy configuration to collect and report on production code usage. It reports in the background via a thread, can be used as Rack middleware, or can be manually configured to meet any need.
|
22
22
|
|
23
|
-
**Note:** Coverband is not intended for test code coverage
|
23
|
+
**Note:** Coverband is not intended for test code coverage; for that we recommend using [SimpleCov](https://github.com/colszowka/simplecov).
|
24
24
|
|
25
25
|
## Key Features
|
26
26
|
|
27
|
-
The primary goal of Coverband is
|
27
|
+
The primary goal of Coverband is to give you deep insight into the production runtime usage of your application code, while having the least impact on performance possible.
|
28
28
|
|
29
29
|
- Low performance overhead
|
30
30
|
- Simple setup and configuration
|
@@ -55,7 +55,7 @@ gem 'coverband'
|
|
55
55
|
|
56
56
|
### No custom code or middleware required
|
57
57
|
|
58
|
-
With older versions of
|
58
|
+
With older versions of Coverband, projects would report to redis using rack or sidekiq middleware. After Coverband 4.0, this should no longer be required and could cause performance issues. Reporting to redis is now automatically done within a background thread with no custom code needed.
|
59
59
|
|
60
60
|
See [changelog](https://github.com/danmayer/coverband/blob/master/changes.md).
|
61
61
|
|
@@ -65,7 +65,7 @@ The Railtie integration means you shouldn't need to do anything else other than
|
|
65
65
|
|
66
66
|
## Sinatra
|
67
67
|
|
68
|
-
For the best coverage you want this loaded as early as possible. We recommend requiring cover band directly in the `config.ru`. Requiring
|
68
|
+
For the best coverage, you want this loaded as early as possible. We recommend requiring cover band directly in the `config.ru`. Requiring Coverband within an initializer could also work, but you may end up missing some boot up coverage. To start collection require Coverband as early as possible.
|
69
69
|
|
70
70
|
```ruby
|
71
71
|
require 'coverband'
|
@@ -79,7 +79,7 @@ run ActionController::Dispatcher.new
|
|
79
79
|
|
80
80
|
![image](https://raw.github.com/danmayer/coverband/master/docs/coverband_web_ui.png)
|
81
81
|
|
82
|
-
> The web index
|
82
|
+
> The web index is available on the [Coverband Demo site](https://coverband-demo.herokuapp.com/coverage?#_Coverage).
|
83
83
|
|
84
84
|
- View overall coverage information
|
85
85
|
|
@@ -87,7 +87,7 @@ run ActionController::Dispatcher.new
|
|
87
87
|
|
88
88
|
- View individual file details
|
89
89
|
|
90
|
-
- Clear Coverage - disabled by default as it could be considered a dangerous operation in production. Enable with `config.web_enable_clear` or leave off and clear from [rake task](#clear-coverage).
|
90
|
+
- Clear Coverage - disabled by default as it could be considered a dangerous operation in production. Enable with `config.web_enable_clear` or leave off and clear from the [rake task](#clear-coverage).
|
91
91
|
|
92
92
|
- Clear coverage report
|
93
93
|
|
@@ -139,10 +139,10 @@ If you want to run on an alternative port:
|
|
139
139
|
COVERBAND_COVERAGE_PORT=8086 bundle exec rake coverband:coverage_server
|
140
140
|
```
|
141
141
|
|
142
|
-
This is especially useful for projects that are api only and cannot support the mounted rack app. To get production coverage, point
|
142
|
+
This is especially useful for projects that are api only and cannot support the mounted rack app. To get production coverage, point Coverband at your production redis server and ensure to checkout the production version of your project code locally.
|
143
143
|
|
144
144
|
```
|
145
|
-
COVERBAND_REDIS_URL=redis://username:password
|
145
|
+
COVERBAND_REDIS_URL=redis://username:password@redis_production_server:2322 bundle exec rake coverband:coverage_server
|
146
146
|
```
|
147
147
|
|
148
148
|
# Coverband Demo
|
@@ -157,7 +157,7 @@ Take Coverband for a spin on the live Heroku deployed [Coverband Demo](https://c
|
|
157
157
|
|
158
158
|
# Advanced Config
|
159
159
|
|
160
|
-
If you need to configure
|
160
|
+
If you need to configure Coverband, this can be done by creating a `config/coverband.rb` file relative to your project root.
|
161
161
|
|
162
162
|
- See [lib/coverband/configuration.rb](https://github.com/danmayer/coverband/blob/master/lib/coverband/configuration.rb) for all options
|
163
163
|
- By default Coverband will try to store data to Redis \* Redis endpoint is looked for in this order: `ENV['COVERBAND_REDIS_URL']`, `ENV['REDIS_URL']`, or `localhost`
|
@@ -183,12 +183,15 @@ Coverband.configure do |config|
|
|
183
183
|
# Does not track line-level usage, only indicates if an entire file
|
184
184
|
# is used or not.
|
185
185
|
config.track_views = true
|
186
|
+
|
187
|
+
# default false. Experimental support for routes usage tracking.
|
188
|
+
config.track_routes = true
|
186
189
|
end
|
187
190
|
```
|
188
191
|
|
189
192
|
### Working with environment variables
|
190
193
|
|
191
|
-
Do you use figaro, mc-settings, dotenv or something else to inject environment variables into your app? If so ensure you have that done BEFORE
|
194
|
+
Do you use figaro, mc-settings, dotenv or something else to inject environment variables into your app? If so ensure you have that done BEFORE Coverband is required.
|
192
195
|
|
193
196
|
For example if you use dotenv, you need to do this, see https://github.com/bkeepers/dotenv#note-on-load-order
|
194
197
|
|
@@ -200,7 +203,7 @@ gem 'other-gem-that-requires-env-variables'
|
|
200
203
|
|
201
204
|
### Ignoring Files
|
202
205
|
|
203
|
-
Sometimes you have files that are known to be valuable perhaps in other environments or something that is just run very infrequently. Opposed to having to mentally filter them out of the report, you can just have them ignored in the Coverband reporting by using `config.ignore` as shown below. Ignore takes a string but can also match with regex rules see how below ignores all rake tasks as an example.
|
206
|
+
Sometimes you have files that are known to be valuable, perhaps in other environments or something that is just run very infrequently. Opposed to having to mentally filter them out of the report, you can just have them ignored in the Coverband reporting by using `config.ignore` as shown below. Ignore takes a string but can also match with regex rules see how below ignores all rake tasks as an example.
|
204
207
|
|
205
208
|
```
|
206
209
|
config.ignore += ['config/application.rb',
|
@@ -212,7 +215,7 @@ config.ignore += ['config/application.rb',
|
|
212
215
|
'lib/tasks/.*']
|
213
216
|
```
|
214
217
|
|
215
|
-
**Ignoring Custom Gem Locations:** Note, if you have your gems in a custom location under your app folder you likely want to add them to `config.ignore`. For example, if you have your gems not in
|
218
|
+
**Ignoring Custom Gem Locations:** Note, if you have your gems in a custom location under your app folder you likely want to add them to `config.ignore`. For example, if you have your gems not in the default ignored location of `app/vendor` but in `app/gems`, you would need to add `gems/*` to your ignore list.
|
216
219
|
|
217
220
|
### View Tracking
|
218
221
|
|
@@ -249,7 +252,7 @@ end
|
|
249
252
|
|
250
253
|
### Avoiding Cache Stampede
|
251
254
|
|
252
|
-
If you have many servers and they all hit Redis at the same time you can see spikes in your Redis CPU, and memory. This is due to a concept called [cache stampede](https://en.wikipedia.org/wiki/Cache_stampede). It is better to spread out the reporting across your servers. A simple way to do this is to add a random wiggle on your background reporting. This configuration option allows a wiggle. The right amount of wiggle depends on the
|
255
|
+
If you have many servers and they all hit Redis at the same time you can see spikes in your Redis CPU, and memory. This is due to a concept called [cache stampede](https://en.wikipedia.org/wiki/Cache_stampede). It is better to spread out the reporting across your servers. A simple way to do this is to add a random wiggle on your background reporting. This configuration option allows a wiggle. The right amount of wiggle depends on the number of servers you have and how willing you are to have delays in your coverage reporting. I would recommend at least 1 second per server. Note, the default wiggle is set to 30 seconds.
|
253
256
|
|
254
257
|
Add a wiggle (in seconds) to the background thread to avoid all your servers reporting at the same time:
|
255
258
|
|
@@ -257,16 +260,16 @@ Add a wiggle (in seconds) to the background thread to avoid all your servers rep
|
|
257
260
|
|
258
261
|
### Redis Hash Store
|
259
262
|
|
260
|
-
Coverband on very high volume sites with many server processes reporting can have a race condition which can cause hit counts to be inaccurate. To resolve the race condition and reduce Ruby memory overhead we have introduced a new Redis storage option. This moves the some of the work from the Ruby processes to Redis. It is worth noting because of this, it has
|
263
|
+
Coverband on very high volume sites with many server processes reporting can have a race condition which can cause hit counts to be inaccurate. To resolve the race condition and reduce Ruby memory overhead we have introduced a new Redis storage option. This moves the some of the work from the Ruby processes to Redis. It is worth noting because of this, it has larger demands on the Redis server. So adjust your Redis instance accordingly. To help reduce the extra redis load you can also change the background reporting frequency.
|
261
264
|
|
262
|
-
- Use a dedicated
|
265
|
+
- Use a dedicated Coverband redis instance: `config.store = Coverband::Adapters::HashRedisStore.new(Redis.new(url: redis_url))`
|
263
266
|
- Adjust from default 30s reporting `config.background_reporting_sleep_seconds = 120`
|
264
267
|
|
265
268
|
See more discussion [here](https://github.com/danmayer/coverband/issues/384).
|
266
269
|
|
267
270
|
### Clear Coverage
|
268
271
|
|
269
|
-
Now that Coverband uses MD5 hashes there should be no reason to manually clear coverage unless one is testing, changing versions, possibly debugging Coverband itself.
|
272
|
+
Now that Coverband uses MD5 hashes there should be no reason to manually clear coverage unless one is testing, changing versions, or possibly debugging Coverband itself.
|
270
273
|
|
271
274
|
`rake coverband:clear`
|
272
275
|
|
@@ -302,11 +305,11 @@ rake coverband:coverage # report runtime coverband code coverage
|
|
302
305
|
|
303
306
|
### Manually Starting Coverband
|
304
307
|
|
305
|
-
Coverband starts on require of the the library which is usually done within the Gemfile. This can be disabled by setting the `COVERBAND_DISABLE_AUTO_START` environment variable. This environment variable can be useful to toggle
|
308
|
+
Coverband starts on require of the the library which is usually done within the Gemfile. This can be disabled by setting the `COVERBAND_DISABLE_AUTO_START` environment variable. This environment variable can be useful to toggle Coverband on and off in certain environments.
|
306
309
|
|
307
310
|
**NOTE:** That any value set for `COVERBAND_DISABLE_AUTO_START` is considered true, it does not match the string content but only checks the presence of the ENV variable.
|
308
311
|
|
309
|
-
In order to start
|
312
|
+
In order to start Coverband manually when this flag is enabled, call `Coverband.configure` followed by `Coverband.start`.
|
310
313
|
|
311
314
|
```ruby
|
312
315
|
Coverband.configure
|
@@ -315,7 +318,7 @@ Coverband.start
|
|
315
318
|
|
316
319
|
### Verbose Debug / Development Mode
|
317
320
|
|
318
|
-
Note: To debug issues getting Coverband working. I recommend running in development mode, by turning verbose logging on `config.verbose = true` and passing in the Rails.logger `config.logger = Rails.logger` to the Coverband config. We respect the log level, and I would recommend log level info generally, but if you are investigating a problem Coverband logs additional data at the `debug` level. This makes it easy to follow in development mode. Be careful to
|
321
|
+
Note: To debug issues getting Coverband working. I recommend running in development mode, by turning verbose logging on `config.verbose = true` and passing in the Rails.logger `config.logger = Rails.logger` to the Coverband config. We respect the log level, and I would recommend log level info generally, but if you are investigating a problem Coverband logs additional data at the `debug` level. This makes it easy to follow in development mode. Be careful not to leave these on in production as they will affect performance.
|
319
322
|
|
320
323
|
---
|
321
324
|
|
@@ -323,7 +326,7 @@ If you are trying to debug locally wondering what code is being run during a req
|
|
323
326
|
|
324
327
|
### Solving: stack level too deep errors
|
325
328
|
|
326
|
-
If you start seeing SystemStackError: stack level too deep errors from background jobs after installing Coverband, this means there is another patch for ResqueWorker that conflicts with Coverband's patch in your application. To fix this, change
|
329
|
+
If you start seeing SystemStackError: stack level too deep errors from background jobs after installing Coverband, this means there is another patch for ResqueWorker that conflicts with Coverband's patch in your application. To fix this, change Coverband gem line in your Gemfile to the following:
|
327
330
|
|
328
331
|
```
|
329
332
|
gem 'coverband', require: ['alternative_coverband_patch', 'coverband']
|
@@ -335,11 +338,11 @@ If you currently have require: false, remove the 'coverband' string from the req
|
|
335
338
|
gem 'coverband', require: ['alternative_coverband_patch']
|
336
339
|
```
|
337
340
|
|
338
|
-
This conflict happens when a ruby method is patched twice, once using module prepend, and once using method aliasing. See this ruby issue for details. The fix is to apply all patches the same way.
|
341
|
+
This conflict happens when a ruby method is patched twice, once using module prepend, and once using method aliasing. See this ruby issue for details. The fix is to apply all patches the same way. By default, Coverband will apply its patch using prepend, but you can change that to method aliasing by adding require: ['alternative_coverband_patch'] to the gem line as shown above.
|
339
342
|
|
340
343
|
### Redis Sizing Info
|
341
344
|
|
342
|
-
A few folks have asked about what size of Redis is needed to run
|
345
|
+
A few folks have asked about what size of Redis is needed to run Coverband. I have some of our largest services with hundreds of servers on cache.m3.medium with plenty of room to spare. I run most apps on the smallest AWS Redis instances available and bump up only if needed or if I am forced to be on a shared Redis instance, which I try to avoid. On Heroku, I have used it with most of the 3rd party and also been fine on the smallest Redis instances, if you have hundreds of dynos you would likely need to scale up. Also note there is a tradeoff one can make, `Coverband::Adapters::HashRedisStore` will use LUA on Redis and increase the Redis load, while being nicer to your app servers and avoid potential lost data during race conditions. While the `Coverband::Adapters::RedisStore` uses in app memory and merging and has lower load on Redis.
|
343
346
|
|
344
347
|
# Newer Features
|
345
348
|
|
data/changes.md
CHANGED
@@ -6,6 +6,11 @@ __NOTE: the current RCs include below, but this might turn into coverband 6.0__
|
|
6
6
|
- refactor non Coverage.so based trackers
|
7
7
|
- adds CSP report support (thanks @jwg2s)
|
8
8
|
- add JSON reporter (thanks @mark-davenport-fountain)
|
9
|
+
- README improvements (thanks @jfvanderwalt)
|
10
|
+
- Fix on test mode configuration (thanks @rileyanderson)
|
11
|
+
- Text Improvements (thanks @etagwerker)
|
12
|
+
- readme update on configuration options (thanks @D-system)
|
13
|
+
- fix for rack mount of class vs instance (thanks @vs37559)
|
9
14
|
|
10
15
|
### Coverband 5.2.5
|
11
16
|
|
@@ -5,7 +5,7 @@ module Coverband
|
|
5
5
|
class FileHasher
|
6
6
|
@cache = {}
|
7
7
|
|
8
|
-
def self.
|
8
|
+
def self.hash_file(file, path_converter: AbsoluteFileConverter.instance)
|
9
9
|
@cache[file] ||= begin
|
10
10
|
file = path_converter.convert(file)
|
11
11
|
Digest::MD5.file(file).hexdigest if File.exist?(file)
|
data/lib/coverband/version.rb
CHANGED
data/lib/coverband.rb
CHANGED
@@ -20,7 +20,7 @@ class RouterTrackerTest < Minitest::Test
|
|
20
20
|
test "init correctly" do
|
21
21
|
Coverband::Collectors::RouteTracker.expects(:supported_version?).returns(true)
|
22
22
|
tracker = Coverband::Collectors::RouteTracker.new(store: fake_store, roots: "dir")
|
23
|
-
|
23
|
+
assert_nil tracker.target.first
|
24
24
|
assert !tracker.store.nil?
|
25
25
|
assert_equal [], tracker.target
|
26
26
|
assert_equal [], tracker.logged_keys
|
@@ -25,7 +25,7 @@ class TranslationTrackerTest < Minitest::Test
|
|
25
25
|
test "init correctly" do
|
26
26
|
Coverband::Collectors::TranslationTracker.expects(:supported_version?).returns(true)
|
27
27
|
tracker = Coverband::Collectors::TranslationTracker.new(store: fake_store, roots: "dir")
|
28
|
-
|
28
|
+
assert_nil tracker.target.first
|
29
29
|
assert !tracker.store.nil?
|
30
30
|
assert_equal [], tracker.target
|
31
31
|
assert_equal [], tracker.logged_keys
|
@@ -6,17 +6,17 @@ module Coverband
|
|
6
6
|
module Utils
|
7
7
|
class FileHasherTest < Minitest::Test
|
8
8
|
def test_hash_same_file
|
9
|
-
refute_nil FileHasher.
|
10
|
-
assert_equal(FileHasher.
|
11
|
-
assert_equal(FileHasher.
|
9
|
+
refute_nil FileHasher.hash_file("./test/dog.rb")
|
10
|
+
assert_equal(FileHasher.hash_file("./test/dog.rb"), FileHasher.hash_file("./test/dog.rb"))
|
11
|
+
assert_equal(FileHasher.hash_file(File.expand_path("./test/dog.rb")), FileHasher.hash_file("./test/dog.rb"))
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_hash_different_files
|
15
|
-
refute_equal(FileHasher.
|
15
|
+
refute_equal(FileHasher.hash_file("./test/dog.rb"), FileHasher.hash_file("./lib/coverband.rb"))
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_hash_file_not_exists
|
19
|
-
assert_nil(FileHasher.
|
19
|
+
assert_nil(FileHasher.hash_file("./made_up_file.py"))
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/test/test_helper.rb
CHANGED
@@ -110,7 +110,7 @@ def test(name, &block)
|
|
110
110
|
end
|
111
111
|
|
112
112
|
def mock_file_hash(hash: "abcd")
|
113
|
-
Coverband::Utils::FileHasher.expects(:
|
113
|
+
Coverband::Utils::FileHasher.expects(:hash_file).at_least_once.returns(hash)
|
114
114
|
end
|
115
115
|
|
116
116
|
def example_line
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coverband
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.2.6.rc.
|
4
|
+
version: 5.2.6.rc.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Mayer
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-07-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: benchmark-ips
|