coverband 2.0.0 → 2.0.3

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.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -1
  3. data/README.md +198 -62
  4. data/Rakefile +7 -0
  5. data/changes.md +40 -0
  6. data/config.ru +4 -0
  7. data/coverband.gemspec +1 -2
  8. data/lib/coverband/adapters/memory_cache_store.rb +16 -16
  9. data/lib/coverband/adapters/redis_store.rb +51 -16
  10. data/lib/coverband/collectors/base.rb +1 -1
  11. data/lib/coverband/collectors/coverage.rb +20 -8
  12. data/lib/coverband/collectors/trace.rb +17 -7
  13. data/lib/coverband/configuration.rb +31 -6
  14. data/lib/coverband/reporters/base.rb +2 -2
  15. data/lib/coverband/reporters/simple_cov_report.rb +6 -1
  16. data/lib/coverband/reporters/web.rb +152 -0
  17. data/lib/coverband/s3_report_writer.rb +13 -2
  18. data/lib/coverband/tasks.rb +0 -46
  19. data/lib/coverband/version.rb +1 -1
  20. data/lib/coverband.rb +6 -5
  21. data/test/benchmarks/benchmark.rake +89 -10
  22. data/test/test_helper.rb +0 -5
  23. data/test/unit/adapters_memory_cache_store_test.rb +40 -30
  24. data/test/unit/adapters_redis_store_test.rb +12 -3
  25. data/test/unit/collectors_base_test.rb +3 -1
  26. data/test/unit/collectors_coverage_test.rb +3 -3
  27. data/test/unit/collectors_trace_test.rb +3 -1
  28. data/test/unit/reports_console_test.rb +10 -1
  29. data/test/unit/reports_simple_cov_test.rb +11 -2
  30. data/test/unit/reports_web_test.rb +37 -0
  31. data/test/unit/s3_report_writer_test.rb +7 -1
  32. metadata +7 -26
  33. data/docs/coverband_details.png +0 -0
  34. data/docs/coverband_index.png +0 -0
  35. data/docs/coverband_install.gif +0 -0
  36. data/lib/coverband/baseline.rb +0 -44
  37. data/lib/coverband/s3_web.rb +0 -25
  38. data/test/unit/baseline_test.rb +0 -59
  39. data/test/unit/s3_web_test.rb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 104227eaef7c235ff16b13a0f80c5f29fe4117deac05acbed7553e3343be7ea9
4
- data.tar.gz: dd5a621f881e955c52c1a2acf903f3bc5abd550bc015650851cb385ff76bf758
2
+ SHA1:
3
+ metadata.gz: 8d6a0e6c24d29f4b432cd6a514b5c1bbca2e699d
4
+ data.tar.gz: d2ef15b6d6b100396b265068acdf1d4d83394823
5
5
  SHA512:
6
- metadata.gz: 7a2c2041a887b5ac729a540489b20e48fba117e2d70e827f3b7c5fb6da21382fa6786a093e915232771abc7a0903f78b3484713e39394fdf3bbf6cda6f8f57c9
7
- data.tar.gz: 38ed9c82a8a607d349f4edef901d7d348b128c9ff2f6ad6276df388f29ee25e98c6e9534f3e0d4d16d1902f958575f72aa6676c8499d81f6a44b72eaaef534fc
6
+ metadata.gz: fd0b35c4a1abceebcda0791290dc71e0fc382c4980c87d09639371a2d4f048b0d79b3938b18c3facbe5e78fcf25c2f1aa8d3766eaca761dd590ecc71138410d9
7
+ data.tar.gz: d0104388613abebf8575d4701b8cda4ff0caaaa5f14d57c72535c7cf68d178f432ac584a7f9c700e625b724c542b78827d5964ab24573e81562bf0b5688e8dd0
data/.gitignore CHANGED
@@ -18,4 +18,5 @@ spec/reports
18
18
  test/tmp
19
19
  test/version_tmp
20
20
  tmp
