scout_apm 2.6.10 → 3.0.0.pre0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -2
  3. data/.rubocop.yml +3 -11
  4. data/CHANGELOG.markdown +4 -362
  5. data/Gemfile +1 -14
  6. data/README.markdown +7 -52
  7. data/Rakefile +1 -0
  8. data/ext/allocations/allocations.c +1 -7
  9. data/ext/allocations/extconf.rb +0 -1
  10. data/ext/rusage/rusage.c +0 -26
  11. data/ext/stacks/extconf.rb +37 -0
  12. data/ext/stacks/scout_atomics.h +86 -0
  13. data/ext/stacks/stacks.c +811 -0
  14. data/lib/scout_apm/agent/logging.rb +69 -0
  15. data/lib/scout_apm/agent/reporting.rb +126 -0
  16. data/lib/scout_apm/agent.rb +259 -138
  17. data/lib/scout_apm/app_server_load.rb +15 -41
  18. data/lib/scout_apm/attribute_arranger.rb +3 -14
  19. data/lib/scout_apm/background_job_integrations/delayed_job.rb +1 -70
  20. data/lib/scout_apm/background_job_integrations/sidekiq.rb +24 -31
  21. data/lib/scout_apm/background_worker.rb +12 -23
  22. data/lib/scout_apm/capacity.rb +57 -0
  23. data/lib/scout_apm/config.rb +37 -206
  24. data/lib/scout_apm/context.rb +4 -20
  25. data/lib/scout_apm/deploy_integrations/capistrano_2.cap +12 -0
  26. data/lib/scout_apm/deploy_integrations/capistrano_2.rb +83 -0
  27. data/lib/scout_apm/deploy_integrations/capistrano_3.cap +12 -0
  28. data/lib/scout_apm/deploy_integrations/capistrano_3.rb +88 -0
  29. data/lib/scout_apm/environment.rb +28 -42
  30. data/lib/scout_apm/fake_store.rb +0 -12
  31. data/lib/scout_apm/framework_integrations/rails_2.rb +1 -2
  32. data/lib/scout_apm/framework_integrations/rails_3_or_4.rb +6 -17
  33. data/lib/scout_apm/framework_integrations/sinatra.rb +1 -1
  34. data/lib/scout_apm/histogram.rb +3 -12
  35. data/lib/scout_apm/instant/assets/xmlhttp_instrumentation.html +2 -2
  36. data/lib/scout_apm/instant/middleware.rb +54 -202
  37. data/lib/scout_apm/instant_reporting.rb +7 -7
  38. data/lib/scout_apm/instruments/.DS_Store +0 -0
  39. data/lib/scout_apm/instruments/action_controller_rails_2.rb +9 -15
  40. data/lib/scout_apm/instruments/action_controller_rails_3_rails4.rb +76 -124
  41. data/lib/scout_apm/instruments/active_record.rb +29 -324
  42. data/lib/scout_apm/instruments/delayed_job.rb +57 -0
  43. data/lib/scout_apm/instruments/elasticsearch.rb +6 -10
  44. data/lib/scout_apm/instruments/grape.rb +9 -12
  45. data/lib/scout_apm/instruments/http_client.rb +7 -14
  46. data/lib/scout_apm/instruments/influxdb.rb +6 -10
  47. data/lib/scout_apm/instruments/middleware_detailed.rb +11 -15
  48. data/lib/scout_apm/instruments/middleware_summary.rb +5 -11
  49. data/lib/scout_apm/instruments/mongoid.rb +8 -39
  50. data/lib/scout_apm/instruments/moped.rb +6 -11
  51. data/lib/scout_apm/instruments/net_http.rb +9 -27
  52. data/lib/scout_apm/instruments/percentile_sampler.rb +23 -42
  53. data/lib/scout_apm/instruments/process/process_cpu.rb +6 -11
  54. data/lib/scout_apm/instruments/process/process_memory.rb +12 -17
  55. data/lib/scout_apm/instruments/rails_router.rb +6 -12
  56. data/lib/scout_apm/instruments/redis.rb +6 -10
  57. data/lib/scout_apm/instruments/sinatra.rb +4 -5
  58. data/lib/scout_apm/job_record.rb +2 -4
  59. data/lib/scout_apm/layaway.rb +34 -88
  60. data/lib/scout_apm/layaway_file.rb +3 -13
  61. data/lib/scout_apm/layer.rb +60 -25
  62. data/lib/scout_apm/layer_converters/allocation_metric_converter.rb +6 -7
  63. data/lib/scout_apm/layer_converters/converter_base.rb +14 -203
  64. data/lib/scout_apm/layer_converters/depth_first_walker.rb +10 -22
  65. data/lib/scout_apm/layer_converters/error_converter.rb +8 -8
  66. data/lib/scout_apm/layer_converters/job_converter.rb +50 -37
  67. data/lib/scout_apm/layer_converters/metric_converter.rb +19 -18
  68. data/lib/scout_apm/layer_converters/request_queue_time_converter.rb +13 -13
  69. data/lib/scout_apm/layer_converters/slow_job_converter.rb +116 -52
  70. data/lib/scout_apm/layer_converters/slow_request_converter.rb +120 -51
  71. data/lib/scout_apm/metric_meta.rb +5 -0
  72. data/lib/scout_apm/metric_set.rb +1 -9
  73. data/lib/scout_apm/metric_stats.rb +8 -7
  74. data/lib/scout_apm/middleware.rb +9 -7
  75. data/lib/scout_apm/reporter.rb +24 -71
  76. data/lib/scout_apm/request_histograms.rb +0 -12
  77. data/lib/scout_apm/request_manager.rb +7 -5
  78. data/lib/scout_apm/scored_item_set.rb +0 -7
  79. data/lib/scout_apm/serializers/app_server_load_serializer.rb +0 -4
  80. data/lib/scout_apm/serializers/deploy_serializer.rb +16 -0
  81. data/lib/scout_apm/serializers/directive_serializer.rb +0 -4
  82. data/lib/scout_apm/serializers/payload_serializer.rb +4 -11
  83. data/lib/scout_apm/serializers/payload_serializer_to_json.rb +16 -35
  84. data/lib/scout_apm/serializers/slow_jobs_serializer_to_json.rb +1 -2
  85. data/lib/scout_apm/server_integrations/passenger.rb +1 -1
  86. data/lib/scout_apm/server_integrations/puma.rb +2 -5
  87. data/lib/scout_apm/slow_job_policy.rb +13 -25
  88. data/lib/scout_apm/slow_job_record.rb +4 -13
  89. data/lib/scout_apm/slow_request_policy.rb +13 -25
  90. data/lib/scout_apm/slow_transaction.rb +5 -25
  91. data/lib/scout_apm/store.rb +32 -99
  92. data/lib/scout_apm/trace_compactor.rb +312 -0
  93. data/lib/scout_apm/tracer.rb +31 -35
  94. data/lib/scout_apm/tracked_request.rb +95 -262
  95. data/lib/scout_apm/utils/active_record_metric_name.rb +13 -88
  96. data/lib/scout_apm/utils/backtrace_parser.rb +4 -7
  97. data/lib/scout_apm/utils/fake_stacks.rb +87 -0
  98. data/lib/scout_apm/utils/installed_gems.rb +3 -7
  99. data/lib/scout_apm/utils/klass_helper.rb +2 -8
  100. data/lib/scout_apm/utils/null_logger.rb +13 -0
  101. data/lib/scout_apm/utils/sql_sanitizer.rb +5 -16
  102. data/lib/scout_apm/utils/sql_sanitizer_regex.rb +0 -7
  103. data/lib/scout_apm/utils/sql_sanitizer_regex_1_8_7.rb +0 -6
  104. data/lib/scout_apm/utils/unique_id.rb +0 -27
  105. data/lib/scout_apm/version.rb +2 -1
  106. data/lib/scout_apm.rb +25 -84
  107. data/scout_apm.gemspec +3 -17
  108. data/test/test_helper.rb +3 -57
  109. data/test/unit/agent_test.rb +54 -1
  110. data/test/unit/background_job_integrations/sidekiq_test.rb +3 -0
  111. data/test/unit/config_test.rb +12 -25
  112. data/test/unit/context_test.rb +4 -4
  113. data/test/unit/histogram_test.rb +4 -25
  114. data/test/unit/ignored_uris_test.rb +1 -1
  115. data/test/unit/instruments/active_record_instruments_test.rb +5 -0
  116. data/test/unit/layaway_test.rb +2 -62
  117. data/test/unit/serializers/payload_serializer_test.rb +15 -43
  118. data/test/unit/slow_request_policy_test.rb +6 -15
  119. data/test/unit/sql_sanitizer_test.rb +6 -53
  120. data/test/unit/store_test.rb +4 -73
  121. data/test/unit/utils/active_record_metric_name_test.rb +5 -59
  122. data/test/unit/utils/backtrace_parser_test.rb +1 -6
  123. data/tester.rb +53 -0
  124. metadata +28 -229
  125. data/.travis.yml +0 -26
  126. data/Guardfile +0 -43
  127. data/gems/README.md +0 -28
  128. data/gems/octoshark.gemfile +0 -4
  129. data/gems/rails3.gemfile +0 -5
  130. data/gems/rails4.gemfile +0 -4
  131. data/gems/rails5.gemfile +0 -4
  132. data/gems/rails6.gemfile +0 -4
  133. data/lib/scout_apm/agent/exit_handler.rb +0 -65
  134. data/lib/scout_apm/agent/preconditions.rb +0 -81
  135. data/lib/scout_apm/agent_context.rb +0 -261
  136. data/lib/scout_apm/auto_instrument/instruction_sequence.rb +0 -31
  137. data/lib/scout_apm/auto_instrument/layer.rb +0 -23
  138. data/lib/scout_apm/auto_instrument/parser.rb +0 -27
  139. data/lib/scout_apm/auto_instrument/rails.rb +0 -175
  140. data/lib/scout_apm/auto_instrument.rb +0 -5
  141. data/lib/scout_apm/background_job_integrations/legacy_sneakers.rb +0 -55
  142. data/lib/scout_apm/background_job_integrations/que.rb +0 -134
  143. data/lib/scout_apm/background_job_integrations/resque.rb +0 -88
  144. data/lib/scout_apm/background_job_integrations/shoryuken.rb +0 -124
  145. data/lib/scout_apm/background_job_integrations/sneakers.rb +0 -87
  146. data/lib/scout_apm/background_recorder.rb +0 -48
  147. data/lib/scout_apm/db_query_metric_set.rb +0 -97
  148. data/lib/scout_apm/db_query_metric_stats.rb +0 -102
  149. data/lib/scout_apm/debug.rb +0 -37
  150. data/lib/scout_apm/detailed_trace.rb +0 -217
  151. data/lib/scout_apm/error.rb +0 -27
  152. data/lib/scout_apm/error_service/error_buffer.rb +0 -39
  153. data/lib/scout_apm/error_service/error_record.rb +0 -211
  154. data/lib/scout_apm/error_service/ignored_exceptions.rb +0 -66
  155. data/lib/scout_apm/error_service/middleware.rb +0 -32
  156. data/lib/scout_apm/error_service/notifier.rb +0 -33
  157. data/lib/scout_apm/error_service/payload.rb +0 -47
  158. data/lib/scout_apm/error_service/periodic_work.rb +0 -17
  159. data/lib/scout_apm/error_service/railtie.rb +0 -11
  160. data/lib/scout_apm/error_service/sidekiq.rb +0 -80
  161. data/lib/scout_apm/error_service.rb +0 -32
  162. data/lib/scout_apm/extensions/config.rb +0 -87
  163. data/lib/scout_apm/extensions/transaction_callback_payload.rb +0 -74
  164. data/lib/scout_apm/git_revision.rb +0 -59
  165. data/lib/scout_apm/instrument_manager.rb +0 -88
  166. data/lib/scout_apm/instruments/action_view.rb +0 -141
  167. data/lib/scout_apm/instruments/http.rb +0 -48
  168. data/lib/scout_apm/instruments/memcached.rb +0 -43
  169. data/lib/scout_apm/instruments/resque.rb +0 -39
  170. data/lib/scout_apm/instruments/samplers.rb +0 -11
  171. data/lib/scout_apm/layer_children_set.rb +0 -86
  172. data/lib/scout_apm/layer_converters/database_converter.rb +0 -70
  173. data/lib/scout_apm/layer_converters/find_layer_by_type.rb +0 -38
  174. data/lib/scout_apm/layer_converters/histograms.rb +0 -15
  175. data/lib/scout_apm/layer_converters/trace_converter.rb +0 -184
  176. data/lib/scout_apm/limited_layer.rb +0 -126
  177. data/lib/scout_apm/logger.rb +0 -158
  178. data/lib/scout_apm/periodic_work.rb +0 -47
  179. data/lib/scout_apm/rack.rb +0 -26
  180. data/lib/scout_apm/remote/message.rb +0 -27
  181. data/lib/scout_apm/remote/recorder.rb +0 -57
  182. data/lib/scout_apm/remote/router.rb +0 -49
  183. data/lib/scout_apm/remote/server.rb +0 -60
  184. data/lib/scout_apm/reporting.rb +0 -143
  185. data/lib/scout_apm/serializers/db_query_serializer_to_json.rb +0 -15
  186. data/lib/scout_apm/serializers/histograms_serializer_to_json.rb +0 -21
  187. data/lib/scout_apm/synchronous_recorder.rb +0 -30
  188. data/lib/scout_apm/tasks/doctor.rb +0 -75
  189. data/lib/scout_apm/tasks/support.rb +0 -22
  190. data/lib/scout_apm/transaction.rb +0 -13
  191. data/lib/scout_apm/transaction_time_consumed.rb +0 -51
  192. data/lib/scout_apm/utils/gzip_helper.rb +0 -24
  193. data/lib/scout_apm/utils/marshal_logging.rb +0 -90
  194. data/lib/scout_apm/utils/numbers.rb +0 -14
  195. data/lib/scout_apm/utils/scm.rb +0 -14
  196. data/lib/tasks/doctor.rake +0 -11
  197. data/test/tmp/README.md +0 -17
  198. data/test/unit/agent_context_test.rb +0 -15
  199. data/test/unit/auto_instrument/assignments-instrumented.rb +0 -31
  200. data/test/unit/auto_instrument/assignments.rb +0 -31
  201. data/test/unit/auto_instrument/controller-ast.txt +0 -57
  202. data/test/unit/auto_instrument/controller-instrumented.rb +0 -49
  203. data/test/unit/auto_instrument/controller.rb +0 -49
  204. data/test/unit/auto_instrument/rescue_from-instrumented.rb +0 -13
  205. data/test/unit/auto_instrument/rescue_from.rb +0 -13
  206. data/test/unit/auto_instrument_test.rb +0 -54
  207. data/test/unit/db_query_metric_set_test.rb +0 -67
  208. data/test/unit/db_query_metric_stats_test.rb +0 -113
  209. data/test/unit/error_service/error_buffer_test.rb +0 -25
  210. data/test/unit/error_service/ignored_exceptions_test.rb +0 -49
  211. data/test/unit/extensions/periodic_callbacks_test.rb +0 -58
  212. data/test/unit/extensions/transaction_callbacks_test.rb +0 -58
  213. data/test/unit/fake_store_test.rb +0 -10
  214. data/test/unit/git_revision_test.rb +0 -15
  215. data/test/unit/instruments/active_record_test.rb +0 -40
  216. data/test/unit/instruments/net_http_test.rb +0 -27
  217. data/test/unit/instruments/percentile_sampler_test.rb +0 -133
  218. data/test/unit/layer_children_set_test.rb +0 -97
  219. data/test/unit/layer_converters/depth_first_walker_test.rb +0 -70
  220. data/test/unit/layer_converters/metric_converter_test.rb +0 -22
  221. data/test/unit/layer_converters/stubs.rb +0 -33
  222. data/test/unit/limited_layer_test.rb +0 -53
  223. data/test/unit/logger_test.rb +0 -69
  224. data/test/unit/remote/test_message.rb +0 -13
  225. data/test/unit/remote/test_router.rb +0 -33
  226. data/test/unit/remote/test_server.rb +0 -15
  227. data/test/unit/request_histograms_test.rb +0 -17
  228. data/test/unit/tracer_test.rb +0 -76
  229. data/test/unit/tracked_request_test.rb +0 -71
  230. data/test/unit/transaction_test.rb +0 -14
  231. data/test/unit/transaction_time_consumed_test.rb +0 -46
  232. data/test/unit/utils/numbers_test.rb +0 -15
  233. data/test/unit/utils/scm.rb +0 -17
