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
@@ -2,7 +2,7 @@ module ScoutApm
2
2
  module Serializers
3
3
  module PayloadSerializerToJson
4
4
  class << self
5
- def serialize(metadata, metrics, slow_transactions, jobs, slow_jobs, histograms, db_query_metrics, traces)
5
+ def serialize(metadata, metrics, slow_transactions, jobs, slow_jobs)
6
6
  metadata.merge!({:payload_version => 2})
7
7
 
8
8
  jsonify_hash({:metadata => metadata,
@@ -10,12 +10,7 @@ module ScoutApm
10
10
  :slow_transactions => rearrange_the_slow_transactions(slow_transactions),
11
11
  :jobs => JobsSerializerToJson.new(jobs).as_json,
12
12
  :slow_jobs => SlowJobsSerializerToJson.new(slow_jobs).as_json,
13
- :histograms => HistogramsSerializerToJson.new(histograms).as_json,
14
- :db_metrics => {
15
- :query => DbQuerySerializerToJson.new(db_query_metrics).as_json,
16
- },
17
- :span_traces => traces.map{ |t| t.as_json },
18
- })
13
+ })
19
14
  end
20
15
 
21
16
  # For the old style of metric serializing.
@@ -45,36 +40,18 @@ module ScoutApm
45
40
  "{#{str_parts.join(",")}}"
46
41
  end
47
42
 
48
- # Ruby 1.8.7 seems to be fundamentally different in how gsub or regexes
49
- # work. This is a hack and will be removed as soon as we can drop
50
- # support
51
- if RUBY_VERSION == "1.8.7"
52
- ESCAPE_MAPPINGS = {
53
- "\b" => '\\b',
54
- "\t" => '\\t',
55
- "\n" => '\\n',
56
- "\f" => '\\f',
57
- "\r" => '\\r',
58
- '"' => '\\"',
59
- '\\' => '\\\\',
60
- }
61
- else
62
- ESCAPE_MAPPINGS = {
63
- # Stackoverflow answer on gsub matches and backslashes - https://stackoverflow.com/a/4149087/2705125
64
- '\\' => '\\\\\\\\',
65
- "\b" => '\\b',
66
- "\t" => '\\t',
67
- "\n" => '\\n',
68
- "\f" => '\\f',
69
- "\r" => '\\r',
70
- '"' => '\\"',
71
- }
72
- end
43
+ ESCAPE_MAPPINGS = {
44
+ "\b" => '\\b',
45
+ "\t" => '\\t',
46
+ "\n" => '\\n',
47
+ "\f" => '\\f',
48
+ "\r" => '\\r',
49
+ '"' => '\\"',
50
+ '\\' => '\\\\',
51
+ }
73
52
 
74
53
  def escape(string)
75
- ESCAPE_MAPPINGS.inject(string.to_s) {|s, (bad, good)|
76
- s.gsub(bad, good)
77
- }
54
+ ESCAPE_MAPPINGS.inject(string.to_s) {|s, (bad, good)| s.gsub(bad, good) }
78
55
  end
79
56
 
80
57
  def format_by_type(formatee)
@@ -90,6 +67,10 @@ module ScoutApm
90
67
  %Q["#{formatee.iso8601}"]
91
68
  when nil
92
69
  "null"
70
+ when TrueClass
71
+ "true"
72
+ when FalseClass
73
+ "false"
93
74
  else # strings and everything
94
75
  %Q["#{escape(formatee)}"]
95
76
  end
@@ -21,11 +21,9 @@ module ScoutApm
21
21
  "allocations" => job.allocations,
22
22
  "seconds_since_startup" => job.seconds_since_startup,
23
23
  "hostname" => job.hostname,
24
- "git_sha" => job.git_sha,
25
24
  "metrics" => MetricsToJsonSerializer.new(job.metrics).as_json, # New style of metrics
26
25
  "allocation_metrics" => MetricsToJsonSerializer.new(job.allocation_metrics).as_json, # New style of metrics
27
26
  "context" => job.context.to_hash,
28
- "truncated_metrics" => job.truncated_metrics,
29
27
 
30
28
  "score" => job.score,
31
29
  }
@@ -34,3 +32,4 @@ module ScoutApm
34
32
  end
