coverband-service-client 0.0.6 → 0.0.11
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 +4 -4
- data/Gemfile.lock +3 -3
- data/lib/coverband-service-client.rb +81 -26
- data/lib/coverband/service/client/version.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: a0d326e9f18a89a72e6a251e92b1a2c4d99a44288c1e695570327675017e5328
         | 
| 4 | 
            +
              data.tar.gz: 83efe304d0dac5797b63ad4dea23516df89ab211a0aa5809554c9b3fce5dfa82
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 3588eb3a0fc1c70afa925b61feaf92ee95b7169476e0008abac2ee83413a7ad0a02726876fda490089fb2008d17861f71cebd297dc78744de049fc62a82c2022
         | 
| 7 | 
            +
              data.tar.gz: ee29788c3d877f9cd0079615c30da437490cc3a4c6fb74ed7a0454d44b405ef041965c648b4e3d5162f775c13d8661165c578fa57993de090d39be253f34a139
         | 
    
        data/Gemfile.lock
    CHANGED
    
    | @@ -1,17 +1,17 @@ | |
| 1 1 | 
             
            PATH
         | 
| 2 2 | 
             
              remote: .
         | 
| 3 3 | 
             
              specs:
         | 
| 4 | 
            -
                coverband-service-client (0.0. | 
| 4 | 
            +
                coverband-service-client (0.0.11)
         | 
| 5 5 | 
             
                  coverband (~> 4.2.4)
         | 
| 6 6 |  | 
| 7 7 | 
             
            GEM
         | 
| 8 8 | 
             
              remote: https://rubygems.org/
         | 
| 9 9 | 
             
              specs:
         | 
| 10 | 
            -
                coverband (4.2. | 
| 10 | 
            +
                coverband (4.2.5)
         | 
| 11 11 | 
             
                  redis
         | 
| 12 12 | 
             
                minitest (5.14.0)
         | 
| 13 13 | 
             
                rake (13.0.1)
         | 
| 14 | 
            -
                redis (4.1. | 
| 14 | 
            +
                redis (4.1.4)
         | 
| 15 15 |  | 
| 16 16 | 
             
            PLATFORMS
         | 
| 17 17 | 
             
              ruby
         | 
| @@ -1,18 +1,31 @@ | |
| 1 1 | 
             
            # frozen_string_literal: true
         | 
| 2 2 |  | 
| 3 | 
            +
            COVERBAND_ORIGINAL_START = ENV['COVERBAND_DISABLE_AUTO_START']
         | 
| 4 | 
            +
            ENV['COVERBAND_DISABLE_AUTO_START'] = 'true'
         | 
| 5 | 
            +
            require 'coverband'
         | 
| 3 6 | 
             
            require 'coverband/service/client/version'
         | 
| 4 7 | 
             
            require 'securerandom'
         | 
| 5 8 |  | 
| 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 | 
            -
            COVERBAND_TIMEOUT = (COVERBAND_ENV == 'development') ? 5 : 1
         | 
| 10 | 
            -
             | 
| 11 9 | 
             
            module Coverband
         | 
| 10 | 
            +
              COVERBAND_ENV = ENV['RACK_ENV'] || ENV['RAILS_ENV'] || (defined?(Rails) ? Rails.env : 'unknown')
         | 
| 11 | 
            +
              COVERBAND_SERVICE_URL = ENV['COVERBAND_URL'] || 'https://coverband.io'
         | 
| 12 | 
            +
              COVERBAND_TIMEOUT = (COVERBAND_ENV == 'development') ? 5 : 1
         | 
| 13 | 
            +
              COVERBAND_ENABLE_DEV_MODE = ENV['COVERBAND_ENABLE_DEV_MODE'] || false
         | 
| 14 | 
            +
              COVERBAND_ENABLE_TEST_MODE = ENV['COVERBAND_ENABLE_TEST_MODE'] || false
         | 
| 15 | 
            +
              COVERBAND_PROCESS_TYPE = ENV['PROCESS_TYPE'] || 'unknown'
         | 
| 16 | 
            +
              COVERBAND_REPORT_PERIOD = (ENV['COVERBAND_REPORT_PERIOD'] || 600).to_i
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              def self.service_disabled_dev_test_env?
         | 
| 19 | 
            +
                (COVERBAND_ENV == 'test' && !COVERBAND_ENABLE_TEST_MODE) ||
         | 
| 20 | 
            +
                  (COVERBAND_ENV == 'development' && !COVERBAND_ENABLE_DEV_MODE)
         | 
| 21 | 
            +
              end
         | 
| 12 22 |  | 
| 13 | 
            -
              if  | 
| 23 | 
            +
              if service_disabled_dev_test_env?
         | 
| 14 24 | 
             
                def self.report_coverage
         | 
| 15 | 
            -
                  # for now disable coverband reporting in test env by default
         | 
| 25 | 
            +
                  # for now disable coverband reporting in test & dev env by default
         | 
| 26 | 
            +
                  if Coverband.configuration.verbose
         | 
| 27 | 
            +
                    puts "Coverband: disabled for #{COVERBAND_ENV}, set COVERBAND_ENABLE_DEV_MODE or COVERBAND_ENABLE_TEST_MODE to enable" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE
         | 
| 28 | 
            +
                  end
         | 
| 16 29 | 
             
                end
         | 
| 17 30 | 
             
              end
         | 
| 18 31 |  | 
| @@ -30,10 +43,14 @@ module Coverband | |
| 30 43 | 
             
                    def initialize(coverband_url, opts = {})
         | 
| 31 44 | 
             
                      super()
         | 
| 32 45 | 
             
                      @coverband_url = coverband_url
         | 
| 33 | 
            -
                      @process_type = opts.fetch(:process_type) {  | 
| 46 | 
            +
                      @process_type = opts.fetch(:process_type) { COVERBAND_PROCESS_TYPE }
         | 
| 34 47 | 
             
                      @runtime_env = opts.fetch(:runtime_env) { COVERBAND_ENV }
         | 
| 35 48 | 
             
                    end
         | 
| 36 49 |  | 
| 50 | 
            +
                    def logger
         | 
| 51 | 
            +
                      Coverband.configuration.logger
         | 
| 52 | 
            +
                    end
         | 
| 53 | 
            +
             | 
| 37 54 | 
             
                    def clear!
         | 
| 38 55 | 
             
                      # TBD
         | 
| 39 56 | 
             
                    end
         | 
| @@ -47,24 +64,25 @@ module Coverband | |
| 47 64 | 
             
                      0
         | 
| 48 65 | 
             
                    end
         | 
| 49 66 |  | 
| 50 | 
            -
                     | 
| 67 | 
            +
                    def api_key
         | 
| 68 | 
            +
                      ENV['COVERBAND_API_KEY'] || Coverband.configuration.api_key
         | 
| 69 | 
            +
                    end
         | 
| 70 | 
            +
             | 
| 51 71 | 
             
                    def coverage(local_type = nil, opts = {})
         | 
| 52 72 | 
             
                      local_type ||= opts.key?(:override_type) ? opts[:override_type] : type
         | 
| 53 | 
            -
                       | 
| 54 | 
            -
                       | 
| 73 | 
            +
                      env_filter = opts.key?(:env_filter) ? opts[:env_filter] : 'production'
         | 
| 74 | 
            +
                      uri = URI("#{coverband_url}/api/coverage?type=#{local_type}&env_filter=#{env_filter}",)
         | 
| 75 | 
            +
                      req = Net::HTTP::Get.new(uri, 'Content-Type' => 'application/json', 'Coverband-Token' => api_key)
         | 
| 55 76 | 
             
                      res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
         | 
| 56 77 | 
             
                        http.request(req)
         | 
| 57 78 | 
             
                      end
         | 
| 58 79 | 
             
                      coverage_data = JSON.parse(res.body)
         | 
| 59 | 
            -
                      # puts "coverage data: "
         | 
| 60 | 
            -
                      # puts coverage_data
         | 
| 61 80 | 
             
                      coverage_data
         | 
| 62 81 | 
             
                    rescue StandardError => e
         | 
| 63 | 
            -
                       | 
| 82 | 
            +
                      logger&.error "Coverband: Error while retrieving coverage #{e}" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE
         | 
| 64 83 | 
             
                    end
         | 
| 65 84 |  | 
| 66 85 | 
             
                    def save_report(report)
         | 
| 67 | 
            -
                      #puts caller.join(',')
         | 
| 68 86 | 
             
                      return if report.empty?
         | 
| 69 87 |  | 
| 70 88 | 
             
                      # TODO: do we need dup
         | 
| @@ -93,12 +111,17 @@ module Coverband | |
| 93 111 | 
             
                    private
         | 
| 94 112 |  | 
| 95 113 | 
             
                    def save_coverage(data)
         | 
| 114 | 
            +
                      if api_key.nil?
         | 
| 115 | 
            +
                        puts "Coverband: Error: no Coverband API key was found!"
         | 
| 116 | 
            +
                      end
         | 
| 117 | 
            +
             | 
| 96 118 | 
             
                      uri = URI("#{coverband_url}/api/collector")
         | 
| 97 119 | 
             
                      req = Net::HTTP::Post.new(uri,
         | 
| 98 120 | 
             
                                                'Content-Type' => 'application/json',
         | 
| 99 | 
            -
                                                'Coverband-Token' =>  | 
| 100 | 
            -
                      # puts "sending #{data}"
         | 
| 121 | 
            +
                                                'Coverband-Token' => api_key)
         | 
| 101 122 | 
             
                      req.body = { remote_uuid: SecureRandom.uuid, data: data }.to_json
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                      logger&.info "Coverband: saving (#{uri}) #{req.body}" if Coverband.configuration.verbose
         | 
| 102 125 | 
             
                      res = Net::HTTP.start(
         | 
| 103 126 | 
             
                        uri.hostname,
         | 
| 104 127 | 
             
                        uri.port,
         | 
| @@ -110,7 +133,7 @@ module Coverband | |
| 110 133 | 
             
                        http.request(req)
         | 
| 111 134 | 
             
                      end
         | 
| 112 135 | 
             
                    rescue StandardError => e
         | 
| 113 | 
            -
                       | 
| 136 | 
            +
                      logger&.info "Coverband: Error while saving coverage #{e}" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE
         | 
| 114 137 | 
             
                    end
         | 
| 115 138 | 
             
                  end
         | 
| 116 139 | 
             
                end
         | 
| @@ -144,14 +167,22 @@ module Coverband | |
| 144 167 | 
             
                  rescue StandardError => e
         | 
| 145 168 | 
             
                    # we don't want to raise errors if Coverband can't reach redis.
         | 
| 146 169 | 
             
                    # This is a nice to have not a bring the system down
         | 
| 147 | 
            -
                    logger&.error "Coverband: view_tracker failed to store, error #{e.class.name}"
         | 
| 170 | 
            +
                    logger&.error "Coverband: view_tracker failed to store, error #{e.class.name}" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE
         | 
| 148 171 | 
             
                  end
         | 
| 149 172 |  | 
| 150 173 | 
             
                  private
         | 
| 151 174 |  | 
| 175 | 
            +
                  def api_key
         | 
| 176 | 
            +
                    ENV['COVERBAND_API_KEY'] || Coverband.configuration.api_key
         | 
| 177 | 
            +
                  end
         | 
| 178 | 
            +
             | 
| 179 | 
            +
                  def logger
         | 
| 180 | 
            +
                    Coverband.configuration.logger
         | 
| 181 | 
            +
                  end
         | 
| 182 | 
            +
             | 
| 152 183 | 
             
                  def save_tracked_views(views:, reported_time:)
         | 
| 153 184 | 
             
                    uri = URI("#{COVERBAND_SERVICE_URL}/api/collector")
         | 
| 154 | 
            -
                    req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json', 'Coverband-Token' =>  | 
| 185 | 
            +
                    req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json', 'Coverband-Token' => api_key)
         | 
| 155 186 | 
             
                    data = {
         | 
| 156 187 | 
             
                      collection_type: 'view_tracker_delta',
         | 
| 157 188 | 
             
                      collection_data: {
         | 
| @@ -168,25 +199,49 @@ module Coverband | |
| 168 199 | 
             
                      http.request(req)
         | 
| 169 200 | 
             
                    end
         | 
| 170 201 | 
             
                  rescue StandardError => e
         | 
| 171 | 
            -
                     | 
| 202 | 
            +
                    logger&.error "Coverband: Error while saving coverage #{e}" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE
         | 
| 172 203 | 
             
                  end
         | 
| 173 204 | 
             
                end
         | 
| 174 205 | 
             
              end
         | 
| 175 206 | 
             
            end
         | 
| 176 207 |  | 
| 208 | 
            +
            module Coverband
         | 
| 209 | 
            +
              class Configuration
         | 
| 210 | 
            +
                attr_accessor :api_key
         | 
| 211 | 
            +
              end
         | 
| 212 | 
            +
            end
         | 
| 213 | 
            +
             | 
| 214 | 
            +
            ENV['COVERBAND_DISABLE_AUTO_START'] = COVERBAND_ORIGINAL_START
         | 
| 177 215 | 
             
            Coverband.configure do |config|
         | 
| 178 216 | 
             
              # Use The Test Service Adapter
         | 
| 179 | 
            -
              config.store = Coverband::Adapters::Service.new(COVERBAND_SERVICE_URL)
         | 
| 217 | 
            +
              config.store = Coverband::Adapters::Service.new(Coverband::COVERBAND_SERVICE_URL)
         | 
| 180 218 |  | 
| 181 219 | 
             
              # default to tracking views true
         | 
| 182 | 
            -
              config.track_views = ENV[' | 
| 220 | 
            +
              config.track_views = if ENV['COVERBAND_DISABLE_VIEW_TRACKER']
         | 
| 221 | 
            +
                  false
         | 
| 222 | 
            +
                elsif Coverband.service_disabled_dev_test_env?
         | 
| 223 | 
            +
                  false
         | 
| 224 | 
            +
                else
         | 
| 225 | 
            +
                  true
         | 
| 226 | 
            +
                end
         | 
| 183 227 |  | 
| 184 228 | 
             
              # report every 10m by default
         | 
| 185 | 
            -
              config.background_reporting_sleep_seconds = COVERBAND_ENV == 'production' ?  | 
| 229 | 
            +
              config.background_reporting_sleep_seconds = Coverband::COVERBAND_ENV == 'production' ? Coverband::COVERBAND_REPORT_PERIOD : 60
         | 
| 186 230 | 
             
              # add a wiggle to avoid service stampede
         | 
| 187 | 
            -
              config.reporting_wiggle = COVERBAND_ENV == 'production' ? 90 : 6
         | 
| 231 | 
            +
              config.reporting_wiggle = Coverband::COVERBAND_ENV == 'production' ? 90 : 6
         | 
| 188 232 |  | 
| 189 | 
            -
              if COVERBAND_ENV == 'test'
         | 
| 233 | 
            +
              if Coverband::COVERBAND_ENV == 'test'
         | 
| 190 234 | 
             
                config.background_reporting_enabled = false
         | 
| 191 235 | 
             
              end
         | 
| 192 236 | 
             
            end
         | 
| 237 | 
            +
             | 
| 238 | 
            +
            # NOTE: it is really hard to bypass / overload our config we should fix this in Coverband
         | 
| 239 | 
            +
            # this hopefully detects anyone that has both gems and was trying to configure Coverband themselves.
         | 
| 240 | 
            +
            if File.exist?('./config/coverband.rb')
         | 
| 241 | 
            +
              puts "Warning: config/coverband.rb found, this overrides coverband service allowing one to setup open source Coverband" if Coverband.configuration.verbose || COVERBAND_ENABLE_DEV_MODE
         | 
| 242 | 
            +
            end
         | 
| 243 | 
            +
             | 
| 244 | 
            +
            Coverband.configure('./config/coverband_service.rb') if File.exist?('./config/coverband_service.rb')
         | 
| 245 | 
            +
            Coverband.start
         | 
| 246 | 
            +
            require "coverband/utils/railtie" if defined? ::Rails::Railtie
         | 
| 247 | 
            +
            require "coverband/integrations/resque" if defined? ::Resque
         | 
    
        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. | 
| 4 | 
            +
              version: 0.0.11
         | 
| 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- | 
| 12 | 
            +
            date: 2020-05-26 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: bundler
         |