@@ -1,40 +0,0 @@
1
- require 'test_helper'
2
- require 'sqlite3'
3
- require 'active_record'
4
-
5
- begin
6
- require 'octoshark'
7
- rescue LoadError
8
- # Ignore
9
- end
10
-
11
- class ActiveRecordTest < Minitest::Test
12
- def database_path
13
- File.expand_path('test.sqlite3', DATA_FILE_DIR)
14
- end
15
-
16
- def setup
17
- database = SQLite3::Database.new(database_path)
18
- database.execute("DROP TABLE IF EXISTS users;")
19
- database.execute("CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(100));")
20
-
21
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => database_path)
22
- end
23
-
24
- class User < ActiveRecord::Base
25
- end
26
-
27
- def test_instrumentation
28
- recorder = FakeRecorder.new
29
- agent_context.recorder = recorder
30
-
31
- instrument = ScoutApm::Instruments::ActiveRecord.new(agent_context)
32
- instrument.install
33
-
34
- ScoutApm::Tracer.instrument("Controller", "foo/bar") do
35
- user = User.create
36
- end
37
-
38
- assert 1, recorder.requests.size
39
- end
40
- end
@@ -1,27 +0,0 @@
1
- require 'test_helper'
2
-
3
- require 'scout_apm/instruments/net_http'
4
-
5
- require 'addressable/uri'
6
-
7
- class NetHttpTest < Minitest::Test
8
- def setup
9
- @context = ScoutApm::AgentContext.new
10
- ScoutApm::Instruments::NetHttp.new(@context).install
11
- end
12
-
13
- def test_request_scout_description_for_uri
14
- if RUBY_VERSION <= '1.9.3'
15
- req = Net::HTTP::Get.new('/here')
16
- else
17
- req = Net::HTTP::Get.new(URI('http://example.org/here'))
18
- end
19
-
20
- assert_equal '/here', Net::HTTP.new('').request_scout_description(req)
21
- end
22
-
23
- def test_request_scout_description_for_addressable
24
- req = Net::HTTP::Get.new(Addressable::URI.parse('http://example.org/here'))
25
- assert_equal '/here', Net::HTTP.new('').request_scout_description(req)
26
- end
27
- end
@@ -1,133 +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
- @context = ScoutApm::AgentContext.new
13
- @subject = PercentileSampler.new(@context)
14
- end
15
-
16
- def test_initialize_with_logger_and_histogram_set
17
- assert_equal subject.logger, @context.logger
18
- assert_equal subject.histograms, @context.request_histograms_by_time
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
- @context.request_histograms_by_time
117
- end
118
-
119
- def histogram
120
- max_bins = 20
121
- ScoutApm::NumericHistogram.new(max_bins)
122
- end
123
-
124
- # An arbitrary time
125
- def time
126
- @time ||= Time.now
127
- end
128
-
129
- def time2
130
- time + 10
131
- end
132
- end
133
-
@@ -1,97 +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
- def test_works_with_marshal
75
- s = SET.new(5)
76
- 10.times do
77
- s << make_layer("LayerType", "LayerName")
78
- end
79
-
80
- Marshal.dump(s)
81
- end
82
-
83
- #############
84
- # Helpers #
85
- #############
86
-
87
- def make_layer(type, name)
88
- @made_layers ||= []
89
- l = ScoutApm::Layer.new(type, name)
90
- @made_layers << l
91
- l
92
- end
93
-
94
- def lookup_layer(i)
95
- @made_layers[i]
96
- end
97
- end
@@ -1,70 +0,0 @@
1
- require 'test_helper'
2
-
3
- module ScoutApm
4
- class DepthFirstWalkerTest < Minitest::Test
5
- def test_walk_single_node_calls_callbacks_in_order
6
- calls = []
7
- layer = Layer.new("A", "x")
8
-
9
- walker = LayerConverters::DepthFirstWalker.new(layer)
10
- walker.before { |l| calls << :before }
11
- walker.after { |l| calls << :after }
12
- walker.on { |l| calls << :on }
13
-
14
- walker.walk
15
-
16
- assert_equal [:before, :on, :after], calls
17
- end
18
-
19
- # Tree looks like:
20
- # A
21
- # |
22
- # B
23
- # / \ \
24
- # C D E
25
- # / \
26
- # F G
27
- def test_walk_interesting_tree
28
- # The test could be rewritten to support 1.8.7, but it would likely be much
29
- # harder to read.
30
- skip "Lack of set ordering in Ruby 1.8.7 prevents this test from running correctly" if RUBY_VERSION.start_with?("1.8.")
31
-
32
- calls = []
33
- a = Layer.new("A", "x")
34
- b = Layer.new("B", "x")
35
- c = Layer.new("C", "x")
36
- d = Layer.new("D", "x")
37
- e = Layer.new("E", "x")
38
- f = Layer.new("F", "x")
39
- g = Layer.new("G", "x")
40
- a.add_child(b)
41
- b.add_child(c)
42
- b.add_child(d)
43
- b.add_child(e)
44
- c.add_child(f)
45
- c.add_child(g)
46
-
47
- root_layer = a
48
-
49
- walker = LayerConverters::DepthFirstWalker.new(root_layer)
50
- walker.before { |l| calls << "#{l.type} before" }
51
- walker.after { |l| calls << "#{l.type} after" }
52
- walker.on { |l| calls << "#{l.type} on" }
53
-
54
- walker.walk
55
-
56
- assert_equal [
57
- "A before", "A on", # before & on always line up next to each other
58
- "B before", "B on",
59
- "C before", "C on",
60
- "F before", "F on", "F after", # leaf nodes run all 3
61
- "G before", "G on", "G after",
62
- "C after", # once all children are done, do a node's after
63
- "D before", "D on", "D after",
64
- "E before", "E on", "E after",
65
- "B after",
66
- "A after"
67
- ], calls
68
- end
69
- end
70
- end
@@ -1,22 +0,0 @@
1
- require 'test_helper'
2
- require File.join(File.dirname(__FILE__), 'stubs')
3
-
4
- module ScoutApm
5
- module LayerConverters
6
- class MetricConverterTest < Minitest::Test
7
- include Stubs
8
-
9
- def test_register_adds_hooks
10
- mc = MetricConverter.new(agent_context, faux_request, faux_layer_finder, faux_store)
11
- faux_walker.expects(:on)
12
- mc.register_hooks(faux_walker)
13
- end
14
-
15
- def test_record
16
- mc = MetricConverter.new(agent_context, faux_request, faux_layer_finder, faux_store)
17
- faux_store.expects(:track!)
18
- mc.record!
19
- end
20
- end
21
- end
22
- end
@@ -1,33 +0,0 @@
1
- ####################################
2
- # Stubs for LayerConverter Tests #
3
- ####################################
4
- module ScoutApm
5
- module LayerConverters
6
- module Stubs
7
- def faux_walker(subscope_stubs = true)
8
- @w ||= stub
9
-
10
- if subscope_stubs && !@w_set_subscope_stubs
11
- @w_set_subscope_stubs = true
12
- @w.expects(:before)
13
- @w.expects(:after)
14
- end
15
- @w
16
- end
17
-
18
- def faux_request
19
- @req ||= stub(:root_layer => stub)
20
- end
21
-
22
- def faux_layer_finder
23
- @layer_finder ||= stub
24
- @layer_finder.stubs(:scope => stub)
25
- @layer_finder
26
- end
27
-
28
- def faux_store
29
- @store ||= stub
30
- end
31
- end
32
- end
33
- 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
@@ -1,69 +0,0 @@
1
- require 'test_helper'
2
- require 'fileutils'
3
-
4
- require 'scout_apm/logger'
5
-
6
- class LoggerTest < Minitest::Test
7
- def setup
8
- @env_root = Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), "..", "..")))
9
- FileUtils.mkdir_p(@env_root + "log")
10
- end
11
-
12
- def test_detect_stdout
13
- logger = ScoutApm::Logger.new("", { :log_file_path => "STDOUT"})
14
- assert logger.stdout?
15
- assert_equal STDOUT, logger.log_destination
16
-
17
- # and lowercase
18
- logger = ScoutApm::Logger.new("", { :log_file_path => "stdout"})
19
- assert logger.stdout?
20
- assert_equal STDOUT, logger.log_destination
21
- end
22
-
23
- def test_force_stdout
24
- logger = ScoutApm::Logger.new("", { :stdout => true })
25
- assert logger.stdout?
26
- assert_equal STDOUT, logger.log_destination
27
- end
28
-
29
- def test_pick_log_file_with_no_options
30
- logger = ScoutApm::Logger.new(@env_root, { })
31
- assert_equal (@env_root + "log" + "scout_apm.log").to_s, logger.log_destination
32
- end
33
-
34
- def test_pick_log_file_with_different_dir
35
- logger = ScoutApm::Logger.new(@env_root, { :log_file_path => "/tmp" })
36
- assert_equal "/tmp/scout_apm.log", logger.log_destination
37
- end
38
-
39
- def test_pick_log_file_invalid_dir
40
- logger = ScoutApm::Logger.new(@env_root, { :log_file_path => "/not_a_real_dir" })
41
- assert_equal STDOUT, logger.log_destination
42
- end
43
-
44
- def test_pick_log_dir_not_writable
45
- Dir.mktmpdir { |dir|
46
- # An unwritable dir
47
- FileUtils.chmod(0000, dir)
48
- logger = ScoutApm::Logger.new(@env_root, { :log_file_path => dir })
49
- assert_equal STDOUT, logger.log_destination
50
-
51
- # so it can be deleted
52
- FileUtils.chmod(0700, dir)
53
- }
54
- end
55
-
56
- def test_set_log_level
57
- logger = ScoutApm::Logger.new(@env_root, { :log_level => "debug" })
58
- assert_equal ::Logger::DEBUG, logger.log_level
59
- end
60
-
61
- def test_set_log_level_after
62
- logger = ScoutApm::Logger.new(@env_root, { :log_level => "debug" })
63
- logger.log_level = "info"
64
- assert_equal ::Logger::INFO, logger.log_level
65
-
66
- logger.log_level = ::Logger::ERROR
67
- assert_equal ::Logger::ERROR, logger.log_level
68
- end
69
- end
@@ -1,13 +0,0 @@
1
- require 'test_helper'
2
-
3
- class MessageTest < Minitest::Test
4
- def test_message_encode_decode_roundtrip
5
- message = ScoutApm::Remote::Message.new('type', 'command', ['arg'])
6
- encoded = message.encode
7
- decoded = ScoutApm::Remote::Message.decode(encoded)
8
- assert_equal message.type, decoded.type
9
- assert_equal message.command, decoded.command
10
- assert_equal message.args, decoded.args
11
- end
12
- end
13
-
@@ -1,33 +0,0 @@
1
- require 'test_helper'
2
-
3
- class RouterTest < Minitest::Test
4
- def test_router_handles_record
5
- recorder = stub
6
- router = ScoutApm::Remote::Router.new(recorder, logger)
7
- message = ScoutApm::Remote::Message.new("record", "foo", 1, 2).encode
8
-
9
- recorder.expects(:foo).with(1, 2)
10
-
11
- router.handle(message)
12
- end
13
-
14
- def test_router_raises_on_unknown_types
15
- recorder = stub
16
- router = ScoutApm::Remote::Router.new(recorder, logger)
17
- message = ScoutApm::Remote::Message.new("something_else", "foo", 1, 2).encode
18
-
19
- recorder.expects(:foo).never
20
- assert_raises do
21
- router.handle(message)
22
- end
23
- end
24
-
25
- def logger
26
- @logger ||= Logger.new(logger_io)
27
- end
28
-
29
- def logger_io
30
- @logger_io ||= StringIO.new
31
- end
32
- end
33
-
@@ -1,15 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TestRemoteServer < Minitest::Test
4
- def test_start_and_bind
5
- bind = "127.0.0.1"
6
- port = 8938
7
- router = stub(:router)
8
- logger_io = StringIO.new
9
- server = ScoutApm::Remote::Server.new(bind, port, router, Logger.new(logger_io))
10
-
11
- server.start
12
- sleep 0.01 # Let the server finish starting. The assert should instead allow a time
13
- assert server.running?
14
- end
15
- end
@@ -1,17 +0,0 @@
1
- require 'test_helper'
2
-
3
- require 'scout_apm/request_histograms'
4
-
5
- class RequestHistogramsTest < Minitest::Test
6
- def test_as_json_without_activesupport
7
- rh = ScoutApm::RequestHistograms.new
8
-
9
- rh.add("foo", 1)
10
- rh.add("foo", 2)
11
- rh.add("bar", 3)
12
-
13
- j = rh.as_json
14
- assert_equal 2, j.size
15
- assert_equal ["bar", "foo"], j.keys.sort
16
- end
17
- end