35
33
  end
36
34
  end
35
+
@@ -29,7 +29,7 @@ module ScoutApm
29
29
  # This does run when a process stops.
30
30
  PhusionPassenger.on_event(:stopping_worker_process) do
31
31
  logger.debug "Passenger is stopping a worker process, shutting down the agent."
32
- ScoutApm::Agent.instance.stop_background_worker
32
+ ScoutApm::Agent.instance.shutdown
33
33
  end
34
34
  end
35
35
 
@@ -24,13 +24,10 @@ module ScoutApm
24
24
  end
25
25
 
26
26
  def install
27
- old = ::Puma.cli_config.options[:before_worker_boot] || []
28
- new = Array(old) + [Proc.new do
27
+ ::Puma.cli_config.options[:before_worker_boot] << Proc.new do
29
28
  logger.info "Installing Puma worker loop."
30
29
  ScoutApm::Agent.instance.start_background_worker
31
- end]
32
-
33
- ::Puma.cli_config.options[:before_worker_boot] = new
30
+ end
34
31
  rescue
35
32
  logger.warn "Unable to install Puma worker loop: #{$!.message}"
36
33
  end
@@ -17,10 +17,6 @@ module ScoutApm
17
17
  # Outliers are worth up to "1000ms" of weight
18
18
  POINT_MULTIPLIER_PERCENTILE = 1.0
19
19
 
20
- # Points for an endpoint's who's throughput * response time is a large % of
21
- # overall time spent processing requests
22
- POINT_MULTIPLIER_PERCENT_TIME = 2.5
23
-
24
20
  # A hash of Job Names to the last time we stored a slow trace for it.
25
21
  #
26
22
  # Defaults to a start time that is pretty close to application boot time.
@@ -28,18 +24,14 @@ module ScoutApm
28
24
  # has been running.
29
25
  attr_reader :last_seen
30
26
 
31
- # The AgentContext we're running in
32
- attr_reader :context
33
-
34
- def initialize(context)
35
- @context = context
36
27
 
28
+ def initialize
37
29
  zero_time = Time.now
38
30
  @last_seen = Hash.new { |h, k| h[k] = zero_time }
39
31
  end
40
32
 
41
33
  def stored!(request)
42
- last_seen[request.unique_name] = Time.now
34
+ last_seen[unique_name_for(request)] = Time.now
43
35
  end
44
36
 
45
37
  # Determine if this job trace should be fully analyzed by scoring it
@@ -62,15 +54,22 @@ module ScoutApm
62
54
  age = Time.now - last_seen[unique_name]
63
55
 
64
56
  # What approximate percentile was this request?
65
- percentile = context.request_histograms.approximate_quantile_of_value(unique_name, total_time)
66
-
67
- percent_of_total_time = context.transaction_time_consumed.percent_of_total(unique_name)
57
+ percentile = ScoutApm::Agent.instance.request_histograms.approximate_quantile_of_value(unique_name, total_time)
68
58
 
69
- return speed_points(total_time) + percentile_points(percentile) + age_points(age) + percent_time_points(percent_of_total_time)
59
+ return speed_points(total_time) + percentile_points(percentile) + age_points(age)
70
60
  end
71
61
 
72
62
  private
73
63
 
64
+ def unique_name_for(request)
65
+ scope_layer = LayerConverters::ConverterBase.new(request).scope_layer
66
+ if scope_layer
67
+ scope_layer.legacy_metric_name
68
+ else
69
+ :unknown
70
+ end
71
+ end
72
+
74
73
  # Time in seconds
75
74
  # Logarithm keeps huge times from swamping the other metrics.
76
75
  # 1+ is necessary to keep the log function in positive territory.
@@ -96,16 +95,5 @@ module ScoutApm
96
95
  def age_points(age)
97
96
  age / 60.0 * POINT_MULTIPLIER_AGE
98
97
  end
99
-
100
- # Of the total time spent handling endpoints in this app, if this endpoint
101
- # is a higher percent, it should get more points.
102
- #
103
- # A: 20 calls @ 100ms each => 2 seconds of total time
104
- # B: 10 calls @ 100ms each => 1 second of total time
105
- #
106
- # Then A is 66% of the total call time
107
- def percent_time_points(percent) # Scale 0.0 - 1.0
108
- percent * POINT_MULTIPLIER_PERCENT_TIME
109
- end
110
98
  end
