scout_apm 3.0.0.pre10 → 3.0.0.pre11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.markdown +47 -0
  4. data/Guardfile +42 -0
  5. data/lib/scout_apm.rb +14 -0
  6. data/lib/scout_apm/agent.rb +58 -1
  7. data/lib/scout_apm/agent/logging.rb +6 -1
  8. data/lib/scout_apm/app_server_load.rb +21 -11
  9. data/lib/scout_apm/background_job_integrations/resque.rb +85 -0
  10. data/lib/scout_apm/background_job_integrations/sidekiq.rb +19 -3
  11. data/lib/scout_apm/background_recorder.rb +43 -0
  12. data/lib/scout_apm/background_worker.rb +6 -6
  13. data/lib/scout_apm/config.rb +14 -3
  14. data/lib/scout_apm/environment.rb +14 -0
  15. data/lib/scout_apm/instruments/action_controller_rails_3_rails4.rb +112 -70
  16. data/lib/scout_apm/instruments/action_view.rb +49 -0
  17. data/lib/scout_apm/instruments/active_record.rb +2 -2
  18. data/lib/scout_apm/instruments/mongoid.rb +10 -2
  19. data/lib/scout_apm/instruments/resque.rb +40 -0
  20. data/lib/scout_apm/layer_children_set.rb +7 -2
  21. data/lib/scout_apm/rack.rb +26 -0
  22. data/lib/scout_apm/remote/message.rb +23 -0
  23. data/lib/scout_apm/remote/recorder.rb +57 -0
  24. data/lib/scout_apm/remote/router.rb +49 -0
  25. data/lib/scout_apm/remote/server.rb +58 -0
  26. data/lib/scout_apm/request_manager.rb +1 -1
  27. data/lib/scout_apm/synchronous_recorder.rb +26 -0
  28. data/lib/scout_apm/tracked_request.rb +53 -5
  29. data/lib/scout_apm/utils/backtrace_parser.rb +3 -3
  30. data/lib/scout_apm/utils/scm.rb +14 -0
  31. data/lib/scout_apm/version.rb +1 -1
  32. data/scout_apm.gemspec +2 -0
  33. data/test/unit/remote/test_message.rb +13 -0
  34. data/test/unit/remote/test_router.rb +33 -0
  35. data/test/unit/remote/test_server.rb +15 -0
  36. data/test/unit/test_tracked_request.rb +87 -0
  37. data/test/unit/utils/backtrace_parser_test.rb +5 -0
  38. data/test/unit/utils/scm.rb +17 -0
  39. metadata +52 -2
@@ -6,8 +6,8 @@ require 'scout_apm/environment'
6
6
  module ScoutApm
7
7
  module Utils
8
8
  class BacktraceParser
9
-
10
- APP_FRAMES = 3 # will return up to 3 frames from the app stack.
9
+ # will return this many backtrace frames from the app stack.
10
+ APP_FRAMES = 8
11
11
 
12
12
  attr_reader :call_stack
13
13
 
@@ -24,7 +24,7 @@ module ScoutApm
24
24
  stack = []
25
25
  call_stack.each do |c|
26
26
  if m = c.match(@@app_dir_regex)
27
- stack << m[1]
27
+ stack << ScoutApm::Utils::Scm.relative_scm_path(m[1])
28
28
  break if stack.size == APP_FRAMES
29
29
  end
30
30
  end
