scout_apm 2.1.32 → 2.2.0.pre0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/CHANGELOG.markdown +2 -161
  4. data/Rakefile +2 -2
  5. data/ext/allocations/allocations.c +0 -6
  6. data/ext/allocations/extconf.rb +0 -1
  7. data/ext/stacks/extconf.rb +33 -0
  8. data/ext/stacks/scout_atomics.h +86 -0
  9. data/ext/stacks/stacks.c +744 -0
  10. data/lib/scout_apm.rb +16 -24
  11. data/lib/scout_apm/agent.rb +38 -93
  12. data/lib/scout_apm/agent/logging.rb +1 -6
  13. data/lib/scout_apm/agent/reporting.rb +6 -8
  14. data/lib/scout_apm/app_server_load.rb +10 -21
  15. data/lib/scout_apm/attribute_arranger.rb +2 -0
  16. data/lib/scout_apm/background_job_integrations/delayed_job.rb +1 -71
  17. data/lib/scout_apm/background_job_integrations/sidekiq.rb +27 -66
  18. data/lib/scout_apm/background_worker.rb +15 -19
  19. data/lib/scout_apm/capacity.rb +57 -0
  20. data/lib/scout_apm/config.rb +29 -135
  21. data/lib/scout_apm/context.rb +5 -9
  22. data/lib/scout_apm/deploy_integrations/capistrano_2.cap +12 -0
  23. data/lib/scout_apm/deploy_integrations/capistrano_2.rb +83 -0
  24. data/lib/scout_apm/deploy_integrations/capistrano_3.cap +12 -0
  25. data/lib/scout_apm/deploy_integrations/capistrano_3.rb +88 -0
  26. data/lib/scout_apm/environment.rb +15 -22
  27. data/lib/scout_apm/histogram.rb +2 -11
  28. data/lib/scout_apm/instant/assets/xmlhttp_instrumentation.html +2 -2
  29. data/lib/scout_apm/instant/middleware.rb +57 -198
  30. data/lib/scout_apm/instruments/action_controller_rails_2.rb +2 -1
  31. data/lib/scout_apm/instruments/action_controller_rails_3_rails4.rb +59 -90
  32. data/lib/scout_apm/instruments/active_record.rb +5 -7
  33. data/lib/scout_apm/instruments/delayed_job.rb +57 -0
  34. data/lib/scout_apm/instruments/grape.rb +3 -4
  35. data/lib/scout_apm/instruments/middleware_detailed.rb +6 -4
  36. data/lib/scout_apm/instruments/middleware_summary.rb +1 -39
  37. data/lib/scout_apm/instruments/mongoid.rb +3 -24
  38. data/lib/scout_apm/instruments/net_http.rb +2 -7
  39. data/lib/scout_apm/instruments/percentile_sampler.rb +19 -36
  40. data/lib/scout_apm/instruments/process/process_cpu.rb +2 -3
  41. data/lib/scout_apm/instruments/process/process_memory.rb +3 -3
  42. data/lib/scout_apm/layaway.rb +33 -76
  43. data/lib/scout_apm/layer.rb +59 -16
  44. data/lib/scout_apm/layer_converters/converter_base.rb +0 -199
  45. data/lib/scout_apm/layer_converters/job_converter.rb +1 -1
  46. data/lib/scout_apm/layer_converters/metric_converter.rb +1 -1
  47. data/lib/scout_apm/layer_converters/slow_job_converter.rb +90 -15
  48. data/lib/scout_apm/layer_converters/slow_request_converter.rb +101 -13
  49. data/lib/scout_apm/metric_set.rb +1 -9
  50. data/lib/scout_apm/metric_stats.rb +8 -8
  51. data/lib/scout_apm/reporter.rb +15 -51
  52. data/lib/scout_apm/request_histograms.rb +0 -4
  53. data/lib/scout_apm/request_manager.rb +1 -2
  54. data/lib/scout_apm/scored_item_set.rb +0 -7
  55. data/lib/scout_apm/serializers/deploy_serializer.rb +16 -0
  56. data/lib/scout_apm/serializers/payload_serializer.rb +3 -9
  57. data/lib/scout_apm/serializers/payload_serializer_to_json.rb +5 -2
  58. data/lib/scout_apm/serializers/slow_jobs_serializer_to_json.rb +1 -2
  59. data/lib/scout_apm/server_integrations/puma.rb +2 -5
  60. data/lib/scout_apm/slow_item_set.rb +80 -0
  61. data/lib/scout_apm/slow_job_record.rb +1 -6
  62. data/lib/scout_apm/slow_transaction.rb +2 -20
  63. data/lib/scout_apm/store.rb +12 -50
  64. data/lib/scout_apm/trace_compactor.rb +311 -0
  65. data/lib/scout_apm/tracked_request.rb +37 -128
  66. data/lib/scout_apm/utils/backtrace_parser.rb +5 -7
  67. data/lib/scout_apm/utils/fake_stacks.rb +83 -0
  68. data/lib/scout_apm/version.rb +1 -1
  69. data/scout_apm.gemspec +4 -6
  70. data/test/test_helper.rb +0 -56
  71. data/test/unit/config_test.rb +9 -60
  72. data/test/unit/histogram_test.rb +0 -14
  73. data/test/unit/layaway_test.rb +16 -31
  74. data/test/unit/serializers/payload_serializer_test.rb +105 -3
  75. data/test/unit/slow_item_set_test.rb +94 -0
  76. data/test/unit/slow_job_policy_test.rb +49 -0
  77. data/test/unit/slow_request_policy_test.rb +5 -4
  78. data/test/unit/utils/backtrace_parser_test.rb +0 -19
  79. data/tester.rb +53 -0
  80. metadata +29 -124
  81. data/.rubocop.yml +0 -8
  82. data/Guardfile +0 -42
  83. data/ext/rusage/README.md +0 -26
  84. data/ext/rusage/extconf.rb +0 -5
  85. data/ext/rusage/rusage.c +0 -52
  86. data/lib/scout_apm/background_job_integrations/resque.rb +0 -85
  87. data/lib/scout_apm/background_recorder.rb +0 -43
  88. data/lib/scout_apm/debug.rb +0 -37
  89. data/lib/scout_apm/git_revision.rb +0 -51
  90. data/lib/scout_apm/instruments/action_view.rb +0 -49
  91. data/lib/scout_apm/instruments/resque.rb +0 -40
  92. data/lib/scout_apm/layer_children_set.rb +0 -77
  93. data/lib/scout_apm/limited_layer.rb +0 -122
  94. data/lib/scout_apm/rack.rb +0 -26
  95. data/lib/scout_apm/remote/message.rb +0 -23
  96. data/lib/scout_apm/remote/recorder.rb +0 -57
  97. data/lib/scout_apm/remote/router.rb +0 -49
  98. data/lib/scout_apm/remote/server.rb +0 -58
  99. data/lib/scout_apm/serializers/histograms_serializer_to_json.rb +0 -21
  100. data/lib/scout_apm/synchronous_recorder.rb +0 -26
  101. data/lib/scout_apm/utils/gzip_helper.rb +0 -24
  102. data/lib/scout_apm/utils/numbers.rb +0 -14
  103. data/lib/scout_apm/utils/scm.rb +0 -14
  104. data/test/unit/background_job_integrations/sidekiq_test.rb +0 -104
  105. data/test/unit/context_test.rb +0 -30
  106. data/test/unit/git_revision_test.rb +0 -15
  107. data/test/unit/instruments/net_http_test.rb +0 -21
  108. data/test/unit/instruments/percentile_sampler_test.rb +0 -137
  109. data/test/unit/layer_children_set_test.rb +0 -88
  110. data/test/unit/limited_layer_test.rb +0 -53
  111. data/test/unit/remote/test_message.rb +0 -13
  112. data/test/unit/remote/test_router.rb +0 -33
  113. data/test/unit/remote/test_server.rb +0 -15
  114. data/test/unit/store_test.rb +0 -89
  115. data/test/unit/test_tracked_request.rb +0 -87
  116. data/test/unit/utils/numbers_test.rb +0 -15
  117. data/test/unit/utils/scm.rb +0 -17
