scout_apm 2.3.0.pre → 2.3.0.pre1
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/lib/scout_apm/config.rb +2 -0
- data/lib/scout_apm/fake_store.rb +6 -0
- data/lib/scout_apm/instant/middleware.rb +6 -1
- data/lib/scout_apm/layer_converters/database_converter.rb +37 -11
- data/lib/scout_apm/store.rb +9 -11
- data/lib/scout_apm/version.rb +1 -1
- data/test/unit/fake_store_test.rb +10 -0
- data/test/unit/store_test.rb +4 -4
- metadata +4 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 87d20e596496af9d020ff073a6c0a6dd5f25989b
         | 
| 4 | 
            +
              data.tar.gz: 76a903858e591025ec82842c3f2a6d30a66f35fd
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d9733bb68af60c98eafddc3ad2d469173987214bc785e80deff2bd6f87161b1c256ca8cdc7b525656cae8bebe06332772b42a4896f624b1a70ca69882f26df1d
         | 
| 7 | 
            +
              data.tar.gz: e5a84284b84bb95bea7cbe7dda0bddfafc79e1180c833f8709d778cbbbc926d617c9f94f2a55dbf8870bd5869088bca8727227172823e7358d6b98617248a8ed
         | 
    
        data/lib/scout_apm/config.rb
    CHANGED
    
    
    
        data/lib/scout_apm/fake_store.rb
    CHANGED
    
    | @@ -17,6 +17,12 @@ module ScoutApm | |
| 17 17 | 
             
                def track_one!(type, name, value, options={})
         | 
| 18 18 | 
             
                end
         | 
| 19 19 |  | 
| 20 | 
            +
                def track_histograms!(histograms, options={})
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def track_db_query_metrics!(db_query_metric_set, options={})
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 20 26 | 
             
                def track_slow_transaction!(slow_transaction)
         | 
| 21 27 | 
             
                end
         | 
| 22 28 |  | 
| @@ -224,7 +224,12 @@ module ScoutApm | |
| 224 224 | 
             
                  end
         | 
| 225 225 |  | 
| 226 226 | 
             
                  def trace
         | 
| 227 | 
            -
                    @trace ||= | 
| 227 | 
            +
                    @trace ||=
         | 
| 228 | 
            +
                      begin
         | 
| 229 | 
            +
                        layer_finder = LayerConverters::FindLayerByType.new(tracked_request)
         | 
| 230 | 
            +
                        converter = LayerConverters::SlowRequestConverter.new(tracked_request, layer_finder, ScoutApm::FakeStore.new)
         | 
| 231 | 
            +
                        converter.call
         | 
| 232 | 
            +
                      end
         | 
| 228 233 | 
             
                  end
         | 
| 229 234 |  | 
| 230 235 | 
             
                  def payload
         | 
| @@ -15,8 +15,8 @@ module ScoutApm | |
| 15 15 | 
             
                      next if skip_layer?(layer)
         | 