111
99
  end
@@ -20,12 +20,8 @@ module ScoutApm
20
20
  attr_reader :hostname
21
21
  attr_reader :seconds_since_startup
22
22
  attr_reader :score
23
- attr_reader :git_sha
24
- attr_reader :truncated_metrics
25
23
 
26
- attr_reader :span_trace
27
-
28
- def initialize(agent_context, queue_name, job_name, time, total_time, exclusive_time, context, metrics, allocation_metrics, mem_delta, allocations, score, truncated_metrics, span_trace)
24
+ def initialize(queue_name, job_name, time, total_time, exclusive_time, context, metrics, allocation_metrics, mem_delta, allocations, score)
29
25
  @queue_name = queue_name
30
26
  @job_name = job_name
31
27
  @time = time
@@ -36,15 +32,10 @@ module ScoutApm
36
32
  @allocation_metrics = allocation_metrics
37
33
  @mem_delta = mem_delta
38
34
  @allocations = allocations
39
- @seconds_since_startup = (Time.now - agent_context.process_start_time)
40
- @hostname = agent_context.environment.hostname
41
- @git_sha = agent_context.environment.git_revision.sha
35
+ @seconds_since_startup = (Time.now - ScoutApm::Agent.instance.process_start_time)
36
+ @hostname = ScoutApm::Environment.instance.hostname
42
37
  @score = score
43
- @truncated_metrics = truncated_metrics
44
-
45
- @span_trace = span_trace
46
-
47
- agent_context.logger.debug { "Slow Job [#{metric_name}] - Call Time: #{total_call_time} Mem Delta: #{mem_delta}"}
38
+ ScoutApm::Agent.instance.logger.debug { "Slow Job [#{metric_name}] - Call Time: #{total_call_time} Mem Delta: #{mem_delta}"}
48
39
  end
49
40
 
50
41
  def metric_name
@@ -17,10 +17,6 @@ module ScoutApm
17
17
  # Outliers are worth up to "1000ms" of weight
18
18
  POINT_MULTIPLIER_PERCENTILE = 1.0
19
19
 
20
- # Points for an endpoint's who's throughput * response time is a large % of
21
- # overall time spent processing requests
22
- POINT_MULTIPLIER_PERCENT_TIME = 2.5
23
-
24
20
  # A hash of Endpoint Name to the last time we stored a slow transaction for it.
25
21
  #
26
22
  # Defaults to a start time that is pretty close to application boot time.
@@ -28,18 +24,14 @@ module ScoutApm
28
24
  # has been running.
29
25
  attr_reader :last_seen
30
26
 
31
- # The AgentContext we're running in
32
- attr_reader :context
33
-
34
- def initialize(context)
35
- @context = context
36
27
 
28
+ def initialize
37
29
  zero_time = Time.now
38
30
  @last_seen = Hash.new { |h, k| h[k] = zero_time }
39
31
  end
40
32
 
41
33
  def stored!(request)
42
- last_seen[request.unique_name] = Time.now
34
+ last_seen[unique_name_for(request)] = Time.now
43
35
  end
44
36
 
45
37
  # Determine if this request trace should be fully analyzed by scoring it
@@ -62,15 +54,22 @@ module ScoutApm
62
54
  age = Time.now - last_seen[unique_name]
63
55
 
64
56
  # What approximate percentile was this request?
65
- percentile = context.request_histograms.approximate_quantile_of_value(unique_name, total_time)
66
-
67
- percent_of_total_time = context.transaction_time_consumed.percent_of_total(unique_name)
57
+ percentile = ScoutApm::Agent.instance.request_histograms.approximate_quantile_of_value(unique_name, total_time)
68
58
 
69
- return speed_points(total_time) + percentile_points(percentile) + age_points(age) + percent_time_points(percent_of_total_time)
59
+ return speed_points(total_time) + percentile_points(percentile) + age_points(age)
70
60
  end
71
61
 
72
62
  private
73
63
 