21
- .byebug_history
21
+ .byebug_history
22
+ .env
data/README.md CHANGED
@@ -4,11 +4,13 @@ Build Status: [![Build Status](https://travis-ci.org/danmayer/coverband.svg?bran
4
4
 
5
5
  <p align="center">
6
6
  <a href="#key-features">Key Features</a> •
7
+ <a href="#coverband-demo">Coverband Demo</a> •
7
8
  <a href="#how-to-use">How To Use</a> •
8
9
  <a href="#installation">Installation</a> •
9
10
  <a href="#configuration">Configuration</a> •
10
11
  <a href="#usage">Usage</a> •
11
- <a href="#license">License</a>
12
+ <a href="#license">License</a>
13
+ <a href="/changes.md">Change Log / Roadmap</a>
12
14
  </p>
13
15
 
14
16
  A gem to measure production code usage, showing each line of code that is executed. Coverband allows easy configuration to collect and report on production code usage. It can be used as Rack middleware, wrapping a block with sampling, or manually configured to meet any need (like usage during background jobs).
@@ -17,24 +19,31 @@ Note: Coverband is not intended for test code coverage, for that just check out
17
19
 
18
20
  ## Key Features
19
21
 
20
- * Allows sampling to avoid the performance overhead on every request.
22
+ The primary goal of Coverband is giving deep insight into your production runtime usage of your application code, while having the least impact on performance possible.
23
+
24
+ * Low performance overhead
25
+ * Various controls from sampling, data collection rate, etc to further control performance
21
26
  * Ignore directories to avoid overhead data collection on vendor, lib, etc.
22
- * Take a baseline to get initial app execution during app initialization. (the baseline is important because some code is executed during app load, but might not be invoked during any requests, think prefetching, initial cache builds, setting constants, etc...)
23
- * Development mode for additional code usage details (number of LOC execution during single request, etc).
27
+ * Development mode, offers deep insight of code usage details (number of LOC execution during single request, etc) during development.
28
+ * Easy setup for any Ruby Rack based web framework (Rails, Sinatra, etc)
29
+ * Allows for integration with any other Ruby application flows (background jobs, crons, scripts)
30
+
31
+ ## Coverband Demo
32
+
33
+ Take Coverband for a spin on the live Heroku deployed [Coverband Demo](https://coverband-demo.herokuapp.com/). The [full source code for the demo](https://github.com/danmayer/coverband_demo) is available to help with configuration and understanding of basic usage.
24
34
 
25
35
  # How To Use
26
36
 
27
37
  Below is my Coverband workflow, which hopefully will help other best use this library.
28
38
 
29
- * install coverband.
30
- * take baseline measurment: `rake coverband:baseline` (__note: never run baseline on production__)
31
- * validate baseline with `rake coverband:coverage`
39
+ * install coverband
40
+ * start your app and hit a few endpoints
41
+ * validate data collection and code coverage with `rake coverband:coverage`
32
42
  * test setup in development (hit endpoints and generate new report)
33
43
  * deploy to staging and verify functionality
34
44
  * deploy to production and verify functionality
35
- * every 2 weeks or with major releases
45
+ * every 2 weeks or so, with major releases
36
46
  * clear old coverage: `rake coverband:clear`
37
- * take new baseline: `rake coverband:baseline`
38
47
  * deploy and verify coverage is matching expectations
39
48
  * __COVERAGE DRIFT__
40
49
  * if you never clear you have lines of code drift from when they were recorded
@@ -57,7 +66,7 @@ Details on a example Sinatra app
57
66
 
58
67
  Follow the below section to install and configure Coverband.
59
68
 
60
- ![coverband installation](https://raw.githubusercontent.com/danmayer/coverband/feature/via_coverage/docs/coverband_install.gif?raw=true)
69
+ ![coverband installation](https://raw.githubusercontent.com/danmayer/coverband/master/docs/coverband-install-resize.gif)
61
70
 
62
71
  ## Prerequisites
63
72
 
@@ -102,6 +111,10 @@ Coverband.configure do |config|
102
111
  config.root = Dir.pwd
103
112
  config.collector = 'coverage'
104
113
  config.redis = Redis.new(url: ENV['REDIS_URL']) if defined? Redis
114
+ # TODO NOTE THIS IS A ISSUE IN THE 2.0 release you set something like redis and the store
115
+ # I need to look a bit more at this but got one bug report quickly after release
116
+ # (even though test builds didnt need)
117
+ config.store = Redis.new(url: ENV['REDIS_URL']) if defined? Redis
105
118
  config.ignore = %w[vendor .erb$ .slim$]
106
119
  # add paths that you deploy to that might be different than your local dev root path
107
120
  config.root_paths = []
@@ -134,8 +147,7 @@ require 'coverband/tasks'
134
147
  This should give you access to a number of Coverband tasks
135
148
 
136
149
  ```bash
137
- bundle exec rake -T coverband
138
- rake coverband:baseline # record coverband coverage baseline
150
+ rake -T coverband
139
151
  rake coverband:clear # reset coverband coverage data
140
152
  rake coverband:coverage # report runtime coverband code coverage
141
153
  ```
@@ -190,10 +202,10 @@ run ActionController::Dispatcher.new
190
202
 
191
203
  # Verify Correct Installation
192
204
 
193
- * Gather baseline metrics: run `bundle exec rake coverband:baseline` (__note: never run baseline on production__)
194
- * run `bundle exec rake coverband:coverage` this will show app initialization coverage
205
+ * boot up your application
206
+ * run `rake coverband:coverage` this will show app initialization coverage
195
207
  * run app and hit a controller (hit at least +1 time over your `config.startup_delay` setting default is 0)
196
- * run `bundle exec rake coverband:coverage` and you should see coverage increasing for the endpoints you hit.
208
+ * run `rake coverband:coverage` and you should see coverage increasing for the endpoints you hit.
197
209
 
198
210
  ## Installation Script
199
211
 
@@ -212,10 +224,11 @@ bundle install
212
224
 
213
225
  # create config/coverband.rb
214
226
  # copy the config from the readme
215
- # If you don't set REDIS_URL, remove that to use default localhose
227
+ # If you don't set REDIS_URL, remove that to use default localhost
216
228
 
229
+ # Make some code so we can look at the coverage
217
230
  rails generate scaffold blogs
218
- bundle exec rake db:migrate
231
+ rake db:migrate
219
232
 
220
233
  # open Rakefile, add lines
221
234
  require 'coverband'
@@ -228,10 +241,9 @@ rake -T coverband
228
241
  # configure config/application.rb
229
242
  # copy lines from readme
230
243
 
231
-
232
- rake coverband:baseline
244
+ # start up your app
233
245
  rake coverband:coverage
234
- # view baseline coverage
246
+ # view boot up coverage
235
247
 
236
248
  rails s
237
249
 
@@ -251,41 +263,11 @@ rake coverband:coverage
251
263
  - [Sinatra app](https://github.com/danmayer/churn-site)
252
264
  - [Non Rack Ruby app](https://github.com/danmayer/coverband_examples)
253
265
 
254
- ### Coverband Baseline
255
-
256
- __TLDR:__ Baseline is app initialization coverage, not captured during runtime.
257
-
258
- Before starting a service verify your baseline by running `rake coverband:baseline` followed by `rake coverband:coverage` to view what your baseline coverage looks like before any runtime traffic has been recorded.
259
-
260
- The baseline seems to cause some confusion. Basically, when Coverband records code usage, it will not request initial startup code like method definition, it covers what it hit during run time. This would produce a fairly odd view of code usage. To cover things like defining routes, dynamic methods, and the like Coverband records a baseline. The baseline should capture coverage of app initialization and boot up, we don't want to do this on deploy as it can be slow. So we take a recording of boot up as a one time baseline Rake task `bundle exec rake coverband:baseline`.
261
-
262
- 1. Start your server with `rails s` or `rackup config.ru`.
263
- 2. Hit your development server exercising the endpoints you want to verify Coverband is recording (you should see debug outputs in your server console)
264
- 3. Run `rake coverband:coverage` again, previously it should have only shown the baseline data of your app initializing. After using it in development it should show increased coverage from the actions you have exercised.
265
-
266
- Note: if you use `rails s` and data isn't recorded, make sure it is using your `config.ru`.
267
-
268
- ### Baseline Missing data
269
-
270
- The default Coverband baseline task will try to detect your app as either Rack or Rails environment. It will load the app to take a baseline reading. The baseline coverage is important because some code is executed during app load, but might not be invoked during any requests, think prefetching, initial cache builds, setting constants, etc. If the baseline task doesn't load your app well you can override the default baseline to create a better baseline yourself. Below for example is how I take a baseline on a pretty simple Sinatra app.
271
-
272
- ```ruby
273
- namespace :coverband do
274
- desc "get coverage baseline"
275
- task :baseline_app do
276
- Coverband::Reporter.baseline {
277
- require 'sinatra'
278
- require './app.rb'
279
- }
280
- end
281
- end
282
- ```
283
-
284
266
  ### View Coverage
285
267
 
286
- You can view the report different ways, but the easiest is the Rake task which opens the Simplecov formated HTML.
268
+ You can view the report different ways, but the easiest is the Rake task which opens the SimpleCov formatted HTML.
287
269
 
288
- `bundle exec rake coverband:coverage`
270
+ `rake coverband:coverage`
289
271
 
290
272
  This should auto-open in your browser, but if it doesn't the output file should be in `coverage/index.html`
291
273
 
@@ -313,7 +295,7 @@ Coverband::Reporter.clear_coverage(Redis.new(:host => 'target.com', :port => 678
313
295
  ```
314
296
  You can also do this with the included rake tasks.
315
297
 
316
- ### Manual configuration (for example for background jobs)
298
+ ### Manual Configuration (for example for background jobs)
317
299
 
318
300
  It is easy to use Coverband outside of a Rack environment. Make sure you configure Coverband in whatever environment you are using (such as `config/initializers/*.rb`). Then you can hook into before and after events to add coverage around background jobs, or for any non Rack code.
319
301
 
@@ -360,6 +342,83 @@ coverband.sample {
360
342
  }
361
343
  ```
362
344
 
345
+ ### Manual Configuration (for cron jobs / Raketasks)
346
+
347
+ A question about [supporting cron jobs and Rake tasks](https://github.com/danmayer/coverband/issues/106) was asked by [@ndbroadbent](https://github.com/ndbroadbent), there are a couple ways to go about it including his good suggestion.
348
+
349
+ He extended the Coverband Rake tasks by adding `lib/tasks/coverband.rake` with support to wrap all Rake tasks with coverband support.
350
+
351
+ ```
352
+ require 'coverband'
353
+ Coverband.configure
354
+ require 'coverband/tasks'
355
+
356
+ # Wrap all Rake tasks with Coverband
357
+ current_tasks = Rake.application.top_level_tasks
358
+ if current_tasks.any? && current_tasks.none? { |t| t.to_s.match?(/^coverband:/) }
359
+ current_tasks.unshift 'coverband:start'
360
+ current_tasks.push 'coverband:stop_and_save'
361
+ end
362
+
363
+ namespace :coverband do
364
+ task :start do
365
+ Coverband::Base.instance.start
366
+ end
367
+
368
+ task :stop_and_save do
369
+ Coverband::Base.instance.stop
370
+ Coverband::Base.instance.save
371
+ end
372
+ end
373
+ ```
374
+
375
+ That is a interesting approach and if you Run all your cron jobs as Rake tasks might work well for you. In a production application where we run Coverband, we run all of our Cron jobs with the `rails runner` script. We took this alternative approach which will wrap all runner jobs with Coverband recording, by creating `lib/railties/coverage_runner.rb`.
376
+
377
+ ```
378
+ require 'rails'
379
+
380
+ # Capture code coverage during our cron jobs
381
+ class CoverageRunner < ::Rails::Railtie
382
+ runner do
383
+ Coverband::Collectors::Base.instance.start
384
+ at_exit do
385
+ Coverband::Collectors::Base.instance.report_coverage
386
+ end
387
+ end
388
+ end
389
+ ```
390
+
391
+ ### safe_reload_files: Forcing Coverband to Track Coverage on Files loaded during boot
392
+
393
+ The way Coverband is built it will record and report code usage in production for anything `required` or `loaded` after calling `Coverband.start`. This means some of Rails initial files and Gems are loaded before you can generally call `Coverband.start` for example if you use the `application.rb` to initialize and start Coverband, that file will be reported as having no coverage, as it can't possibly start Coverband before the file is loaded.
394
+
395
+ The `safe_reload_files` reload option in the configuration options can help to ensure you can track any files you want regardless of them loading before Coverband. For example if I wanted to show the coverage of `config/coverband.rb` which has to be loaded before calling `Coverband.start` I could do that by adding that path to the `safe_reload_files` option.
396
+
397
+ ```
398
+ Coverband.configure do |config|
399
+ # ... a bunch of other options
400
+ # using the new safe reload to enforce files loaded
401
+ config.safe_reload_files = ['config/coverband.rb']
402
+ end
403
+ ```
404
+ By adding any files above you will get reporting on those files as part of your coverage runtime report.
405
+
406
+
407
+ ### Collecting Gem / Library Usage
408
+
409
+ By default Coverband has assumed you are trying to track your application code usage not all the supporting framework and library (Gems) code usage. There has been some good points and reasons folks want to track library usage, for example to find out which Gems they aren't actually using in production. See some of the discussion on [issue 21](https://github.com/danmayer/coverband/issues/21).
410
+
411
+ * Using the Tracepoint Collector
412
+ * just make sure to set `Coverband.configuration.include_gems = true` in your config options
413
+ * note by tracking all the additional usage this can have significant performance impacts of the Tracepoint implementation
414
+ * Using the Coverage Collector
415
+ * use the `safe_reload_files` feature to add the path of all gem files you wish to track
416
+ * --- or ---
417
+ * ensure you call `Coverband.start` before loading all your gems
418
+ * while possible this is currently hard as Rails and most environments load your whole Gemfile
419
+ * looking for an improve and easier way to support this.
420
+
421
+
363
422
  ### Verbose Debug / Development Mode
364
423
 
365
424
  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. This makes it easy to follow in development mode. Be careful to not leave these on in production as they will affect performance.
@@ -400,6 +459,83 @@ Coverband::Reporter.report :additional_scov_data => [data]
400
459
 
401
460
  You can also pass a `:additional_scov_data => [data]` option to `Coverband::Reporter.get_current_scov_data` to write out merged data.
402
461
 
462
+ ### Writing Coverband Results to S3
463
+
464
+ If you add some additional Coverband configuration your coverage html report will be written directly to S3, update `config/coverband.rb` like below.
465
+
466
+ ```
467
+ # configure S3 integration
468
+ config.s3_bucket = 'coverband-demo'
469
+ config.s3_region = 'us-east-1'
470
+ config.s3_access_key_id = ENV['AWS_ACCESS_KEY_ID']
471
+ config.s3_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
472
+ ```
473
+
474
+ ### Viewing / Hosting S3 Coverband results in app
475
+
476
+ Beyond writing to S3 you can host the S3 file with a build in Sintatra app in Coverband. Just configure your Rails route `config/routes.rb`
477
+
478
+ ```
479
+ Rails.application.routes.draw do
480
+ # ... lots of routes
481
+ mount Coverband::Reporters::Web.new, at: '/coverage'
482
+ end
483
+ ```
484
+
485
+ __NOTE__: ADD PASSWORD PROTECTION OR YOU CAN EXPOSE ALL YOUR SOURCE CODE
486
+
487
+ It is easy to add some basic protect around the coverage data, below shows how you can use devise or basic auth, by adding a bit of code to your `config/routes.rb` file.
488
+
489
+ ```
490
+ # protect with existing Rails devise configuration
491
+ devise_constraint = lambda do |request|
492
+ request.env['warden'] && request.env['warden'].authenticate? && request.env['warden'].user.admin?
493
+ end
494
+
495
+ # protect with http basic auth
496
+ # curl --user foo:bar http://localhost:3000/coverage
497
+ basic_constraint = lambda do |request|
498
+ return true if Rails.env.development?
499
+ if ActionController::HttpAuthentication::Basic.has_basic_credentials?(request)
500
+ credentials = ActionController::HttpAuthentication::Basic.decode_credentials(request)
501
+ email, password = credentials.split(':')
502
+
503
+ email == 'foo' && password = 'bar'
504
+ end
505
+ end
506
+
507
+ Rails.application.routes.draw do
508
+ # ... lots of routes
509
+ constraints basic_constraint do
510
+ mount Coverband::Reporters::Web.new, at: '/coverage'
511
+ end
512
+ end
513
+ ```
514
+
515
+ ### Conflicting .Simplecov: Issue with Missing or 0% Coverage Report
516
+
517
+ If you use SimpleCov to generate code coverage for your tests. You might have setup a `.simplecov` file to help control and focus it's output. Often the settings you want for your test's code coverage report are different than what you want Coverband to be reporting on. Since Coverband uses the SimpleCov HTML formatter to prepare it's report.
518
+
519
+ So if you had something like this in a `.simplecov` file in the root of your project, as reported in [issue 83](https://github.com/danmayer/coverband/issues/83)
520
+
521
+ ```
522
+ require 'simplecov'
523
+
524
+ SimpleCov.start do
525
+ add_filter 'app/admin'
526
+ add_filter '/spec/'
527
+ add_filter '/config/'
528
+ add_filter '/vendor/'
529
+ add_filter 'userevents'
530
+ end
531
+ ```
532
+
533
+ You could see some confusing results... To avoid this issue Coverband has a Rake task that will ignore all Simplecov filters.
534
+
535
+ `rake coverband:coverage_no_filters`
536
+
537
+ This will build the report after disabling any `.simplecov` applied settings.
538
+
403
539
  # Contributing To Coverband
404
540
 
405
541
  If you are working on adding features, PRs, or bugfixes to Coverband this section should help get you going.
@@ -408,24 +544,24 @@ If you are working on adding features, PRs, or bugfixes to Coverband this sectio
408
544
  2. Create your feature branch (`git checkout -b my-new-feature`)
409
545
  3. Commit your changes (`git commit -am 'Add some feature'`)
410
546
  4. Push to the branch (`git push origin my-new-feature`)
411
- 5. Make sure all tests are passing (run `bundle install`, make sure Redis is running, and then execute `bundle exec rake test`)
547
+ 5. Make sure all tests are passing (run `bundle install`, make sure Redis is running, and then execute `rake test`)
412
548
  6. Create new Pull Request
413
549
 
414
550
  ### Tests & Benchmarks
415
551
 
416
552
  If you submit a change please make sure the tests and benchmarks are passing.
417
553
 
418
- * run tests: `bundle exec rake`
554
+ * run tests: `rake`
419
555
  * view test coverage: `open coverage/index.html`
420
556
  * run the benchmarks before and after your change to see impact
421
- * `bundle exec rake benchmarks`
557
+ * `rake benchmarks`
422
558
 
423
559
  ### Known Issues
424
560
 
425
561
  * __total fail__ on front end code, because of the precompiled template step basically coverage doesn't work well for `erb`, `slim`, and the like.
562
+ * related it will try to report something, but the line numbers reported for `ERB` files are often off and aren't considered useful. I recommend filtering out .erb using the `config.ignore` option.
426
563
  * If you have SimpleCov filters, you need to clear them prior to generating your coverage report. As the filters will be applied to Coverband as well and can often filter out everything we are recording.
427
- * the line numbers reported for `ERB` files are often off and aren't considered useful. I recommend filtering out .erb using the `config.ignore` option.
428
- * coverage doesn't show for Rails `config/application.rb` or `config/boot.rb` as they get loaded when loading the Rake environment prior to starting to record the baseline..
564
+ * coverage doesn't show for Rails `config/application.rb` or `config/boot.rb` as they get loaded when loading the Rake environment prior to starting the `Coverage` library.
429
565
 
430
566
  ### Debugging Redis Store
431
567
 
@@ -496,19 +632,19 @@ Similar format to redis store, but array with integer values
496
632
 
497
633
  ### Todo
498
634
 
635
+ * add articles / podcasts like prontos readme https://github.com/prontolabs/pronto
499
636
  * graphite adapters (it would allow passing in date ranges on usage)
500
637
  * perf test for array vs hash
501
638
  * redis pipeline around hash (or batch get then push)
502
- * pass in namespace to redis (coverage vs baseline)
503
- * what about having baseline a onetime recording into redis no merge later
504
639
  * move to SimpleCov console out, or make similar console tabular output
505
- * Fix network performance by logging to files that purge later (like NR) (far more time lost in TracePoint than sending files, hence not a high priority, but would be cool)
640
+ * Improve network performance by logging to files that purge later (like NR) (far more time lost in TracePoint than sending files, hence not a high priority, but would be cool)
506
641
  * Add support for [zadd](http://redis.io/topics/data-types-intro) so one could determine single call versus multiple calls on a line, letting us determine the most executed code in production.
507
642
  * Possibly add ability to record code run for a given route
643
+ * integrate recording with deploy tag or deploy timestamp
644
+ * diff code usage across deployed versions
508
645
  * Improve client code api, around manual usage of sampling (like event usage)
509
646
  * ability to change the Coverband config at runtime by changing the config pushed to the Redis hash. In memory cache around the changes to only make that call periodically.
510
647
  * Opposed to just showing code usage on a route allow 'tagging' events which would record line coverage for that tag (this would allow tagging all code that modified an ActiveRecord model for example
511
- * mountable rack app to view coverage similar to flipper-ui
512
648
  * support runner, active job, etc without needed extra config (improved railtie integration)
513
649
 
514
650
  # Resources
data/Rakefile CHANGED
@@ -19,3 +19,10 @@ desc 'load irb with this gem'
19
19
  task :console do
20
20
  exec 'irb -I lib -r coverband'
21
21
  end
22
+
23
+ # This is really just for testing and development because without configuration
24
+ # Coverband can't do much
25
+ desc 'start webserver'
26
+ task :server do
27
+ exec 'rackup -I lib'
28
+ end
data/changes.md CHANGED
@@ -12,9 +12,49 @@ Will be the fully modern release that drops maintenance legacy support in favor
12
12
  * add built-in support for easy loading via Railties
13
13
  * expects to add safe list support to force reload files one wants coverage on that may happen outside of the standard load order
14
14
  * built in support for activejob, sidekiq, and other common frameworks
15
+ * code route tracing (entry point to all code executed for example /some_path -> code coverage of that path)
16
+
17
+ # Alpha
18
+
19
+ ### 3.0.0
20
+
21
+ * drop Tracepoint
22
+ * background thread reporter
23
+
24
+ # 2.0.3
25
+
26
+ * don''t include docs in the gemfile thanks @bquorning
27
+ * pipeline_redis to reduce network overhead thanks @Kallin
28
+ * various additional benchmarks @danmayer
29
+ * Filter out files with no coverage thanks @kbaum
30
+
15
31
 
16
32
  # Released
17
33
 
34
+ ### 2.0.2
35
+
36
+ * fix possible nil error on files that changed since initial recording @viktor-silakov
37
+ * add improve error logging in verbose mode (stacktrace) @viktor-silakov
38
+ * improved logging level support @viktor-silakov
39
+ * launch Coverband demo and integrate into Readme / Documentation
40
+ * fix on baseline to show an issue by @viktor-silakov
41
+ * remove all coverband:baseline related features and documentation
42
+ * dropped Sinatra requirement for web mountable page
43
+ * fix on filestore by @danrabinowitz
44
+ * fixes to the MemoryCacheStore by @kbaum
45
+
46
+ ### 2.0.1
47
+
48
+ * add support for fine grained S3 configuration via Coverband config, thanks @a0s
49
+ * https://github.com/danmayer/coverband/pull/98
50
+ * Using the file argument to self.configure in lib/coverband.rb, thanks @ThomasOwens
51
+ * https://github.com/danmayer/coverband/pull/100
52
+ * added redis improvements allowing namespace and TTL thx @oded-zahavi
53
+ * fix warnings about duplicate method definition
54
+ * Add support for safe_reload_files based on full file path
55
+ * Add support for Sinatra admin control endpoints
56
+ * improved documentation
57
+
18
58
  ### 2.0.0
19
59
 
20
60
  Major release with various backwards compatibility breaking changes (generally related to the configuration). The 2.0 lifecycle will act as a mostly easy upgrade that supports past users looking to move to the much faster new Coverage Adapter.
data/config.ru ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require ::File.expand_path('../lib/coverband', __FILE__)
4
+ run Coverband::Reporters::Web.new
data/coverband.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = 'https://github.com/danmayer/coverband'
15
15
  spec.license = 'MIT'
16
16
 
17
- spec.files = `git ls-files`.split("\n")
17
+ spec.files = `git ls-files`.split("\n").reject { |f| f.start_with?('docs') }
18
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ['lib']
@@ -26,7 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'rack'
27
27
  spec.add_development_dependency 'rack-test'
28
28
  spec.add_development_dependency 'rake'
29
- spec.add_development_dependency 'sinatra'
30
29
  spec.add_development_dependency 'test-unit'
31
30
  spec.add_development_dependency 'redis'
32
31
  spec.add_development_dependency 'benchmark-ips'
@@ -9,16 +9,18 @@ module Coverband
9
9
  class MemoryCacheStore < Base
10
10
  attr_accessor :store
11
11
 
12
+ @@files_cache = {}
13
+
12
14
  def initialize(store)
13
15
  @store = store
14
16
  end
15
17
 
16
- def self.reset!
17
- files_cache.clear
18
+ def self.clear!
19
+ @@files_cache.clear
18
20
  end
19
21
 
20
22
  def clear!
21
- self.class.reset!
23
+ self.class.clear!
22
24
  end
23
25
 
24
26
  def save_report(files)
@@ -26,28 +28,26 @@ module Coverband
26
28
  store.save_report(filtered_files) if filtered_files.any?
27
29
  end
28
30
 
29
- # rubocop:disable Lint/IneffectiveAccessModifier
30
31
  private
31
32
 
32
- def self.files_cache
33
- @files_cache ||= {}
34
- end
35
-
36
33
  def files_cache
37
- self.class.files_cache
34
+ @@files_cache
38
35
  end
39
36
 
40
37
  def filter(files)
41
- files.each_with_object({}) do |(file, lines), filtered_file_hash|
42
- # first time we see a file, we pre-init the in memory cache to whatever is in store(redis)
43
- line_cache = files_cache[file] ||= Set.new(store.covered_lines_for_file(file))
44
- lines.reject! do |line|
45
- line_cache.include?(line) ? true : (line_cache << line && false)
38
+ files.each_with_object({}) do |(file, covered_lines), filtered_file_hash|
39
+ if covered_lines != cached_file(file)
40
+ files_cache[file] = covered_lines
41
+ filtered_file_hash[file] = covered_lines
46
42
  end
47
- filtered_file_hash[file] = lines if lines.any?
48
43
  end
49
44
  end
50
- # rubocop:enable Lint/IneffectiveAccessModifier
45
+
46
+ def cached_file(file)
47
+ files_cache[file] ||= store.covered_lines_for_file(file).each_with_object({}) do |(line_number, value), hash|
48
+ hash[line_number.to_i] = value.to_i
49
+ end
50
+ end
51
51
  end
52
52
  end
53
53
  end