| 16 16 |  | 
| 17 17 | 
             
                      stat = DbQueryMetricStats.new(
         | 
| 18 | 
            -
                        layer | 
| 19 | 
            -
                        layer | 
| 18 | 
            +
                        model_name(layer),
         | 
| 19 | 
            +
                        operation_name(layer),
         | 
| 20 20 | 
             
                        scope_layer.legacy_metric_name, # controller_scope
         | 
| 21 21 | 
             
                        1,                              # count, this is a single query, so 1
         | 
| 22 22 | 
             
                        layer.total_call_time,
         | 
| @@ -26,15 +26,6 @@ module ScoutApm | |
| 26 26 | 
             
                    end
         | 
| 27 27 | 
             
                  end
         | 
| 28 28 |  | 
| 29 | 
            -
                  def skip_layer?(layer)
         | 
| 30 | 
            -
                    layer.type != 'ActiveRecord'            ||
         | 
| 31 | 
            -
                    layer.limited?                          ||
         | 
| 32 | 
            -
                    ( ! layer.name.respond_to?(:model))     ||
         | 
| 33 | 
            -
                    ( ! layer.name.respond_to?(:normalized_operation)) ||
         | 
| 34 | 
            -
                    layer.name.model.nil?                   ||
         | 
| 35 | 
            -
                    layer.name.normalized_operation.nil?
         | 
| 36 | 
            -
                  end
         | 
| 37 | 
            -
             | 
| 38 29 | 
             
                  def record!
         | 
| 39 30 | 
             
                    # Everything in the metric set here is from a single transaction, which
         | 
| 40 31 | 
             
                    # we want to keep track of. (One web call did a User#find 10 times, but
         | 
| @@ -43,6 +34,41 @@ module ScoutApm | |
| 43 34 | 
             
                    @store.track_db_query_metrics!(@db_query_metric_set)
         | 
| 44 35 | 
             
                  end
         | 
| 45 36 |  | 
| 37 | 
            +
                  def skip_layer?(layer)
         | 
| 38 | 
            +
                    layer.type != 'ActiveRecord' ||
         | 
| 39 | 
            +
                      layer.limited? ||
         | 
| 40 | 
            +
                      super
         | 
| 41 | 
            +
                  end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  private
         | 
| 44 | 
            +
             | 
| 45 | 
            +
             | 
| 46 | 
            +
                  # If we can't name the model, default to:
         | 
| 47 | 
            +
                  DEFAULT_MODEL = "SQL"
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  # If we can't name the operation, default to:
         | 
| 50 | 
            +
                  DEFAULT_OPERATION = "other"
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                  def model_name(layer)
         | 
| 53 | 
            +
                    if layer.name.respond_to?(:model)
         | 
| 54 | 
            +
                      layer.name.model || DEFAULT_MODEL
         | 
| 55 | 
            +
                    else
         | 
| 56 | 
            +
                      DEFAULT_MODEL
         | 
| 57 | 
            +
                    end
         | 
| 58 | 
            +
                  rescue
         | 
| 59 | 
            +
                    DEFAULT_MODEL
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  def operation_name(layer)
         | 
| 63 | 
            +
                    if layer.name.respond_to?(:normalized_operation)
         | 
| 64 | 
            +
                      layer.name.normalized_operation || DEFAULT_OPERATION
         | 
| 65 | 
            +
                    else
         | 
| 66 | 
            +
                      DEFAULT_OPERATION
         | 
| 67 | 
            +
                    end
         | 
| 68 | 
            +
                  rescue
         | 
| 69 | 
            +
                    DEFAULT_OPERATION
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
             | 
| 46 72 | 
             
                  def records_returned(layer)
         | 
| 47 73 | 
             
                    if layer.annotations
         | 
| 48 74 | 
             
                      layer.annotations.fetch(:record_count, 0)
         | 
    
        data/lib/scout_apm/store.rb
    CHANGED
    
    | @@ -3,12 +3,6 @@ | |
| 3 3 | 
             
            # the layaway file for cross-process aggregation.
         | 
| 4 4 | 
             
            module ScoutApm
         | 
| 5 5 | 
             
              class Store
         | 
| 6 | 
            -
                # A hash of reporting periods. { StoreReportingPeriodTimestamp => StoreReportingPeriod }
         | 
| 7 | 
            -
                attr_reader :reporting_periods
         | 
| 8 | 
            -
             | 
| 9 | 
            -
                # Used to pull metrics into each reporting period, as that reporting period is finished.
         | 
| 10 | 
            -
                attr_reader :samplers
         | 
| 11 | 
            -
             | 
| 12 6 | 
             
                def initialize
         | 
| 13 7 | 
             
                  @mutex = Mutex.new
         | 
| 14 8 | 
             
                  @reporting_periods = Hash.new { |h,k| h[k] = StoreReportingPeriod.new(k) }
         | 
| @@ -20,8 +14,9 @@ module ScoutApm | |
| 20 14 | 
             
                end
         | 
| 21 15 |  | 
| 22 16 | 
             
                def current_period
         | 
| 23 | 
            -
                  reporting_periods[current_timestamp]
         | 
| 17 | 
            +
                  @reporting_periods[current_timestamp]
         | 
| 24 18 | 
             
                end
         | 
| 19 | 
            +
                private :current_period
         | 
| 25 20 |  | 
| 26 21 | 
             
                def find_period(timestamp = nil)
         | 
| 27 22 | 
             
                  if timestamp
         | 
| @@ -30,6 +25,7 @@ module ScoutApm | |
| 30 25 | 
             
                    current_period
         | 
| 31 26 | 
             
                  end
         | 
| 32 27 | 
             
                end
         | 
| 28 | 
            +
                private :find_period
         | 
| 33 29 |  | 
| 34 30 | 
             
                # Save newly collected metrics
         | 
| 35 31 | 
             
                def track!(metrics, options={})
         | 
| @@ -90,7 +86,7 @@ module ScoutApm | |
| 90 86 | 
             
                def write_to_layaway(layaway, force=false)
         | 
| 91 87 | 
             
                  ScoutApm::Agent.instance.logger.debug("Writing to layaway#{" (Forced)" if force}")
         | 
| 92 88 |  | 
| 93 | 
            -
                    reporting_periods.select { |time, rp| force || (time.timestamp < current_timestamp.timestamp) }.
         | 
| 89 | 
            +
                    @reporting_periods.select { |time, rp| force || (time.timestamp < current_timestamp.timestamp) }.
         | 
| 94 90 | 
             
                                      each   { |time, rp| collect_samplers(rp) }.
         | 
| 95 91 | 
             
                                      each   { |time, rp| write_reporting_period(layaway, time, rp) }
         | 
| 96 92 | 
             
                end
         | 
| @@ -102,10 +98,11 @@ module ScoutApm | |
| 102 98 | 
             
                rescue => e
         | 
| 103 99 | 
             
                  ScoutApm::Agent.instance.logger.warn("Failed writing data to layaway file: #{e.message} / #{e.backtrace}")
         | 
| 104 100 | 
             
                ensure
         | 
| 105 | 
            -
                  ScoutApm::Agent.instance.logger.debug("Before delete, reporting periods length: #{reporting_periods.size}")
         | 
| 106 | 
            -
                  deleted_items = reporting_periods.delete(time)
         | 
| 107 | 
            -
                  ScoutApm::Agent.instance.logger.debug("After delete, reporting periods length: #{reporting_periods.size}. Did delete #{deleted_items}")
         | 
| 101 | 
            +
                  ScoutApm::Agent.instance.logger.debug("Before delete, reporting periods length: #{@reporting_periods.size}")
         | 
| 102 | 
            +
                  deleted_items = @reporting_periods.delete(time)
         | 
| 103 | 
            +
                  ScoutApm::Agent.instance.logger.debug("After delete, reporting periods length: #{@reporting_periods.size}. Did delete #{deleted_items}")
         | 
| 108 104 | 
             
                end
         | 
| 105 | 
            +
                private :write_reporting_period
         | 
| 109 106 |  | 
| 110 107 | 
             
                ######################################
         | 
| 111 108 | 
             
                # Sampler support
         | 
| @@ -123,6 +120,7 @@ module ScoutApm | |
| 123 120 | 
             
                    end
         | 
| 124 121 | 
             
                  end
         | 
| 125 122 | 
             
                end
         | 
| 123 | 
            +
                private :collect_samplers
         | 
| 126 124 | 
             
              end
         | 
| 127 125 |  | 
| 128 126 | 
             
              # A timestamp, normalized to the beginning of a minute. Used as a hash key to
         | 
    
        data/lib/scout_apm/version.rb
    CHANGED
    
    
    
        data/test/unit/store_test.rb
    CHANGED
    
    | @@ -14,11 +14,11 @@ class StoreTest < Minitest::Test | |
| 14 14 | 
             
                s = ScoutApm::Store.new
         | 
| 15 15 | 
             
                s.track_one!("Controller", "user/show", 10)
         | 
| 16 16 |  | 
| 17 | 
            -
                assert_equal(1, s.reporting_periods.size)
         | 
| 17 | 
            +
                assert_equal(1, s.instance_variable_get('@reporting_periods').size)
         | 
| 18 18 |  | 
| 19 19 | 
             
                s.write_to_layaway(FakeFailingLayaway.new, true)
         | 
| 20 20 |  | 
| 21 | 
            -
                assert_equal({}, s.reporting_periods)
         | 
| 21 | 
            +
                assert_equal({}, s.instance_variable_get('@reporting_periods'))
         | 
| 22 22 | 
             
              end
         | 
| 23 23 |  | 
| 24 24 | 
             
              def test_writing_layaway_removes_stale_timestamps
         | 
| @@ -29,11 +29,11 @@ class StoreTest < Minitest::Test | |
| 29 29 | 
             
                s = ScoutApm::Store.new
         | 
| 30 30 | 
             
                ScoutApm::Instruments::Process::ProcessMemory.new(Logger.new(StringIO.new)).metrics(stale_rp.timestamp, s)
         | 
| 31 31 | 
             
                ScoutApm::Instruments::Process::ProcessMemory.new(Logger.new(StringIO.new)).metrics(current_rp.timestamp, s)
         | 
| 32 | 
            -
                assert_equal 2, s.reporting_periods.size
         | 
| 32 | 
            +
                assert_equal 2, s.instance_variable_get('@reporting_periods').size
         | 
| 33 33 |  | 
| 34 34 | 
             
                s.write_to_layaway(FakeFailingLayaway.new, true)
         | 
| 35 35 |  | 
| 36 | 
            -
                assert_equal({}, s.reporting_periods)
         | 
| 36 | 
            +
                assert_equal({}, s.instance_variable_get('@reporting_periods'))
         | 
| 37 37 | 
             
              end
         | 
| 38 38 | 
             
            end
         | 
| 39 39 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: scout_apm
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2.3.0. | 
| 4 | 
            +
              version: 2.3.0.pre1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Derek Haynes
         | 
| @@ -9,7 +9,7 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2017-09- | 
| 12 | 
            +
            date: 2017-09-28 00:00:00.000000000 Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: minitest
         | 
| @@ -294,6 +294,7 @@ files: | |
| 294 294 | 
             
            - test/unit/db_query_metric_set_test.rb
         | 
| 295 295 | 
             
            - test/unit/db_query_metric_stats_test.rb
         | 
| 296 296 | 
             
            - test/unit/environment_test.rb
         | 
| 297 | 
            +
            - test/unit/fake_store_test.rb
         | 
| 297 298 | 
             
            - test/unit/git_revision_test.rb
         | 
| 298 299 | 
             
            - test/unit/histogram_test.rb
         | 
| 299 300 | 
             
            - test/unit/ignored_uris_test.rb
         | 
| @@ -356,6 +357,7 @@ test_files: | |
| 356 357 | 
             
            - test/unit/db_query_metric_set_test.rb
         | 
| 357 358 | 
             
            - test/unit/db_query_metric_stats_test.rb
         | 
| 358 359 | 
             
            - test/unit/environment_test.rb
         | 
| 360 | 
            +
            - test/unit/fake_store_test.rb
         | 
| 359 361 | 
             
            - test/unit/git_revision_test.rb
         | 
| 360 362 | 
             
            - test/unit/histogram_test.rb
         | 
| 361 363 | 
             
            - test/unit/ignored_uris_test.rb
         |