64
+ def unique_name_for(request)
65
+ scope_layer = LayerConverters::ConverterBase.new(request).scope_layer
66
+ if scope_layer
67
+ scope_layer.legacy_metric_name
68
+ else
69
+ :unknown
70
+ end
71
+ end
72
+
74
73
  # Time in seconds
75
74
  # Logarithm keeps huge times from swamping the other metrics.
76
75
  # 1+ is necessary to keep the log function in positive territory.
@@ -96,16 +95,5 @@ module ScoutApm
96
95
  def age_points(age)
97
96
  age / 60.0 * POINT_MULTIPLIER_AGE
98
97
  end
99
-
100
- # Of the total time spent handling endpoints in this app, if this endpoint
101
- # is a higher percent, it should get more points.
102
- #
103
- # A: 20 calls @ 100ms each => 2 seconds of total time
104
- # B: 10 calls @ 100ms each => 1 second of total time
105
- #
106
- # Then A is 66% of the total call time
107
- def percent_time_points(percent) # Scale 0.0 - 1.0
108
- percent * POINT_MULTIPLIER_PERCENT_TIME
109
- end
110
98
  end
111
99
  end
@@ -13,14 +13,10 @@ module ScoutApm
13
13
  attr_reader :prof
14
14
  attr_reader :mem_delta
15
15
  attr_reader :allocations
16
- attr_reader :span_trace
17
16
  attr_accessor :hostname # hack - we need to reset these server side.
18
17
  attr_accessor :seconds_since_startup # hack - we need to reset these server side.
19
- attr_accessor :git_sha # hack - we need to reset these server side.
20
18
 
21
- attr_reader :truncated_metrics # True/False that says if we had to truncate the metrics of this trace
22
-
23
- def initialize(agent_context, uri, metric_name, total_call_time, metrics, allocation_metrics, context, time, raw_stackprof, mem_delta, allocations, score, truncated_metrics, span_trace)
19
+ def initialize(uri, metric_name, total_call_time, metrics, allocation_metrics, context, time, raw_stackprof, mem_delta, allocations, score)
24
20
  @uri = uri
25
21
  @metric_name = metric_name
26
22
  @total_call_time = total_call_time
@@ -31,14 +27,10 @@ module ScoutApm
31
27
  @prof = []
32
28
  @mem_delta = mem_delta
33
29
  @allocations = allocations
34
- @seconds_since_startup = (Time.now - agent_context.process_start_time)
35
- @hostname = agent_context.environment.hostname
30
+ @seconds_since_startup = (Time.now - ScoutApm::Agent.instance.process_start_time)
31
+ @hostname = ScoutApm::Environment.instance.hostname
36
32
  @score = score
37
- @git_sha = agent_context.environment.git_revision.sha
38
- @truncated_metrics = truncated_metrics
39
- @span_trace = span_trace
40
-
41
- agent_context.logger.debug { "Slow Request [#{uri}] - Call Time: #{total_call_time} Mem Delta: #{mem_delta} Score: #{score}"}
33
+ ScoutApm::Agent.instance.logger.debug { "Slow Request [#{uri}] - Call Time: #{total_call_time} Mem Delta: #{mem_delta} Score: #{score}"}
42
34
  end
43
35
 
44
36
  # Used to remove metrics when the payload will be too large.
@@ -52,19 +44,7 @@ module ScoutApm
52
44
  end
53
45
 
54
46
  def as_json
55
- json_attributes = [:key,
56
- :time,
57
- :total_call_time,
58
- :uri,
59
- [:context, :context_hash],
60
- :score,
61
- :prof,
62
- :mem_delta,
63
- :allocations,
64
- :seconds_since_startup,
65
- :hostname,
66
- :git_sha,
67
- :truncated_metrics]
47
+ json_attributes = [:key, :time, :total_call_time, :uri, [:context, :context_hash], :score, :prof, :mem_delta, :allocations, :seconds_since_startup, :hostname]
68
48
  ScoutApm::AttributeArranger.call(self, json_attributes)
69
49
  end
70
50
 
@@ -3,52 +3,30 @@
3
3
  # the layaway file for cross-process aggregation.
4
4
  module ScoutApm
5
5
  class Store