@@ -0,0 +1,14 @@
1
+ # Module for helping to deal with Source Code Management settings
2
+ module ScoutApm
3
+ module Utils
4
+ class Scm
5
+ # Takes an *already relative* path +path+
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)
8
+ @@scm_subdirectory ||= scm_subdirectory.sub(/^\//, '')
9
+ @@scm_subdirectoy_blank ||= @@scm_subdirectory.empty?
10
+ @@scm_subdirectoy_blank ? path : File.join(@@scm_subdirectory, path)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module ScoutApm
2
- VERSION = "3.0.0.pre10"
2
+ VERSION = "3.0.0.pre11"
3
3
  end
data/scout_apm.gemspec CHANGED
@@ -29,4 +29,6 @@ Gem::Specification.new do |s|
29
29
  s.add_development_dependency "simplecov"
30
30
  s.add_development_dependency "rake-compiler"
31
31
  s.add_development_dependency "addressable"
32
+ s.add_development_dependency "guard"
33
+ s.add_development_dependency "guard-minitest"
32
34
  end
@@ -0,0 +1,13 @@
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
+
@@ -0,0 +1,33 @@
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
+
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,87 @@
1
+ require 'test_helper'
2
+
3
+ class TrackedRequestDumpAndLoadTest < Minitest::Test
4
+ # TrackedRequest must be marshalable
5
+ def test_marshal_dump_load
6
+ tr = ScoutApm::TrackedRequest.new(ScoutApm::FakeStore.new)
7
+ tr.prepare_to_dump!
8
+
9
+ dumped = Marshal.dump(tr)
10
+ loaded = Marshal.load(dumped)
11
+ assert_false loaded.nil?
12
+ end
13
+
14
+ def test_restore_store
15
+ faux = ScoutApm::FakeStore.new
16
+ tr = ScoutApm::TrackedRequest.new(faux)
17
+ assert_equal faux, tr.instance_variable_get("@store")
18
+
19
+ tr.prepare_to_dump!
20
+ assert_nil tr.instance_variable_get("@store")
21
+
22
+ tr.restore_store
23
+ assert_equal ScoutApm::Agent.instance.store, tr.instance_variable_get("@store")
24
+ end
25
+ end
26
+
27
+ class TrackedRequestFlagsTest < Minitest::Test
28
+ def test_set_web
29
+ tr = ScoutApm::TrackedRequest.new(ScoutApm::FakeStore.new)
30
+ assert_false tr.web?
31
+ tr.web!
32
+ assert tr.web?
33
+ end
34
+
35
+ def test_set_job
36
+ tr = ScoutApm::TrackedRequest.new(ScoutApm::FakeStore.new)
37
+ assert ! tr.job?
38
+ tr.job!
39
+ assert tr.job?
40
+ end
41
+
42
+ def test_set_error
43
+ tr = ScoutApm::TrackedRequest.new(ScoutApm::FakeStore.new)
44
+ assert_false tr.error?
45
+ tr.error!
46
+ assert tr.error?
47
+ end
48
+
49
+ def test_set_error_and_web
50
+ tr = ScoutApm::TrackedRequest.new(ScoutApm::FakeStore.new)
51
+ assert_false tr.error?
52
+ assert_false tr.web?
53
+
54
+ tr.web!
55
+ assert_false tr.error?
56
+ assert tr.web?
57
+
58
+ tr.error!
59
+ assert tr.error?
60
+ assert tr.web?
61
+ end
62
+ end
63
+
64
+ class TrackedRequestLayerManipulationTest < Minitest::Test
65
+ def test_start_layer
66
+ tr = ScoutApm::TrackedRequest.new(ScoutApm::FakeStore.new)
67
+ tr.start_layer(ScoutApm::Layer.new("Foo", "Bar"))
68
+
69
+ assert_equal "Foo", tr.current_layer.type
70
+ end
71
+
72
+ def test_start_several_layers
73
+ # layers are Controller -> ActiveRecord
74
+ controller_layer = ScoutApm::Layer.new("Controller", "users/index")
75
+ ar_layer = ScoutApm::Layer.new("ActiveRecord", "Users#find")
76
+
77
+ tr = ScoutApm::TrackedRequest.new(ScoutApm::FakeStore.new)
78
+ tr.start_layer(controller_layer)
79
+ tr.start_layer(ar_layer)
80
+
81
+ assert_equal "ActiveRecord", tr.current_layer.type
82
+
83
+ tr.stop_layer
84
+
85
+ assert_equal "Controller", tr.current_layer.type
86
+ end
87
+ end
@@ -39,6 +39,11 @@ class BacktraceParserTest < Minitest::Test
39
39
  end
40
40
  end
41
41
 
42
+ def test_calls_scm_relative_path
43
+ ScoutApm::Utils::Scm.expects(:relative_scm_path).at_least_once
44
+ assert ScoutApm::Utils::BacktraceParser.new(raw_backtrace, root).call
45
+ end
46
+
42
47
  def test_works_on_shorter_backtraces
43
48
  result = ScoutApm::Utils::BacktraceParser.new(raw_backtrace(1), root).call
44
49
 
@@ -0,0 +1,17 @@
1
+ require_relative '../../test_helper'
2
+ require 'scout_apm/utils/scm'
3
+
4
+ class ScmTest < Minitest::Test
5
+
6
+ def test_relative_scm_path_blank
7
+ assert_equal 'app/models/person.rb', ScoutApm::Utils::Scm.relative_scm_path('app/models/person.rb', '')
8
+ end
9
+
10
+ def test_relative_scm_path_not_blank
11
+ assert_equal 'src/app/models/person.rb', ScoutApm::Utils::Scm.relative_scm_path('app/models/person.rb', 'src')
12
+ end
13
+
14
+ def test_relative_scm_path_not_blank_with_slashes
15
+ assert_equal 'src/app/models/person.rb', ScoutApm::Utils::Scm.relative_scm_path('app/models/person.rb', '/src/')
16
+ end
17
+ end
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: 3.0.0.pre10
4
+ version: 3.0.0.pre11
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-06-21 00:00:00.000000000 Z
12
+ date: 2017-09-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -109,6 +109,34 @@ dependencies:
109
109
  - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: guard
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: guard-minitest
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
112
140
  description: Monitors Ruby apps and reports detailed metrics on performance to Scout.
113
141
  email:
114
142
  - support@scoutapp.com
@@ -123,6 +151,7 @@ files:
123
151
  - ".rubocop.yml"
124
152
  - CHANGELOG.markdown
125
153
  - Gemfile
154
+ - Guardfile
126
155
  - LICENSE.md
127
156
  - README.markdown
128
157
  - Rakefile
@@ -142,7 +171,9 @@ files:
142
171
  - lib/scout_apm/app_server_load.rb
143
172
  - lib/scout_apm/attribute_arranger.rb
144
173
  - lib/scout_apm/background_job_integrations/delayed_job.rb
174
+ - lib/scout_apm/background_job_integrations/resque.rb
145
175
  - lib/scout_apm/background_job_integrations/sidekiq.rb
176
+ - lib/scout_apm/background_recorder.rb
146
177
  - lib/scout_apm/background_worker.rb
147
178
  - lib/scout_apm/bucket_name_splitter.rb
148
179
  - lib/scout_apm/call_set.rb
@@ -164,6 +195,7 @@ files:
164
195
  - lib/scout_apm/instruments/.DS_Store
165
196
  - lib/scout_apm/instruments/action_controller_rails_2.rb
166
197
  - lib/scout_apm/instruments/action_controller_rails_3_rails4.rb
198
+ - lib/scout_apm/instruments/action_view.rb
167
199
  - lib/scout_apm/instruments/active_record.rb
168
200
  - lib/scout_apm/instruments/elasticsearch.rb
169
201
  - lib/scout_apm/instruments/grape.rb
@@ -179,6 +211,7 @@ files:
179
211
  - lib/scout_apm/instruments/process/process_memory.rb
180
212
  - lib/scout_apm/instruments/rails_router.rb
181
213
  - lib/scout_apm/instruments/redis.rb
214
+ - lib/scout_apm/instruments/resque.rb
182
215
  - lib/scout_apm/instruments/sinatra.rb
183
216
  - lib/scout_apm/job_record.rb
184
217
  - lib/scout_apm/layaway.rb
@@ -202,6 +235,11 @@ files:
202
235
  - lib/scout_apm/platform_integrations/cloud_foundry.rb
203
236
  - lib/scout_apm/platform_integrations/heroku.rb
204
237
  - lib/scout_apm/platform_integrations/server.rb
238
+ - lib/scout_apm/rack.rb
239
+ - lib/scout_apm/remote/message.rb
240
+ - lib/scout_apm/remote/recorder.rb
241
+ - lib/scout_apm/remote/router.rb
242
+ - lib/scout_apm/remote/server.rb
205
243
  - lib/scout_apm/reporter.rb
206
244
  - lib/scout_apm/request_histograms.rb
207
245
  - lib/scout_apm/request_manager.rb
@@ -227,6 +265,7 @@ files:
227
265
  - lib/scout_apm/slow_transaction.rb
228
266
  - lib/scout_apm/stack_item.rb
229
267
  - lib/scout_apm/store.rb
268
+ - lib/scout_apm/synchronous_recorder.rb
230
269
  - lib/scout_apm/trace_compactor.rb
231
270
  - lib/scout_apm/tracer.rb
232
271
  - lib/scout_apm/tracked_request.rb
@@ -238,6 +277,7 @@ files:
238
277
  - lib/scout_apm/utils/klass_helper.rb
239
278
  - lib/scout_apm/utils/null_logger.rb
240
279
  - lib/scout_apm/utils/numbers.rb
280
+ - lib/scout_apm/utils/scm.rb
241
281
  - lib/scout_apm/utils/sql_sanitizer.rb
242
282
  - lib/scout_apm/utils/sql_sanitizer_regex.rb
243
283
  - lib/scout_apm/utils/sql_sanitizer_regex_1_8_7.rb
@@ -262,15 +302,20 @@ files:
262
302
  - test/unit/layer_children_set_test.rb
263
303
  - test/unit/limited_layer_test.rb
264
304
  - test/unit/metric_set_test.rb
305
+ - test/unit/remote/test_message.rb
306
+ - test/unit/remote/test_router.rb
307
+ - test/unit/remote/test_server.rb
265
308
  - test/unit/scored_item_set_test.rb
266
309
  - test/unit/serializers/payload_serializer_test.rb
267
310
  - test/unit/slow_job_policy_test.rb
268
311
  - test/unit/slow_request_policy_test.rb
269
312
  - test/unit/sql_sanitizer_test.rb
270
313
  - test/unit/store_test.rb
314
+ - test/unit/test_tracked_request.rb
271
315
  - test/unit/utils/active_record_metric_name_test.rb
272
316
  - test/unit/utils/backtrace_parser_test.rb
273
317
  - test/unit/utils/numbers_test.rb
318
+ - test/unit/utils/scm.rb
274
319
  - tester.rb
275
320
  homepage: https://github.com/scoutapp/scout_apm_ruby
276
321
  licenses:
@@ -315,12 +360,17 @@ test_files:
315
360
  - test/unit/layer_children_set_test.rb
316
361
  - test/unit/limited_layer_test.rb
317
362
  - test/unit/metric_set_test.rb
363
+ - test/unit/remote/test_message.rb
364
+ - test/unit/remote/test_router.rb
365
+ - test/unit/remote/test_server.rb
318
366
  - test/unit/scored_item_set_test.rb
319
367
  - test/unit/serializers/payload_serializer_test.rb
320
368
  - test/unit/slow_job_policy_test.rb
321
369
  - test/unit/slow_request_policy_test.rb
322
370
  - test/unit/sql_sanitizer_test.rb
323
371
  - test/unit/store_test.rb
372
+ - test/unit/test_tracked_request.rb
324
373
  - test/unit/utils/active_record_metric_name_test.rb
325
374
  - test/unit/utils/backtrace_parser_test.rb
326
375
  - test/unit/utils/numbers_test.rb
376
+ - test/unit/utils/scm.rb