scout_apm 3.0.0.pre13 → 3.0.0.pre14

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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/lib/scout_apm.rb +20 -10
  3. data/lib/scout_apm/agent.rb +114 -319
  4. data/lib/scout_apm/agent/exit_handler.rb +66 -0
  5. data/lib/scout_apm/agent/preconditions.rb +69 -0
  6. data/lib/scout_apm/agent_context.rb +234 -0
  7. data/lib/scout_apm/app_server_load.rb +24 -14
  8. data/lib/scout_apm/background_job_integrations/resque.rb +7 -8
  9. data/lib/scout_apm/background_job_integrations/sidekiq.rb +2 -2
  10. data/lib/scout_apm/background_recorder.rb +8 -3
  11. data/lib/scout_apm/background_worker.rb +14 -7
  12. data/lib/scout_apm/config.rb +35 -26
  13. data/lib/scout_apm/context.rb +11 -4
  14. data/lib/scout_apm/db_query_metric_set.rb +17 -5
  15. data/lib/scout_apm/debug.rb +1 -1
  16. data/lib/scout_apm/environment.rb +10 -14
  17. data/lib/scout_apm/framework_integrations/sinatra.rb +1 -1
  18. data/lib/scout_apm/git_revision.rb +13 -8
  19. data/lib/scout_apm/histogram.rb +1 -1
  20. data/lib/scout_apm/instant/middleware.rb +7 -7
  21. data/lib/scout_apm/instant_reporting.rb +7 -7
  22. data/lib/scout_apm/instrument_manager.rb +87 -0
  23. data/lib/scout_apm/instruments/action_controller_rails_2.rb +12 -7
  24. data/lib/scout_apm/instruments/action_controller_rails_3_rails4.rb +17 -12
  25. data/lib/scout_apm/instruments/action_view.rb +11 -7
  26. data/lib/scout_apm/instruments/active_record.rb +25 -11
  27. data/lib/scout_apm/instruments/elasticsearch.rb +10 -6
  28. data/lib/scout_apm/instruments/grape.rb +12 -8
  29. data/lib/scout_apm/instruments/http_client.rb +10 -6
  30. data/lib/scout_apm/instruments/influxdb.rb +10 -6
  31. data/lib/scout_apm/instruments/middleware_detailed.rb +11 -5
  32. data/lib/scout_apm/instruments/middleware_summary.rb +11 -5
  33. data/lib/scout_apm/instruments/mongoid.rb +10 -5
  34. data/lib/scout_apm/instruments/moped.rb +11 -6
  35. data/lib/scout_apm/instruments/net_http.rb +10 -6
  36. data/lib/scout_apm/instruments/percentile_sampler.rb +8 -6
  37. data/lib/scout_apm/instruments/process/process_cpu.rb +8 -4
  38. data/lib/scout_apm/instruments/process/process_memory.rb +15 -10
  39. data/lib/scout_apm/instruments/rails_router.rb +12 -6
  40. data/lib/scout_apm/instruments/redis.rb +10 -6
  41. data/lib/scout_apm/instruments/samplers.rb +11 -0
  42. data/lib/scout_apm/instruments/sinatra.rb +5 -4
  43. data/lib/scout_apm/layaway.rb +21 -20
  44. data/lib/scout_apm/layaway_file.rb +8 -3
  45. data/lib/scout_apm/layer.rb +3 -3
  46. data/lib/scout_apm/layer_converters/converter_base.rb +6 -7
  47. data/lib/scout_apm/layer_converters/database_converter.rb +1 -1
  48. data/lib/scout_apm/layer_converters/histograms.rb +2 -2
  49. data/lib/scout_apm/layer_converters/slow_job_converter.rb +4 -3
  50. data/lib/scout_apm/layer_converters/slow_request_converter.rb +5 -4
  51. data/lib/scout_apm/logger.rb +143 -0
  52. data/lib/scout_apm/middleware.rb +7 -9
  53. data/lib/scout_apm/periodic_work.rb +28 -0
  54. data/lib/scout_apm/reporter.rb +14 -8
  55. data/lib/scout_apm/reporting.rb +135 -0
  56. data/lib/scout_apm/request_manager.rb +4 -6
  57. data/lib/scout_apm/serializers/payload_serializer.rb +1 -1
  58. data/lib/scout_apm/slow_job_policy.rb +6 -2
  59. data/lib/scout_apm/slow_job_record.rb +5 -5
  60. data/lib/scout_apm/slow_request_policy.rb +6 -2
  61. data/lib/scout_apm/slow_transaction.rb +5 -5
  62. data/lib/scout_apm/store.rb +22 -16
  63. data/lib/scout_apm/synchronous_recorder.rb +7 -3
  64. data/lib/scout_apm/tasks/doctor.rb +75 -0
  65. data/lib/scout_apm/tasks/support.rb +22 -0
  66. data/lib/scout_apm/tracer.rb +5 -5
  67. data/lib/scout_apm/tracked_request.rb +43 -19
  68. data/lib/scout_apm/utils/active_record_metric_name.rb +66 -8
  69. data/lib/scout_apm/utils/backtrace_parser.rb +1 -1
  70. data/lib/scout_apm/utils/installed_gems.rb +7 -3
  71. data/lib/scout_apm/utils/klass_helper.rb +8 -2
  72. data/lib/scout_apm/utils/scm.rb +1 -1
  73. data/lib/scout_apm/utils/sql_sanitizer.rb +3 -3
  74. data/lib/scout_apm/version.rb +1 -1
  75. data/lib/tasks/doctor.rake +11 -0
  76. data/scout_apm.gemspec +1 -0
  77. data/test/test_helper.rb +17 -2
  78. data/test/unit/agent_test.rb +1 -54
  79. data/test/unit/config_test.rb +9 -5
  80. data/test/unit/context_test.rb +4 -4
  81. data/test/unit/db_query_metric_set_test.rb +11 -4
  82. data/test/unit/fake_store_test.rb +1 -1
  83. data/test/unit/git_revision_test.rb +3 -3
  84. data/test/unit/instruments/net_http_test.rb +2 -1
  85. data/test/unit/instruments/percentile_sampler_test.rb +5 -9
  86. data/test/unit/layaway_test.rb +10 -5
  87. data/test/unit/layer_converters/metric_converter_test.rb +2 -2
  88. data/test/unit/slow_request_policy_test.rb +7 -3
  89. data/test/unit/sql_sanitizer_test.rb +0 -6
  90. data/test/unit/store_test.rb +11 -8
  91. data/test/unit/utils/active_record_metric_name_test.rb +45 -7
  92. metadata +27 -5
  93. data/lib/scout_apm/agent/logging.rb +0 -74
  94. data/lib/scout_apm/agent/reporting.rb +0 -129
  95. data/lib/scout_apm/utils/null_logger.rb +0 -13