6
- def initialize(context)
7
- @context = context
8
- @mutex = Monitor.new
9
- @reporting_periods = Hash.new { |h,k|
10
- @mutex.synchronize { h[k] = StoreReportingPeriod.new(k, @context) }
11
- }
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
+ def initialize
13
+ @mutex = Mutex.new
14
+ @reporting_periods = Hash.new { |h,k| h[k] = StoreReportingPeriod.new(k) }
12
15
  @samplers = []
13
16
  end
14
17
 
15
18
  def current_timestamp
16
- StoreReportingPeriodTimestamp.new(Time.now)
19
+ StoreReportingPeriodTimestamp.new
17
20
  end
18
21
 
19
22
  def current_period
20
- @reporting_periods[current_timestamp]
21
- end
22
- private :current_period
23
-
24
- def find_period(timestamp = nil)
25
- if timestamp
26
- @reporting_periods[timestamp]
27
- else
28
- current_period
29
- end
23
+ reporting_periods[current_timestamp]
30
24
  end
31
- private :find_period
32
25
 
33
26
  # Save newly collected metrics
34
27
  def track!(metrics, options={})
35
28
  @mutex.synchronize {
36
- period = find_period(options[:timestamp])
37
- period.absorb_metrics!(metrics)
38
- }
39
- end
40
-
41
- def track_histograms!(histograms, options={})
42
- @mutex.synchronize {
43
- period = find_period(options[:timestamp])
44
- period.merge_histograms!(histograms)
45
- }
46
- end
47
-
48
- def track_db_query_metrics!(db_query_metric_set, options={})
49
- @mutex.synchronize {
50
- period = find_period(options[:timestamp])
51
- period.merge_db_query_metrics!(db_query_metric_set)
29
+ current_period.absorb_metrics!(metrics)
52
30
  }
53
31
  end
54
32
 
@@ -87,56 +65,41 @@ module ScoutApm
87
65
  # current-minute metrics. Useful when we are shutting down the agent
88
66
  # during a restart.
89
67
  def write_to_layaway(layaway, force=false)
90
- logger.debug("Writing to layaway#{" (Forced)" if force}")
68
+ ScoutApm::Agent.instance.logger.debug("Writing to layaway#{" (Forced)" if force}")
91
69
 
