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.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/CHANGELOG.markdown +2 -161
- data/Rakefile +2 -2
- data/ext/allocations/allocations.c +0 -6
- data/ext/allocations/extconf.rb +0 -1
- data/ext/stacks/extconf.rb +33 -0
- data/ext/stacks/scout_atomics.h +86 -0
- data/ext/stacks/stacks.c +744 -0
- data/lib/scout_apm.rb +16 -24
- data/lib/scout_apm/agent.rb +38 -93
- data/lib/scout_apm/agent/logging.rb +1 -6
- data/lib/scout_apm/agent/reporting.rb +6 -8
- data/lib/scout_apm/app_server_load.rb +10 -21
- data/lib/scout_apm/attribute_arranger.rb +2 -0
- data/lib/scout_apm/background_job_integrations/delayed_job.rb +1 -71
- data/lib/scout_apm/background_job_integrations/sidekiq.rb +27 -66
- data/lib/scout_apm/background_worker.rb +15 -19
- data/lib/scout_apm/capacity.rb +57 -0
- data/lib/scout_apm/config.rb +29 -135
- data/lib/scout_apm/context.rb +5 -9
- data/lib/scout_apm/deploy_integrations/capistrano_2.cap +12 -0
- data/lib/scout_apm/deploy_integrations/capistrano_2.rb +83 -0
- data/lib/scout_apm/deploy_integrations/capistrano_3.cap +12 -0
- data/lib/scout_apm/deploy_integrations/capistrano_3.rb +88 -0
- data/lib/scout_apm/environment.rb +15 -22
- data/lib/scout_apm/histogram.rb +2 -11
- data/lib/scout_apm/instant/assets/xmlhttp_instrumentation.html +2 -2
- data/lib/scout_apm/instant/middleware.rb +57 -198
- data/lib/scout_apm/instruments/action_controller_rails_2.rb +2 -1
- data/lib/scout_apm/instruments/action_controller_rails_3_rails4.rb +59 -90
- data/lib/scout_apm/instruments/active_record.rb +5 -7
- data/lib/scout_apm/instruments/delayed_job.rb +57 -0
- data/lib/scout_apm/instruments/grape.rb +3 -4
- data/lib/scout_apm/instruments/middleware_detailed.rb +6 -4
- data/lib/scout_apm/instruments/middleware_summary.rb +1 -39
- data/lib/scout_apm/instruments/mongoid.rb +3 -24
- data/lib/scout_apm/instruments/net_http.rb +2 -7
- data/lib/scout_apm/instruments/percentile_sampler.rb +19 -36
- data/lib/scout_apm/instruments/process/process_cpu.rb +2 -3
- data/lib/scout_apm/instruments/process/process_memory.rb +3 -3
- data/lib/scout_apm/layaway.rb +33 -76
- data/lib/scout_apm/layer.rb +59 -16
- data/lib/scout_apm/layer_converters/converter_base.rb +0 -199
- data/lib/scout_apm/layer_converters/job_converter.rb +1 -1
- data/lib/scout_apm/layer_converters/metric_converter.rb +1 -1
- data/lib/scout_apm/layer_converters/slow_job_converter.rb +90 -15
- data/lib/scout_apm/layer_converters/slow_request_converter.rb +101 -13
- data/lib/scout_apm/metric_set.rb +1 -9
- data/lib/scout_apm/metric_stats.rb +8 -8
- data/lib/scout_apm/reporter.rb +15 -51
- data/lib/scout_apm/request_histograms.rb +0 -4
- data/lib/scout_apm/request_manager.rb +1 -2
- data/lib/scout_apm/scored_item_set.rb +0 -7
- data/lib/scout_apm/serializers/deploy_serializer.rb +16 -0
- data/lib/scout_apm/serializers/payload_serializer.rb +3 -9
- data/lib/scout_apm/serializers/payload_serializer_to_json.rb +5 -2
- data/lib/scout_apm/serializers/slow_jobs_serializer_to_json.rb +1 -2
- data/lib/scout_apm/server_integrations/puma.rb +2 -5
- data/lib/scout_apm/slow_item_set.rb +80 -0
- data/lib/scout_apm/slow_job_record.rb +1 -6
- data/lib/scout_apm/slow_transaction.rb +2 -20
- data/lib/scout_apm/store.rb +12 -50
- data/lib/scout_apm/trace_compactor.rb +311 -0
- data/lib/scout_apm/tracked_request.rb +37 -128
- data/lib/scout_apm/utils/backtrace_parser.rb +5 -7
- data/lib/scout_apm/utils/fake_stacks.rb +83 -0
- data/lib/scout_apm/version.rb +1 -1
- data/scout_apm.gemspec +4 -6
- data/test/test_helper.rb +0 -56
- data/test/unit/config_test.rb +9 -60
- data/test/unit/histogram_test.rb +0 -14
- data/test/unit/layaway_test.rb +16 -31
- data/test/unit/serializers/payload_serializer_test.rb +105 -3
- data/test/unit/slow_item_set_test.rb +94 -0
- data/test/unit/slow_job_policy_test.rb +49 -0
- data/test/unit/slow_request_policy_test.rb +5 -4
- data/test/unit/utils/backtrace_parser_test.rb +0 -19
- data/tester.rb +53 -0
- metadata +29 -124
- data/.rubocop.yml +0 -8
- data/Guardfile +0 -42
- data/ext/rusage/README.md +0 -26
- data/ext/rusage/extconf.rb +0 -5
- data/ext/rusage/rusage.c +0 -52
- data/lib/scout_apm/background_job_integrations/resque.rb +0 -85
- data/lib/scout_apm/background_recorder.rb +0 -43
- data/lib/scout_apm/debug.rb +0 -37
- data/lib/scout_apm/git_revision.rb +0 -51
- data/lib/scout_apm/instruments/action_view.rb +0 -49
- data/lib/scout_apm/instruments/resque.rb +0 -40
- data/lib/scout_apm/layer_children_set.rb +0 -77
- data/lib/scout_apm/limited_layer.rb +0 -122
- data/lib/scout_apm/rack.rb +0 -26
- data/lib/scout_apm/remote/message.rb +0 -23
- data/lib/scout_apm/remote/recorder.rb +0 -57
- data/lib/scout_apm/remote/router.rb +0 -49
- data/lib/scout_apm/remote/server.rb +0 -58
- data/lib/scout_apm/serializers/histograms_serializer_to_json.rb +0 -21
- data/lib/scout_apm/synchronous_recorder.rb +0 -26
- data/lib/scout_apm/utils/gzip_helper.rb +0 -24
- data/lib/scout_apm/utils/numbers.rb +0 -14
- data/lib/scout_apm/utils/scm.rb +0 -14
- data/test/unit/background_job_integrations/sidekiq_test.rb +0 -104
- data/test/unit/context_test.rb +0 -30
- data/test/unit/git_revision_test.rb +0 -15
- data/test/unit/instruments/net_http_test.rb +0 -21
- data/test/unit/instruments/percentile_sampler_test.rb +0 -137
- data/test/unit/layer_children_set_test.rb +0 -88
- data/test/unit/limited_layer_test.rb +0 -53
- data/test/unit/remote/test_message.rb +0 -13
- data/test/unit/remote/test_router.rb +0 -33
- data/test/unit/remote/test_server.rb +0 -15
- data/test/unit/store_test.rb +0 -89
- data/test/unit/test_tracked_request.rb +0 -87
- data/test/unit/utils/numbers_test.rb +0 -15
- data/test/unit/utils/scm.rb +0 -17
@@ -1,122 +0,0 @@
|
|
1
|
-
module ScoutApm
|
2
|
-
# A LimitedLayer is a lossy-compression approach to fall back on once we max out
|
3
|
-
# the number of detailed layer objects we store. See LayerChildrenSet for the
|
4
|
-
# logic on when that change over happens
|
5
|
-
#
|
6
|
-
# QUESTION: What do we do if we attempt to merge an item that has children?
|
7
|
-
class LimitedLayer
|
8
|
-
attr_reader :type
|
9
|
-
|
10
|
-
def initialize(type)
|
11
|
-
@type = type
|
12
|
-
|
13
|
-
@total_call_time = 0
|
14
|
-
@total_exclusive_time = 0
|
15
|
-
@total_allocations = 0
|
16
|
-
@total_exclusive_allocations = 0
|
17
|
-
@total_layers = 0
|
18
|
-
end
|
19
|
-
|
20
|
-
def absorb(layer)
|
21
|
-
@total_layers += 1
|
22
|
-
|
23
|
-
@total_call_time += layer.total_call_time
|
24
|
-
@total_exclusive_time += layer.total_exclusive_time
|
25
|
-
|
26
|
-
@total_allocations += layer.total_allocations
|
27
|
-
@total_exclusive_allocations += layer.total_exclusive_allocations
|
28
|
-
end
|
29
|
-
|
30
|
-
def total_call_time
|
31
|
-
@total_call_time
|
32
|
-
end
|
33
|
-
|
34
|
-
def total_exclusive_time
|
35
|
-
@total_exclusive_time
|
36
|
-
end
|
37
|
-
|
38
|
-
def total_allocations
|
39
|
-
@total_allocations
|
40
|
-
end
|
41
|
-
|
42
|
-
def total_exclusive_allocations
|
43
|
-
@total_exclusive_allocations
|
44
|
-
end
|
45
|
-
|
46
|
-
def count
|
47
|
-
@total_layers
|
48
|
-
end
|
49
|
-
|
50
|
-
# This is the old style name. This function is used for now, but should be
|
51
|
-
# removed, and the new type & name split should be enforced through the
|
52
|
-
# app.
|
53
|
-
def legacy_metric_name
|
54
|
-
"#{type}/Limited"
|
55
|
-
end
|
56
|
-
|
57
|
-
def children
|
58
|
-
Set.new
|
59
|
-
end
|
60
|
-
|
61
|
-
def annotations
|
62
|
-
nil
|
63
|
-
end
|
64
|
-
|
65
|
-
def to_s
|
66
|
-
"<LimitedLayer type=#{type} count=#{count}>"
|
67
|
-
end
|
68
|
-
|
69
|
-
######################################################
|
70
|
-
# Stub out some methods with static default values #
|
71
|
-
######################################################
|
72
|
-
def subscopable?
|
73
|
-
false
|
74
|
-
end
|
75
|
-
|
76
|
-
def desc
|
77
|
-
nil
|
78
|
-
end
|
79
|
-
|
80
|
-
def backtrace
|
81
|
-
nil
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
#######################################################################
|
86
|
-
# Many methods don't make any sense on a limited layer. Raise errors #
|
87
|
-
# aggressively for now to detect mistaken calls #
|
88
|
-
#######################################################################
|
89
|
-
|
90
|
-
def add_child
|
91
|
-
raise "Should never call add_child on a limited_layer"
|
92
|
-
end
|
93
|
-
|
94
|
-
def record_stop_time!(*)
|
95
|
-
raise "Should never call record_stop_time! on a limited_layer"
|
96
|
-
end
|
97
|
-
|
98
|
-
def record_allocations!
|
99
|
-
raise "Should never call record_allocations! on a limited_layer"
|
100
|
-
end
|
101
|
-
|
102
|
-
def desc=(*)
|
103
|
-
raise "Should never call desc on a limited_layer"
|
104
|
-
end
|
105
|
-
|
106
|
-
def annotate_layer(*)
|
107
|
-
raise "Should never call annotate_layer on a limited_layer"
|
108
|
-
end
|
109
|
-
|
110
|
-
def subscopable!
|
111
|
-
raise "Should never call subscopable! on a limited_layer"
|
112
|
-
end
|
113
|
-
|
114
|
-
def capture_backtrace!
|
115
|
-
raise "Should never call capture_backtrace on a limited_layer"
|
116
|
-
end
|
117
|
-
|
118
|
-
def caller_array
|
119
|
-
raise "Should never call caller_array on a limited_layer"
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
data/lib/scout_apm/rack.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module ScoutApm
|
2
|
-
module Rack
|
3
|
-
def self.install!
|
4
|
-
ScoutApm::Agent.instance.start(:skip_app_server_check => true)
|
5
|
-
ScoutApm::Agent.instance.start_background_worker
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.transaction(endpoint_name, env)
|
9
|
-
req = ScoutApm::RequestManager.lookup
|
10
|
-
req.annotate_request(:uri => env["REQUEST_PATH"]) rescue nil
|
11
|
-
req.context.add_user(:ip => env["REMOTE_ADDR"]) rescue nil
|
12
|
-
|
13
|
-
req.web!
|
14
|
-
req.start_layer(ScoutApm::Layer.new('Controller', endpoint_name))
|
15
|
-
|
16
|
-
begin
|
17
|
-
yield
|
18
|
-
rescue
|
19
|
-
req.error!
|
20
|
-
raise
|
21
|
-
ensure
|
22
|
-
req.stop_layer
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module ScoutApm
|
2
|
-
module Remote
|
3
|
-
class Message
|
4
|
-
attr_reader :type
|
5
|
-
attr_reader :command
|
6
|
-
attr_reader :args
|
7
|
-
|
8
|
-
def initialize(type, command, *args)
|
9
|
-
@type = type
|
10
|
-
@command = command
|
11
|
-
@args = args
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.decode(msg)
|
15
|
-
Marshal.load(msg)
|
16
|
-
end
|
17
|
-
|
18
|
-
def encode
|
19
|
-
Marshal.dump(self)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module ScoutApm
|
2
|
-
module Remote
|
3
|
-
class Recorder
|
4
|
-
attr_reader :logger
|
5
|
-
attr_reader :remote_agent_host
|
6
|
-
attr_reader :remote_agent_port
|
7
|
-
|
8
|
-
def initialize(remote_agent_host, remote_agent_port, logger)
|
9
|
-
@remote_agent_host = remote_agent_host
|
10
|
-
@remote_agent_port = remote_agent_port
|
11
|
-
@logger = logger
|
12
|
-
end
|
13
|
-
|
14
|
-
def start
|
15
|
-
# nothing to do
|
16
|
-
self
|
17
|
-
end
|
18
|
-
|
19
|
-
def stop
|
20
|
-
# nothing to do
|
21
|
-
end
|
22
|
-
|
23
|
-
def record!(request)
|
24
|
-
begin
|
25
|
-
t1 = Time.now
|
26
|
-
# Mark this request as recorded, so the next lookup on this thread, it
|
27
|
-
# can be recreated
|
28
|
-
request.recorded!
|
29
|
-
|
30
|
-
# Only send requests that we actually want. Incidental http &
|
31
|
-
# background thread stuff can just be dropped
|
32
|
-
unless request.job? || request.web?
|
33
|
-
return
|
34
|
-
end
|
35
|
-
|
36
|
-
request.prepare_to_dump!
|
37
|
-
message = ScoutApm::Remote::Message.new('record', 'record!', request)
|
38
|
-
encoded = message.encode
|
39
|
-
logger.debug "Remote Agent: Posting a message of length: #{encoded.length}"
|
40
|
-
post(encoded)
|
41
|
-
t2 = Time.now
|
42
|
-
|
43
|
-
logger.debug("Remote Recording took: #{t2.to_f - t1.to_f} seconds")
|
44
|
-
rescue => e
|
45
|
-
logger.debug "Remote: Error while sending to collector: #{e.inspect}, #{e.backtrace.join("\n")}"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def post(encoded_message)
|
50
|
-
http = Net::HTTP.new(remote_agent_host, remote_agent_port)
|
51
|
-
request = Net::HTTP::Post.new("/users")
|
52
|
-
request.body = encoded_message
|
53
|
-
response = http.request(request)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module ScoutApm
|
2
|
-
module Remote
|
3
|
-
class Router
|
4
|
-
attr_reader :logger
|
5
|
-
attr_reader :routes
|
6
|
-
|
7
|
-
# If/When we add different types, this signature should change to a hash
|
8
|
-
# of {type => Object}, rather than building it in the initializer here.
|
9
|
-
#
|
10
|
-
# Keys of routes should be strings
|
11
|
-
def initialize(recorder, logger)
|
12
|
-
@routes = {
|
13
|
-
'record' => recorder
|
14
|
-
}
|
15
|
-
|
16
|
-
@logger = logger
|
17
|
-
end
|
18
|
-
|
19
|
-
# A message is a 2 element array [:type, :command, [args]].
|
20
|
-
# For this first creation, this should be ['record', 'record', [TrackedRequest]] (the args arg should always be an array, even w/ only 1 item)
|
21
|
-
#
|
22
|
-
# Where
|
23
|
-
# type: ['recorder']
|
24
|
-
# command: any function supported on that type of object
|
25
|
-
# args: any array of arguments
|
26
|
-
#
|
27
|
-
# Raises on unknown message
|
28
|
-
#
|
29
|
-
# Returns whatever the recipient object returns
|
30
|
-
def handle(msg)
|
31
|
-
message = Remote::Message.decode(msg)
|
32
|
-
assert_type(message)
|
33
|
-
call_route(message)
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def assert_type(message)
|
39
|
-
if ! routes.keys.include?(message.type.to_s)
|
40
|
-
raise "Unknown type: #{message.type.to_s}"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def call_route(message)
|
45
|
-
routes[message.type].send(message.command, *message.args)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# Web Server bound to localhost that listens for remote agent reports. Forwards
|
2
|
-
# onto the router
|
3
|
-
module ScoutApm
|
4
|
-
module Remote
|
5
|
-
class Server
|
6
|
-
attr_reader :router
|
7
|
-
attr_reader :bind
|
8
|
-
attr_reader :port
|
9
|
-
attr_reader :logger
|
10
|
-
|
11
|
-
def initialize(bind, port, router, logger)
|
12
|
-
@router = router
|
13
|
-
@logger = logger
|
14
|
-
@bind = bind
|
15
|
-
@port = port
|
16
|
-
@server = nil
|
17
|
-
end
|
18
|
-
|
19
|
-
def start
|
20
|
-
@server = WEBrick::HTTPServer.new(
|
21
|
-
:BindAddress => bind,
|
22
|
-
:Port => port,
|
23
|
-
:AccessLog => [],
|
24
|
-
:Logger => @logger
|
25
|
-
)
|
26
|
-
|
27
|
-
@server.mount_proc '/' do |request, response|
|
28
|
-
router.handle(request.body)
|
29
|
-
|
30
|
-
# arbitrary response, client doesn't expect anything in particular
|
31
|
-
response.body = 'Ok'
|
32
|
-
end
|
33
|
-
|
34
|
-
@thread = Thread.new do
|
35
|
-
begin
|
36
|
-
logger.debug("Remote: Starting Server on #{bind}:#{port}")
|
37
|
-
|
38
|
-
@server.start
|
39
|
-
|
40
|
-
logger.debug("Remote: Server returned after #start call, thread exiting")
|
41
|
-
rescue => e
|
42
|
-
logger.debug("Remote: Server Exception, #{e}")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def running?
|
48
|
-
@thread.alive?
|
49
|
-
@server && @server.status == :Running
|
50
|
-
end
|
51
|
-
|
52
|
-
def stop
|
53
|
-
@server.stop
|
54
|
-
@thread.kill
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
|
2
|
-
module ScoutApm
|
3
|
-
module Serializers
|
4
|
-
class HistogramsSerializerToJson
|
5
|
-
attr_reader :histograms
|
6
|
-
|
7
|
-
def initialize(histograms)
|
8
|
-
@histograms = histograms
|
9
|
-
end
|
10
|
-
|
11
|
-
def as_json
|
12
|
-
histograms.map do |histo|
|
13
|
-
{
|
14
|
-
"name" => histo.name,
|
15
|
-
"histogram" => histo.histogram.as_json,
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# Provide a synchronous approach to recording TrackedRequests
|
2
|
-
# Doesn't attempt to background the work, or do it elsewhere. It happens
|
3
|
-
# inline, in the caller thread right when record! is called
|
4
|
-
|
5
|
-
module ScoutApm
|
6
|
-
class SynchronousRecorder
|
7
|
-
attr_reader :logger
|
8
|
-
|
9
|
-
def initialize(logger)
|
10
|
-
@logger = logger
|
11
|
-
end
|
12
|
-
|
13
|
-
def start
|
14
|
-
# nothing to do
|
15
|
-
self
|
16
|
-
end
|
17
|
-
|
18
|
-
def stop
|
19
|
-
# nothing to do
|
20
|
-
end
|
21
|
-
|
22
|
-
def record!(request)
|
23
|
-
request.record!
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module ScoutApm
|
2
|
-
module Utils
|
3
|
-
# A simple wrapper around Ruby's built-in gzip support.
|
4
|
-
class GzipHelper
|
5
|
-
DEFAULT_GZIP_LEVEL = 5
|
6
|
-
|
7
|
-
attr_reader :level
|
8
|
-
|
9
|
-
def initialize(level = DEFAULT_GZIP_LEVEL)
|
10
|
-
@level = level
|
11
|
-
end
|
12
|
-
|
13
|
-
def deflate(str)
|
14
|
-
strio = StringIO.new
|
15
|
-
|
16
|
-
gz = Zlib::GzipWriter.new(strio, level)
|
17
|
-
gz.write str
|
18
|
-
gz.close
|
19
|
-
|
20
|
-
strio.string
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/scout_apm/utils/scm.rb
DELETED
@@ -1,14 +0,0 @@
|
|
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
|