@@ -4,7 +4,7 @@ module ScoutApm
4
4
  class Scm
5
5
  # Takes an *already relative* path +path+
6
6
  # Returns a relative path, prepending the configured +scm_subdirectory+ environment string
7
- def self.relative_scm_path(path, scm_subdirectory = ScoutApm::Environment.instance.scm_subdirectory)
7
+ def self.relative_scm_path(path, scm_subdirectory = ScoutApm::Agent.instance.context.environment.scm_subdirectory)
8
8
  @@scm_subdirectory ||= scm_subdirectory.sub(/^\//, '')
9
9
  @@scm_subdirectoy_blank ||= @@scm_subdirectory.empty?
10
10
  @@scm_subdirectoy_blank ? path : File.join(@@scm_subdirectory, path)
@@ -16,7 +16,7 @@ module ScoutApm
16
16
 
17
17
  def initialize(sql)
18
18
  @raw_sql = sql
19
- @database_engine = ScoutApm::Environment.instance.database_engine
19
+ @database_engine = ScoutApm::Agent.instance.context.environment.database_engine
20
20
  @sanitized = false # only sanitize once.
21
21
  end
22
22
 
@@ -78,13 +78,13 @@ module ScoutApm
78
78
  return '' if !str.is_a?(String) || str.length > 4000 # safeguard - don't sanitize or scrub large SQL statements
79
79
  return str if !str.respond_to?(:encode) # Ruby <= 1.8 doesn't have string encoding
80
80
  return str if str.valid_encoding? # Whatever encoding it is, it is valid and we can operate on it
81
- ScoutApm::Agent.instance.logger.debug "Scrubbing invalid sql encoding."
81
+ ScoutApm::Agent.instance.context.logger.debug "Scrubbing invalid sql encoding."
82
82
  if str.respond_to?(:scrub) # Prefer to scrub before we have to convert
83
83
  return str.scrub('_')
84
84
  elsif has_encodings?(['UTF-8', 'binary'])
85
85
  return str.encode('UTF-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '_')
86
86
  end
87
- ScoutApm::Agent.instance.logger.debug "Unable to scrub invalid sql encoding."
87
+ ScoutApm::Agent.instance.context.logger.debug "Unable to scrub invalid sql encoding."
88
88
  ''
89
89
  end
90
90
 
@@ -1,3 +1,3 @@
1
1
  module ScoutApm
2
- VERSION = "3.0.0.pre13"
2
+ VERSION = "3.0.0.pre14"
3
3
  end
@@ -0,0 +1,11 @@
1
+ namespace :scout do
2
+ desc "Prints out details of the detected environment"
3
+ task :doctor => :environment do
4
+ ScoutApm::Tasks::Doctor.run!
5
+ end
6
+
7
+ desc "Collect logs, settings and environment to help debug issues"
8
+ task :support => :environment do
9
+ ScoutApm::Tasks::Support.run!
10
+ end
11
+ end
@@ -31,4 +31,5 @@ Gem::Specification.new do |s|
31
31
  s.add_development_dependency "addressable"
32
32
  s.add_development_dependency "guard"
33
33
  s.add_development_dependency "guard-minitest"
34
+ s.add_development_dependency "activesupport"
34
35
  end
@@ -9,6 +9,8 @@ require 'mocha/mini_test'
9
9
  require 'pry'
10
10
 
11
11
 
12
+ require 'active_support/core_ext/string/inflections'
13
+
12
14
  require 'scout_apm'
13
15
 
14
16
  Kernel.module_eval do
@@ -39,6 +41,14 @@ class FakeConfigOverlay
39
41
  def has_key?(key)
40
42
  @values.has_key?(key)
41
43
  end
44
+
45
+ def name
46
+ "agent-test-config-overlay"
47
+ end
48
+
49
+ def any_keys_found?
50
+ true
51
+ end
42
52
  end
43
53
 
44
54
  class FakeEnvironment
@@ -64,7 +74,7 @@ class Minitest::Test
64
74
  end
65
75
 
66
76
  def teardown
67
- ScoutApm::Agent.instance.shutdown
77
+ ScoutApm::Agent.instance.stop_background_worker
68
78
  File.delete(DATA_FILE_PATH) if File.exist?(DATA_FILE_PATH)
69
79
  end
70
80
 
@@ -83,8 +93,13 @@ class Minitest::Test
83
93
  FakeEnvironment.new(values)
84
94
  end
85
95
 
96
+ # XXX: Make it easy to override context here?
86
97
  def make_fake_config(values)
87
- ScoutApm::Config.new(FakeConfigOverlay.new(values))
98
+ ScoutApm::Config.new(agent_context, [FakeConfigOverlay.new(values), ScoutApm::Config::ConfigNull.new] )
99
+ end
100
+
101
+ def agent_context
102
+ ScoutApm::AgentContext.new
88
103
  end
89
104
 
90
105
  DATA_FILE_DIR = File.dirname(__FILE__) + '/tmp'
@@ -1,58 +1,5 @@
1
1
  require 'test_helper'
2
- require 'scout_apm/agent'
3
- require 'scout_apm/slow_transaction'
4
- require 'scout_apm/metric_meta'
5
- require 'scout_apm/metric_stats'
6
- require 'scout_apm/context'
7
- require 'scout_apm/store'
8
2
 
9
3
  class AgentTest < Minitest::Test
10
-
11
- # Safeguard to ensure the main agent thread doesn't have any interaction with the layaway file. Contention on file locks can cause delays.
12
- def test_start_with_lock_on_layaway_file
13
- # setup the file, putting a lock on it.
14
- File.open(DATA_FILE_PATH, "w") {}
15
- f = File.open(DATA_FILE_PATH, File::RDWR | File::CREAT)
16
- f.flock(File::LOCK_EX)
17
-
18
- agent = ScoutApm::Agent.instance
19
-
20
- no_timeout = true
21
- begin
22
- Timeout::timeout(3) { agent.start({:monitor => true, :force => true}) }
23
- rescue Timeout::Error
24
- no_timeout = false
25
- ensure
26
- f.flock(File::LOCK_UN)
27
- f.close
28
- end
29
- assert no_timeout, "Agent took >= 3s to start. Possible file lock issue."
30
- end
31
-
32
- def test_reset_file_with_old_format
33
- File.open(DATA_FILE_PATH, 'w') { |file| file.write(Marshal.dump(OLD_FORMAT)) }
34
- begin
35
- ScoutApm::Agent.instance(:force => true).process_metrics
36
- rescue NoMethodError
37
- # The agent will raise an exception the first time metrics are processed for scout_apm < 1.2.
38
- #
39
- # NoMethodError: undefined method `values' for []:Array
40
- # /Users/dlite/projects/scout_apm_ruby/lib/scout_apm/layaway.rb:46:in `periods_ready_for_delivery'
41
- # /Users/dlite/projects/scout_apm_ruby/lib/scout_apm/agent/reporting.rb:31:in `report_to_server'
42
- # /Users/dlite/projects/scout_apm_ruby/lib/scout_apm/agent/reporting.rb:24:in `process_metrics'
43
- # /Users/dlite/projects/scout_apm_ruby/test/unit/layaway_test.rb:27:in `test_reset_file_with_old_format'
44
- end
45
- # Data will be fine the next go-around
46
- no_error = true
47
- begin
48
- ScoutApm::Agent.instance(:force => true).process_metrics
49
- rescue Exception => e
50
- no_error = false
51
- end
52
- assert no_error, "Error trying to process metrics after upgrading from < 1.2 data format: #{e.message if e}"
53
- end
54
-
55
- ## TODO - adds tests to ensure other potentially long-running things don't sneak in, like HTTP calls.
56
-
57
- OLD_FORMAT = {1452533280 => {:metrics => {}, :slow_transactions => {}} } # Pre 1.2 agents used a different file format to store data.
4
+ # XXX: Write tests around agent startup sequence
58
5
  end
@@ -3,8 +3,12 @@ require 'test_helper'
3
3
  require 'scout_apm/config'
4
4
 
5
5
  class ConfigTest < Minitest::Test
6
+ def setup
7
+ @context = ScoutApm::AgentContext.new
8
+ end
9
+
6
10
  def test_initalize_without_a_config
7
- conf = ScoutApm::Config.without_file
11
+ conf = ScoutApm::Config.without_file(@context)
8
12
 
9
13
  # nil for random keys
10
14
  assert_nil conf.value('log_file_path')
@@ -21,7 +25,7 @@ class ConfigTest < Minitest::Test
21
25
  set_rack_env('production')
22
26
 
23
27
  conf_file = File.expand_path('../../data/config_test_1.yml', __FILE__)
24
- conf = ScoutApm::Config.with_file(conf_file)
28
+ conf = ScoutApm::Config.with_file(@context, conf_file)
25
29
 
26
30
  assert_equal 'debug', conf.value('log_level')
27
31
  assert_equal 'APM Test Conf (Production)', conf.value('name')
@@ -29,7 +33,7 @@ class ConfigTest < Minitest::Test
29
33
 
30
34
  def test_loading_file_without_env_in_file
31
35
  conf_file = File.expand_path("../../data/config_test_1.yml", __FILE__)
32
- conf = ScoutApm::Config.with_file(conf_file, environment: "staging")
36
+ conf = ScoutApm::Config.with_file(@context, conf_file, environment: "staging")
33
37
 
34
38
  assert_equal "info", conf.value('log_level') # the default value
35
39
  assert_nil nil, conf.value('name') # the default value
@@ -71,11 +75,11 @@ class ConfigTest < Minitest::Test
71
75
  def test_any_keys_found
72
76
  ENV.stubs(:has_key?).returns(nil)
73
77
 
74
- conf = ScoutApm::Config.with_file("a_file_that_doesnt_exist.yml")
78
+ conf = ScoutApm::Config.with_file(@context, "a_file_that_doesnt_exist.yml")
75
79
  assert ! conf.any_keys_found?
76
80
 
77
81
  ENV.stubs(:has_key?).with("SCOUT_MONITOR").returns("true")
78
- conf = ScoutApm::Config.with_file("a_file_that_doesnt_exist.yml")
82
+ conf = ScoutApm::Config.with_file(@context, "a_file_that_doesnt_exist.yml")
79
83
  assert conf.any_keys_found?
80
84
  end
81
85
  end
@@ -4,25 +4,25 @@ require 'scout_apm/context'
4
4
 
5
5
  class ContextText < Minitest::Test
6
6
  def test_ignore_nil_value
7
- context = ScoutApm::Context.new
7
+ context = ScoutApm::Context.new(ScoutApm::AgentContext.new)
8
8
  assert hash = context.add(:nil_key => nil, :org => 'org')
9
9
  assert_equal ({:org => 'org'}), hash
10
10
  end
11
11
 
12
12
  def test_ignore_nil_key
13
- context = ScoutApm::Context.new
13
+ context = ScoutApm::Context.new(ScoutApm::AgentContext.new)
14
14
  assert hash = context.add(nil => nil, :org => 'org')
15
15
  assert_equal ({:org => 'org'}), hash
16
16
  end
17
17
 
18
18
  def test_ignore_unsupported_value_type
19
- context = ScoutApm::Context.new
19
+ context = ScoutApm::Context.new(ScoutApm::AgentContext.new)
20
20
  assert hash = context.add(:array => [1,2,3,4], :org => 'org')
21
21
  assert_equal ({:org => 'org'}), hash
22
22
  end
23
23
 
24
24
  def test_ignore_unsupported_key_type
25
- context = ScoutApm::Context.new
25
+ context = ScoutApm::Context.new(ScoutApm::AgentContext.new)
26
26
  assert hash = context.add([1,2,3,4] => 'hey', :org => 'org')
27
27
  assert_equal ({:org => 'org'}), hash
28
28
  end
@@ -8,7 +8,9 @@ class DbQueryMetricSetTest < Minitest::Test
8
8
  config = make_fake_config(
9
9
  'database_metric_limit' => 5, # The hard limit on db metrics
10
10
  'database_metric_report_limit' => 2,)
11
- set = DbQueryMetricSet.new(config)
11
+ context = ScoutApm::AgentContext.new().tap{|c| c.config = config }
12
+ set = DbQueryMetricSet.new(context)
13
+
12
14
  set << fake_stat("a", 10)
13
15
  set << fake_stat("b", 20)
14
16
  set << fake_stat("c", 30)
@@ -23,7 +25,8 @@ class DbQueryMetricSetTest < Minitest::Test
23
25
  config = make_fake_config(
24
26
  'database_metric_limit' => 50, # much larger max, uninterested in hitting it.
25
27
  'database_metric_report_limit' => 2,)
26
- set = DbQueryMetricSet.new(config)
28
+ context = ScoutApm::AgentContext.new().tap{|c| c.config = config }
29
+ set = DbQueryMetricSet.new(context)
27
30
  set << fake_stat("a", 10)
28
31
  set << fake_stat("b", 20)
29
32
  set << fake_stat("c", 30)
@@ -36,10 +39,14 @@ class DbQueryMetricSetTest < Minitest::Test
36
39
  end
37
40
 
38
41
  def test_combine
39
- set1 = DbQueryMetricSet.new
42
+ config = make_fake_config(
43
+ 'database_metric_limit' => 5, # The hard limit on db metrics
44
+ 'database_metric_report_limit' => 2,)
45
+ context = ScoutApm::AgentContext.new().tap{|c| c.config = config }
46
+ set1 = DbQueryMetricSet.new(context)
40
47
  set1 << fake_stat("a", 10)
41
48
  set1 << fake_stat("b", 20)
42
- set2 = DbQueryMetricSet.new
49
+ set2 = DbQueryMetricSet.new(context)
43
50
  set2 << fake_stat("c", 10)
44
51
  set2 << fake_stat("d", 20)
45
52
 
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class FakeStoreTest < Minitest::Test
4
4
  def test_responds_to_same_instance_methods_as_store
5
5
  fs = ScoutApm::FakeStore.new
6
- s = ScoutApm::Store.new
6
+ s = ScoutApm::Store.new(ScoutApm::AgentContext.new)
7
7
 
8
8
  assert_equal [], s.methods - fs.methods
9
9
  end
@@ -6,10 +6,10 @@ class GitRevisionTest < Minitest::Test
6
6
  # TODO - other tests that would be nice:
7
7
  # * ensure we only detect once, on initialize.
8
8
  # * tests for reading cap files
9
-
9
+
10
10
  def test_sha_from_heroku
11
11
  ENV['HEROKU_SLUG_COMMIT'] = 'heroku_slug'
12
- revision = ScoutApm::GitRevision.new
12
+ revision = ScoutApm::GitRevision.new(ScoutApm::AgentContext.new)
13
13
  assert_equal 'heroku_slug', revision.sha
14
14
  end
15
- end
15
+ end
@@ -6,7 +6,8 @@ require 'addressable'
6
6
 
7
7
  class NetHttpTest < Minitest::Test
8
8
  def setup
9
- ScoutApm::Instruments::NetHttp.new.install
9
+ @context = ScoutApm::AgentContext.new
10
+ ScoutApm::Instruments::NetHttp.new(@context).install
10
11
  end
11
12
 
12
13
  def test_request_scout_description_for_uri
@@ -9,13 +9,13 @@ class PercentileSamplerTest < Minitest::Test
9
9
  attr_reader :subject
10
10
 
11
11
  def setup
12
- @subject = PercentileSampler.new(logger, histograms)
12
+ @context = ScoutApm::AgentContext.new
13
+ @subject = PercentileSampler.new(@context)
13
14
  end
14
15
 
15
-
16
16
  def test_initialize_with_logger_and_histogram_set
17
- assert_equal subject.logger, logger
18
- assert_equal subject.histograms, histograms
17
+ assert_equal subject.logger, @context.logger
18
+ assert_equal subject.histograms, @context.request_histograms_by_time
19
19
  end
20
20
 
21
21
  def test_implements_instrument_interface
@@ -113,11 +113,7 @@ class PercentileSamplerTest < Minitest::Test
113
113
  end
114
114
 
115
115
  def histograms
116
- @histograms ||= begin
117
- @request_histograms_by_time = Hash.new { |hash, key|
118
- hash[key] = ScoutApm::RequestHistograms.new
119
- }
120
- end
116
+ @context.request_histograms_by_time
121
117
  end
122
118
 
123
119
  def histogram
@@ -10,27 +10,32 @@ class LayawayTest < Minitest::Test
10
10
  def test_directory_uses_DATA_FILE_option
11
11
  FileUtils.mkdir_p '/tmp/scout_apm_test/data_file_option'
12
12
  config = make_fake_config("data_file" => "/tmp/scout_apm_test/data_file_option")
13
+ context = ScoutApm::AgentContext.new().tap{|c| c.config = config }
14
+ layaway = ScoutApm::Layaway.new(context)
13
15
 
14
- assert_equal Pathname.new("/tmp/scout_apm_test/data_file_option"), ScoutApm::Layaway.new(config, ScoutApm::Agent.instance.environment).directory
16
+ assert_equal Pathname.new("/tmp/scout_apm_test/data_file_option"), layaway.directory
15
17
  end
16
18
 
17
19
  def test_directory_looks_for_root_slash_tmp
18
20
  FileUtils.mkdir_p '/tmp/scout_apm_test/tmp'
19
21
  config = make_fake_config({})
20
22
  env = make_fake_environment(:root => "/tmp/scout_apm_test")
23
+ context = ScoutApm::AgentContext.new().tap{|c| c.config = config; c.environment = env }
21
24
 
22
- assert_equal Pathname.new("/tmp/scout_apm_test/tmp"), ScoutApm::Layaway.new(config, env).directory
25
+ assert_equal Pathname.new("/tmp/scout_apm_test/tmp"), ScoutApm::Layaway.new(context).directory
23
26
  end
24
27
 
25
28
  def test_layaway_file_limit_prevents_new_writes
26
29
  FileUtils.mkdir_p '/tmp/scout_apm_test/layaway_limit'
27
30
  config = make_fake_config("data_file" => "/tmp/scout_apm_test/layaway_limit")
28
- layaway = ScoutApm::Layaway.new(config, ScoutApm::Agent.instance.environment)
31
+ context = ScoutApm::AgentContext.new().tap{|c| c.config = config }
32
+ layaway = ScoutApm::Layaway.new(context)
29
33
  layaway.delete_files_for(:all)
30
34
 
35
+ context = ScoutApm::AgentContext.new
31
36
  current_time = Time.now.utc
32
- current_rp = ScoutApm::StoreReportingPeriod.new(current_time)
33
- stale_rp = ScoutApm::StoreReportingPeriod.new(current_time - current_time.sec - 120)
37
+ current_rp = ScoutApm::StoreReportingPeriod.new(current_time, context)
38
+ stale_rp = ScoutApm::StoreReportingPeriod.new(current_time - current_time.sec - 120, context)
34
39
 
35
40
  # layaway.write_reporting_period returns nil on successful write
36
41
  # It should probably be changed to return true or the number of bytes written
@@ -7,13 +7,13 @@ class MetricConverterTest < Minitest::Test
7
7
  include Stubs
8
8
 
9
9
  def test_register_adds_hooks
10
- mc = MetricConverter.new(faux_request, faux_layer_finder, faux_store)
10
+ mc = MetricConverter.new(agent_context, faux_request, faux_layer_finder, faux_store)
11
11
  faux_walker.expects(:on)
12
12
  mc.register_hooks(faux_walker)
13
13
  end
14
14
 
15
15
  def test_record
16
- mc = MetricConverter.new(faux_request, faux_layer_finder, faux_store)
16
+ mc = MetricConverter.new(agent_context, faux_request, faux_layer_finder, faux_store)
17
17
  faux_store.expects(:track!)
18
18
  mc.record!
19
19
  end
@@ -17,9 +17,13 @@ class FakeRequest
17
17
  end
18
18
 
19
19
  class SlowRequestPolicyTest < Minitest::Test
20
+ def setup
21
+ @context = ScoutApm::AgentContext.new
22
+ end
23
+
20
24
  def test_stored_records_current_time
21
25
  test_start = Time.now
22
- policy = ScoutApm::SlowRequestPolicy.new
26
+ policy = ScoutApm::SlowRequestPolicy.new(@context)
23
27
  request = FakeRequest.new("users/index")
24
28
 
25
29
  policy.stored!(request)
@@ -27,12 +31,12 @@ class SlowRequestPolicyTest < Minitest::Test
27
31
  end
28
32
 
29
33
  def test_score
30
- policy = ScoutApm::SlowRequestPolicy.new
34
+ policy = ScoutApm::SlowRequestPolicy.new(@context)
31
35
  request = FakeRequest.new("users/index")
32
36
 
33
37
  request.set_duration(10) # 10 seconds
34
38
  policy.last_seen[request.unique_name] = Time.now - 120 # 2 minutes since last seen
35
- ScoutApm::Agent.instance.request_histograms.add(request.unique_name, 1)
39
+ @context.request_histograms.add(request.unique_name, 1)
36
40
 
37
41
  # Actual value I have in console is 1.499
38
42
  assert policy.score(request) > 1.45
@@ -1,14 +1,8 @@
1
1
  require 'test_helper'
2
2
 
3
- require 'scout_apm/utils/sql_sanitizer'
4
-
5
3
  module ScoutApm
6
4
  module Utils
7
5
  class SqlSanitizerTest < Minitest::Test
8
- def setup
9
- ScoutApm::Agent.instance.init_logger
10
- end
11
-
12
6
  # Too long, and we just bail out to prevent long running instrumentation
13
7
  def test_long_sql
14
8
  sql = " " * 1001