92
- to_report = @mutex.synchronize {
93
- @reporting_periods.select { |time, rp|
94
- force || (time.timestamp < current_timestamp.timestamp)
95
- }
70
+ @mutex.synchronize {
71
+ reporting_periods.select { |time, rp| force || time.timestamp < current_timestamp.timestamp}.
72
+ each { |time, rp| write_reporting_period(layaway, time, rp) }
96
73
  }
97
-
98
- to_report.each { |time, rp| write_reporting_period(layaway, time, rp) }
99
- end
100
-
101
- # For each tick (minute), be sure we have a reporting period, and that samplers are run for it.
102
- def tick!
103
- rp = current_period
104
- collect_samplers(rp)
105
74
  end
106
75
 
107
76
  def write_reporting_period(layaway, time, rp)
108
- layaway.write_reporting_period(rp)
77
+ collect_samplers(rp)
78
+ layaway.write_reporting_period(rp)
109
79
  rescue => e
110
- logger.warn("Failed writing data to layaway file: #{e.message} / #{e.backtrace}")
80
+ ScoutApm::Agent.instance.logger.warn("Failed writing data to layaway file: #{e.message} / #{e.backtrace}")
111
81
  ensure
112
- logger.debug("Before delete, reporting periods length: #{@reporting_periods.size}")
113
- deleted_items = @mutex.synchronize { @reporting_periods.delete(time) }
114
- logger.debug("After delete, reporting periods length: #{@reporting_periods.size}. Did delete #{deleted_items}")
82
+ reporting_periods.delete(time)
115
83
  end
116
- private :write_reporting_period
117
84
 
118
85
  ######################################
119
86
  # Sampler support
120
- def add_sampler(sampler_klass)
121
- @samplers << sampler_klass.new(@context)
87
+ def add_sampler(sampler)
88
+ @samplers << sampler
122
89
  end
123
90
 
124
91
  def collect_samplers(rp)
125
92
  @samplers.each do |sampler|
126
93
  begin
127
- sampler.metrics(rp.timestamp, self)
94
+ metrics = sampler.metrics(rp.timestamp)
95
+ rp.absorb_metrics!(metrics)
128
96
  rescue => e
129
- logger.info "Error reading #{sampler.human_name} for period: #{rp}"
130
- logger.debug "#{e.message}\n\t#{e.backtrace.join("\n\t")}"
97
+ ScoutApm::Agent.instance.logger.info "Error reading #{sampler.human_name} for period: #{rp}"
98
+ ScoutApm::Agent.instance.logger.debug e.message
99
+ ScoutApm::Agent.instance.logger.debug e.backtrace.join("\n")
131
100
  end
132
101
  end
133
102
  end
134
- private :collect_samplers
135
-
136
- def logger
137
- @context.logger
138
- end
139
- private :logger
140
103
  end
141
104
 
142
105
  # A timestamp, normalized to the beginning of a minute. Used as a hash key to
@@ -189,34 +152,26 @@ module ScoutApm
189
152
 
190
153
  # One period of Storage. Typically 1 minute
191
154
  class StoreReportingPeriod
155
+
192
156
  # A ScoredItemSet holding the "best" traces for the period
193
157
  attr_reader :request_traces
194
158
 
195
159
  # A ScoredItemSet holding the "best" traces for the period
196
160
  attr_reader :job_traces
197
161
 
198
- # An Array of HistogramsReport
199
- attr_reader :histograms
200
-
201
162
  # A StoreReportingPeriodTimestamp representing the time that this
202
163
  # collection of metrics is for
203
164
  attr_reader :timestamp
204
165
 
205
166
  attr_reader :metric_set
206
167
 
207
- attr_reader :db_query_metric_set
208
-
209
- def initialize(timestamp, context)
168
+ def initialize(timestamp)
210
169
  @timestamp = timestamp
211
170
 
212
- @request_traces = ScoredItemSet.new(context.config.value('max_traces'))
213
- @job_traces = ScoredItemSet.new(context.config.value('max_traces'))
214
-
215
- @histograms = []
171
+ @request_traces = ScoredItemSet.new
172
+ @job_traces = ScoredItemSet.new
216
173
 
217
174
  @metric_set = MetricSet.new
218
- @db_query_metric_set = DbQueryMetricSet.new(context)
219
-
220
175
  @jobs = Hash.new
221
176
  end
222
177
 
@@ -226,9 +181,7 @@ module ScoutApm
226
181
  merge_metrics!(other.metric_set).
227
182
  merge_slow_transactions!(other.slow_transactions_payload).
228
183
  merge_jobs!(other.jobs).
229
- merge_slow_jobs!(other.slow_jobs_payload).
230
- merge_histograms!(other.histograms).
231
- merge_db_query_metrics!(other.db_query_metric_set)
184
+ merge_slow_jobs!(other.slow_jobs_payload)
232
185
  self
233
186
  end
234
187
 
@@ -249,11 +202,6 @@ module ScoutApm
249
202
  self
250
203
  end
251
204
 
252
- def merge_db_query_metrics!(other_metric_set)
253
- db_query_metric_set.combine!(other_metric_set)
254
- self
255
- end
256
-
257
205
  def merge_slow_transactions!(new_transactions)
258
206
  Array(new_transactions).each do |one_transaction|
259
207
  request_traces << one_transaction
@@ -282,17 +230,6 @@ module ScoutApm
282
230
  self
283
231
  end
284
232
 
285
- def merge_histograms!(new_histograms)
286
- new_histograms = Array(new_histograms)
287
- @histograms = (histograms + new_histograms).
288
- group_by { |histo| histo.name }.
289
- map { |(_, histos)|
290
- histos.inject { |merged, histo| merged.combine!(histo) }
291
- }
292
-
293
- self
294
- end
295
-
296
233
  #################################
297
234
  # Retrieve Metrics for reporting
298
235
  #################################
@@ -312,10 +249,6 @@ module ScoutApm
312
249
  job_traces.to_a
313
250
  end
314
251
 
315
- def db_query_metrics_payload
316
- db_query_metric_set.metrics_to_report
317
- end
318
-
319
252
  #################################
320
253
  # Debug Helpers
321
254
  #################################