@@ -1,104 +0,0 @@
1
- require 'test_helper'
2
- require 'scout_apm/request_manager'
3
- require 'scout_apm/background_job_integrations/sidekiq'
4
-
5
- class SidekiqTest < Minitest::Test
6
- SidekiqMiddleware = ScoutApm::BackgroundJobIntegrations::SidekiqMiddleware
7
-
8
- ########################################
9
- # Middleware
10
- ########################################
11
- def test_middleware_call_happy_path
12
- fake_request = mock
13
- fake_request.expects(:annotate_request)
14
- fake_request.expects(:job!)
15
- fake_request.expects(:start_layer).twice
16
- fake_request.expects(:stop_layer).twice
17
- fake_request.expects(:error!).never
18
-
19
- ScoutApm::RequestManager.stubs(:lookup).returns(fake_request)
20
-
21
- block_called = false
22
- msg = { 'class' => 'MyJobClass',
23
- 'created_at' => Time.now }
24
-
25
- SidekiqMiddleware.new.call(nil, msg, "defaultqueue") { block_called = true }
26
- assert_equal true, block_called
27
- end
28
-
29
- def test_middleware_call_job_exception
30
- fake_request = mock
31
- fake_request.expects(:annotate_request)
32
- fake_request.expects(:job!)
33
- fake_request.expects(:start_layer).twice
34
- fake_request.expects(:stop_layer).twice
35
- fake_request.expects(:error!)
36
-
37
- ScoutApm::RequestManager.stubs(:lookup).returns(fake_request)
38
-
39
- msg = { 'class' => 'MyJobClass',
40
- 'created_at' => Time.now }
41
-
42
- assert_raises RuntimeError do
43
- SidekiqMiddleware.new.call(nil, msg, "defaultqueue") { raise "TheJobFailed" }
44
- end
45
- end
46
-
47
- def test_middleware_call_edge_cases
48
- fake_request = mock
49
- fake_request.expects(:annotate_request)
50
- fake_request.expects(:job!)
51
- fake_request.expects(:start_layer).twice
52
- fake_request.expects(:stop_layer).twice
53
- fake_request.expects(:error!)
54
-
55
- ScoutApm::RequestManager.stubs(:lookup).returns(fake_request)
56
-
57
- # msg doesn't have anything
58
- msg = { }
59
-
60
- assert_raises RuntimeError do
61
- SidekiqMiddleware.new.call(nil, msg, "defaultqueue") { raise "TheJobFailed" }
62
- end
63
- end
64
-
65
- ########################################
66
- # Job Class Determination
67
- ########################################
68
- def test_job_class_name_normally
69
- msg = { 'class' => 'AGreatJob' }
70
- assert_equal 'AGreatJob', SidekiqMiddleware.new.job_class(msg)
71
- end
72
-
73
- def test_job_class_name_activejob
74
- msg = { 'class' => 'ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper',
75
- 'wrapped' => 'RealJobClass' }
76
- assert_equal 'RealJobClass', SidekiqMiddleware.new.job_class(msg)
77
- end
78
-
79
- def test_job_class_name_error_default
80
- msg = {}
81
- assert_equal 'UnknownJob', SidekiqMiddleware.new.job_class(msg)
82
- end
83
-
84
- ########################################
85
- # Latency Calculation
86
- ########################################
87
- def test_latency_from_created_at
88
- # Created at time 80, but now it is 200. Latency was 120
89
- msg = { 'created_at' => 80 }
90
- assert_equal 120, SidekiqMiddleware.new.latency(msg, 200)
91
- end
92
-
93
- def test_latency_from_enqueued_at
94
- # Created at time 80, but now it is 200. Latency was 120
95
- msg = { 'enqueued_at' => 80 }
96
- assert_equal 120, SidekiqMiddleware.new.latency(msg, 200)
97
- end
98
-
99
- def test_latency_fallback
100
- # No created at time, so fall back to 0
101
- msg = {}
102
- assert_equal 0, SidekiqMiddleware.new.latency(msg, 200)
103
- end
104
- end
@@ -1,30 +0,0 @@
1
- require 'test_helper'
2
-
3
- require 'scout_apm/context'
4
-
5
- class ContextText < Minitest::Test
6
- def test_ignore_nil_value
7
- context = ScoutApm::Context.new
8
- assert hash = context.add(:nil_key => nil, :org => 'org')
9
- assert_equal ({:org => 'org'}), hash
10
- end
11
-
12
- def test_ignore_nil_key
13
- context = ScoutApm::Context.new
14
- assert hash = context.add(nil => nil, :org => 'org')
15
- assert_equal ({:org => 'org'}), hash
16
- end
17
-
18
- def test_ignore_unsupported_value_type
19
- context = ScoutApm::Context.new
20
- assert hash = context.add(:array => [1,2,3,4], :org => 'org')
21
- assert_equal ({:org => 'org'}), hash
22
- end
23
-
24
- def test_ignore_unsupported_key_type
25
- context = ScoutApm::Context.new
26
- assert hash = context.add([1,2,3,4] => 'hey', :org => 'org')
27
- assert_equal ({:org => 'org'}), hash
28
- end
29
- end
30
-
@@ -1,15 +0,0 @@
1
- require 'test_helper'
2
-
3
- require 'scout_apm/git_revision'
4
-
5
- class GitRevisionTest < Minitest::Test
6
- # TODO - other tests that would be nice:
7
- # * ensure we only detect once, on initialize.
8
- # * tests for reading cap files
9
-
10
- def test_sha_from_heroku
11
- ENV['HEROKU_SLUG_COMMIT'] = 'heroku_slug'
12
- revision = ScoutApm::GitRevision.new
13
- assert_equal 'heroku_slug', revision.sha
14
- end
15
- end
@@ -1,21 +0,0 @@
1
- require 'test_helper'
2
-
3
- require 'scout_apm/instruments/net_http'
4
-
5
- require 'addressable'
6
-
7
- class NetHttpTest < Minitest::Test
8
- def setup
9
- ScoutApm::Instruments::NetHttp.new.install
10
- end
11
-
12
- def test_request_scout_description_for_uri
13
- req = Net::HTTP::Get.new(URI('http://example.org/here'))
14
- assert_equal '/here', Net::HTTP.new('').request_scout_description(req)
15
- end
16
-
17
- def test_request_scout_description_for_addressable
18
- req = Net::HTTP::Get.new(Addressable::URI.parse('http://example.org/here'))
19
- assert_equal '/here', Net::HTTP.new('').request_scout_description(req)
20
- end
21
- end
@@ -1,137 +0,0 @@
1
- require 'test_helper'
2
-
3
- require 'scout_apm/instruments/percentile_sampler'
4
-
5
- class PercentileSamplerTest < Minitest::Test
6
- PercentileSampler = ScoutApm::Instruments::PercentileSampler
7
- HistogramReport = ScoutApm::Instruments::HistogramReport
8
-
9
- attr_reader :subject
10
-
11
- def setup
12
- @subject = PercentileSampler.new(logger, histograms)
13
- end
14
-
15
-
16
- def test_initialize_with_logger_and_histogram_set
17
- assert_equal subject.logger, logger
18
- assert_equal subject.histograms, histograms
19
- end
20
-
21
- def test_implements_instrument_interface
22
- assert subject.respond_to?(:human_name)
23
- end
24
-
25
- def test_percentiles_returns_one_percentile_per_endpoint_at_time
26
- histograms[time].add("foo", 10)
27
- histograms[time].add("bar", 15)
28
- histograms[time2].add("baz", 15)
29
-
30
- assert_equal subject.percentiles(time).length, 2
31
- assert_equal subject.percentiles(time2).length, 1
32
- end
33
-
34
- def test_percentiles_clears_time_from_hash
35
- histograms[time].add("foo", 10)
36
- histograms[time2].add("baz", 15)
37
-
38
- subject.percentiles(time)
39
-
40
- assert_false histograms.key?(time)
41
- assert histograms.key?(time + 10)
42
- end
43
-
44
- def test_percentiles_returns_histogram_reports
45
- histograms[time].add("foo", 10)
46
-
47
- assert subject.percentiles(time).
48
- all?{ |item| item.is_a?(HistogramReport) }
49
- end
50
-
51
- def test_percentiles_returns_correct_histogram_report
52
- histograms[time].add("foo", 100)
53
- histograms[time].add("foo", 200)
54
- histograms[time].add("foo", 100)
55
- histograms[time].add("foo", 300)
56
-
57
- report = subject.percentiles(time).first
58
- histogram = report.histogram
59
-
60
- assert_equal "foo", report.name
61
- assert_equal 4, histogram.total
62
- assert_equal [[2, 100], [1, 200], [1, 300]],
63
- histogram.bins.map{|bin| [bin.count, bin.value] }
64
- end
65
-
66
- def test_metrics_saves_histogram_to_store
67
- store = mock
68
- store.expects(:track_histograms!)
69
- subject.metrics(ScoutApm::StoreReportingPeriodTimestamp.new(time), store)
70
- end
71
-
72
-
73
- ################################################################################
74
- # HistogramReport Test
75
- ################################################################################
76
- def test_histogram_report_combine_refuses_to_combine_mismatched_name
77
- assert_raises { HistogramReport.new("foo", histogram).combine!(HistogramReport.new("bar", histogram)) }
78
- end
79
-
80
- def test_histogram_report_merge_keeps_name
81
- report1 = HistogramReport.new("foo", histogram)
82
- report2 = HistogramReport.new("foo", histogram)
83
- combined = report1.combine!(report2)
84
-
85
- assert "foo", combined.name
86
- end
87
-
88
- def test_histogram_report_combine_merges_histograms
89
- histogram1 = histogram
90
- histogram2 = histogram
91
- histogram1.add(1)
92
- histogram1.add(2)
93
- histogram2.add(2)
94
- histogram2.add(3)
95
-
96
- report1 = HistogramReport.new("foo", histogram1)
97
- report2 = HistogramReport.new("foo", histogram2)
98
- combined = report1.combine!(report2)
99
-
100
- assert_equal 4, combined.histogram.total
101
- assert_equal [[1, 1], [2, 2], [1, 3]],
102
- combined.histogram.bins.map{|bin| [bin.count, bin.value.to_i] }
103
- end
104
-
105
- ################################################################################
106
- # Test Helpers
107
- ################################################################################
108
- def logger
109
- @logger ||= begin
110
- @logger_io = StringIO.new
111
- Logger.new(@logger_io)
112
- end
113
- end
114
-
115
- def histograms
116
- @histograms ||= begin
117
- @request_histograms_by_time = Hash.new { |hash, key|
118
- hash[key] = ScoutApm::RequestHistograms.new
119
- }
120
- end
121
- end
122
-
123
- def histogram
124
- max_bins = 20
125
- ScoutApm::NumericHistogram.new(max_bins)
126
- end
127
-
128
- # An arbitrary time
129
- def time
130
- @time ||= Time.now
131
- end
132
-
133
- def time2
134
- time + 10
135
- end
136
- end
137
-
@@ -1,88 +0,0 @@
1
- require 'test_helper'
2
- require 'scout_apm/layer_children_set'
3
-
4
- class LayerChildrenSetTest < Minitest::Test
5
- SET = ScoutApm::LayerChildrenSet
6
-
7
- def test_limit_default
8
- assert_equal SET::DEFAULT_UNIQUE_CUTOFF, SET.new.unique_cutoff
9
- end
10
-
11
- # Add 5, make sure they're all in the children list we get back.
12
- def test_add_layer_before_limit
13
- s = SET.new(5)
14
-
15
- 5.times do
16
- s << make_layer("LayerType", "LayerName")
17
- end
18
-
19
- children = s.to_a
20
- assert_equal 5, children.size
21
-
22
- # Don't care about order
23
- (0..4).each do |i|
24
- assert children.include?(lookup_layer(i))
25
- end
26
- end
27
-
28
- def test_add_layer_after_limit
29
- s = SET.new(5)
30
-
31
- 10.times do
32
- s << make_layer("LayerType", "LayerName")
33
- end
34
-
35
- children = s.to_a
36
- # 6 = 5 real ones + 1 merged.
37
- assert_equal 6, children.size
38
-
39
- # Don't care about order
40
- (0..4).each do |i|
41
- assert children.include?(lookup_layer(i))
42
- end
43
-
44
- # Don't care about order
45
- (5..9).each do |i|
46
- assert ! children.include?(lookup_layer(i))
47
- end
48
-
49
- limited_layer = children.last
50
- assert_equal ScoutApm::LimitedLayer, limited_layer.class
51
- assert_equal 5, limited_layer.count
52
- end
53
-
54
- def test_add_layer_with_different_type_after_limit
55
- s = SET.new(5)
56
-
57
- # Add 20 items
58
- 10.times do
59
- s << make_layer("LayerType", "LayerName")
60
- s << make_layer("DifferentLayerType", "LayerName")
61
- end
62
-
63
- children = s.to_a
64
-
65
- # Tyo types, so 2 distinct limitdlayer objects
66
- limited_layers = children.select{ |l| ScoutApm::LimitedLayer === l }
67
- assert_equal 2, limited_layers.length
68
-
69
- # 5 unchanged children each for the two layer types, plus the 2 limitd when each overran their limit
70
- assert_equal 12, children.length
71
- limited_layers.each { |ml| assert_equal 5, ml.count }
72
- end
73
-
74
- #############
75
- # Helpers #
76
- #############
77
-
78
- def make_layer(type, name)
79
- @made_layers ||= []
80
- l = ScoutApm::Layer.new(type, name)
81
- @made_layers << l
82
- l
83
- end
84
-
85
- def lookup_layer(i)
86
- @made_layers[i]
87
- end
88
- end
@@ -1,53 +0,0 @@
1
- require 'test_helper'
2
- require 'ostruct'
3
-
4
- class LimitedLayerTest < Minitest::Test
5
-
6
- def test_counts_while_absorbing
7
- ll = ScoutApm::LimitedLayer.new("ActiveRecord")
8
- assert_equal 0, ll.count
9
-
10
- ll.absorb faux_layer("ActiveRecord", "User#Find", 2, 1, 200, 100)
11
- assert_equal 1, ll.count
12
-
13
- ll.absorb faux_layer("ActiveRecord", "User#Find", 2, 1, 200, 100)
14
- assert_equal 2, ll.count
15
- end
16
-
17
- def test_sums_values_while_absorbing
18
- ll = ScoutApm::LimitedLayer.new("ActiveRecord")
19
-
20
- ll.absorb faux_layer("ActiveRecord", "User#Find", 2, 1, 200, 100)
21
- assert_equal 1, ll.total_exclusive_time
22
- assert_equal 2, ll.total_call_time
23
- assert_equal 100, ll.total_exclusive_allocations
24
- assert_equal 200, ll.total_allocations
25
-
26
-
27
- ll.absorb faux_layer("ActiveRecord", "User#Find", 4, 3, 400, 300)
28
- assert_equal 4, ll.total_exclusive_time # 3 + 1
29
- assert_equal 6, ll.total_call_time # 4 + 2
30
- assert_equal 400, ll.total_exclusive_allocations # 300 + 100
31
- assert_equal 600, ll.total_allocations # 400 + 200
32
- end
33
-
34
- def test_the_name
35
- ll = ScoutApm::LimitedLayer.new("ActiveRecord")
36
- assert_equal "ActiveRecord/Limited", ll.legacy_metric_name
37
- end
38
-
39
- #############
40
- # Helpers #
41
- #############
42
-
43
- def faux_layer(type, name, tct, tet, a_tct, a_tet)
44
- OpenStruct.new(
45
- :type => type,
46
- :name => name,
47
- :total_call_time => tct,
48
- :total_exclusive_time => tet,
49
- :total_allocations => a_tct,
50
- :total_exclusive_allocations => a_tet,
51
- )
52
- end
53
- end