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.
- checksums.yaml +5 -5
- data/.gitignore +1 -2
- data/.rubocop.yml +3 -11
- data/CHANGELOG.markdown +4 -362
- data/Gemfile +1 -14
- data/README.markdown +7 -52
- data/Rakefile +1 -0
- data/ext/allocations/allocations.c +1 -7
- data/ext/allocations/extconf.rb +0 -1
- data/ext/rusage/rusage.c +0 -26
- data/ext/stacks/extconf.rb +37 -0
- data/ext/stacks/scout_atomics.h +86 -0
- data/ext/stacks/stacks.c +811 -0
- data/lib/scout_apm/agent/logging.rb +69 -0
- data/lib/scout_apm/agent/reporting.rb +126 -0
- data/lib/scout_apm/agent.rb +259 -138
- data/lib/scout_apm/app_server_load.rb +15 -41
- data/lib/scout_apm/attribute_arranger.rb +3 -14
- data/lib/scout_apm/background_job_integrations/delayed_job.rb +1 -70
- data/lib/scout_apm/background_job_integrations/sidekiq.rb +24 -31
- data/lib/scout_apm/background_worker.rb +12 -23
- data/lib/scout_apm/capacity.rb +57 -0
- data/lib/scout_apm/config.rb +37 -206
- data/lib/scout_apm/context.rb +4 -20
- 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 +28 -42
- data/lib/scout_apm/fake_store.rb +0 -12
- data/lib/scout_apm/framework_integrations/rails_2.rb +1 -2
- data/lib/scout_apm/framework_integrations/rails_3_or_4.rb +6 -17
- data/lib/scout_apm/framework_integrations/sinatra.rb +1 -1
- data/lib/scout_apm/histogram.rb +3 -12
- data/lib/scout_apm/instant/assets/xmlhttp_instrumentation.html +2 -2
- data/lib/scout_apm/instant/middleware.rb +54 -202
- data/lib/scout_apm/instant_reporting.rb +7 -7
- data/lib/scout_apm/instruments/.DS_Store +0 -0
- data/lib/scout_apm/instruments/action_controller_rails_2.rb +9 -15
- data/lib/scout_apm/instruments/action_controller_rails_3_rails4.rb +76 -124
- data/lib/scout_apm/instruments/active_record.rb +29 -324
- data/lib/scout_apm/instruments/delayed_job.rb +57 -0
- data/lib/scout_apm/instruments/elasticsearch.rb +6 -10
- data/lib/scout_apm/instruments/grape.rb +9 -12
- data/lib/scout_apm/instruments/http_client.rb +7 -14
- data/lib/scout_apm/instruments/influxdb.rb +6 -10
- data/lib/scout_apm/instruments/middleware_detailed.rb +11 -15
- data/lib/scout_apm/instruments/middleware_summary.rb +5 -11
- data/lib/scout_apm/instruments/mongoid.rb +8 -39
- data/lib/scout_apm/instruments/moped.rb +6 -11
- data/lib/scout_apm/instruments/net_http.rb +9 -27
- data/lib/scout_apm/instruments/percentile_sampler.rb +23 -42
- data/lib/scout_apm/instruments/process/process_cpu.rb +6 -11
- data/lib/scout_apm/instruments/process/process_memory.rb +12 -17
- data/lib/scout_apm/instruments/rails_router.rb +6 -12
- data/lib/scout_apm/instruments/redis.rb +6 -10
- data/lib/scout_apm/instruments/sinatra.rb +4 -5
- data/lib/scout_apm/job_record.rb +2 -4
- data/lib/scout_apm/layaway.rb +34 -88
- data/lib/scout_apm/layaway_file.rb +3 -13
- data/lib/scout_apm/layer.rb +60 -25
- data/lib/scout_apm/layer_converters/allocation_metric_converter.rb +6 -7
- data/lib/scout_apm/layer_converters/converter_base.rb +14 -203
- data/lib/scout_apm/layer_converters/depth_first_walker.rb +10 -22
- data/lib/scout_apm/layer_converters/error_converter.rb +8 -8
- data/lib/scout_apm/layer_converters/job_converter.rb +50 -37
- data/lib/scout_apm/layer_converters/metric_converter.rb +19 -18
- data/lib/scout_apm/layer_converters/request_queue_time_converter.rb +13 -13
- data/lib/scout_apm/layer_converters/slow_job_converter.rb +116 -52
- data/lib/scout_apm/layer_converters/slow_request_converter.rb +120 -51
- data/lib/scout_apm/metric_meta.rb +5 -0
- data/lib/scout_apm/metric_set.rb +1 -9
- data/lib/scout_apm/metric_stats.rb +8 -7
- data/lib/scout_apm/middleware.rb +9 -7
- data/lib/scout_apm/reporter.rb +24 -71
- data/lib/scout_apm/request_histograms.rb +0 -12
- data/lib/scout_apm/request_manager.rb +7 -5
- data/lib/scout_apm/scored_item_set.rb +0 -7
- data/lib/scout_apm/serializers/app_server_load_serializer.rb +0 -4
- data/lib/scout_apm/serializers/deploy_serializer.rb +16 -0
- data/lib/scout_apm/serializers/directive_serializer.rb +0 -4
- data/lib/scout_apm/serializers/payload_serializer.rb +4 -11
- data/lib/scout_apm/serializers/payload_serializer_to_json.rb +16 -35
- data/lib/scout_apm/serializers/slow_jobs_serializer_to_json.rb +1 -2
- data/lib/scout_apm/server_integrations/passenger.rb +1 -1
- data/lib/scout_apm/server_integrations/puma.rb +2 -5
- data/lib/scout_apm/slow_job_policy.rb +13 -25
- data/lib/scout_apm/slow_job_record.rb +4 -13
- data/lib/scout_apm/slow_request_policy.rb +13 -25
- data/lib/scout_apm/slow_transaction.rb +5 -25
- data/lib/scout_apm/store.rb +32 -99
- data/lib/scout_apm/trace_compactor.rb +312 -0
- data/lib/scout_apm/tracer.rb +31 -35
- data/lib/scout_apm/tracked_request.rb +95 -262
- data/lib/scout_apm/utils/active_record_metric_name.rb +13 -88
- data/lib/scout_apm/utils/backtrace_parser.rb +4 -7
- data/lib/scout_apm/utils/fake_stacks.rb +87 -0
- data/lib/scout_apm/utils/installed_gems.rb +3 -7
- data/lib/scout_apm/utils/klass_helper.rb +2 -8
- data/lib/scout_apm/utils/null_logger.rb +13 -0
- data/lib/scout_apm/utils/sql_sanitizer.rb +5 -16
- data/lib/scout_apm/utils/sql_sanitizer_regex.rb +0 -7
- data/lib/scout_apm/utils/sql_sanitizer_regex_1_8_7.rb +0 -6
- data/lib/scout_apm/utils/unique_id.rb +0 -27
- data/lib/scout_apm/version.rb +2 -1
- data/lib/scout_apm.rb +25 -84
- data/scout_apm.gemspec +3 -17
- data/test/test_helper.rb +3 -57
- data/test/unit/agent_test.rb +54 -1
- data/test/unit/background_job_integrations/sidekiq_test.rb +3 -0
- data/test/unit/config_test.rb +12 -25
- data/test/unit/context_test.rb +4 -4
- data/test/unit/histogram_test.rb +4 -25
- data/test/unit/ignored_uris_test.rb +1 -1
- data/test/unit/instruments/active_record_instruments_test.rb +5 -0
- data/test/unit/layaway_test.rb +2 -62
- data/test/unit/serializers/payload_serializer_test.rb +15 -43
- data/test/unit/slow_request_policy_test.rb +6 -15
- data/test/unit/sql_sanitizer_test.rb +6 -53
- data/test/unit/store_test.rb +4 -73
- data/test/unit/utils/active_record_metric_name_test.rb +5 -59
- data/test/unit/utils/backtrace_parser_test.rb +1 -6
- data/tester.rb +53 -0
- metadata +28 -229
- data/.travis.yml +0 -26
- data/Guardfile +0 -43
- data/gems/README.md +0 -28
- data/gems/octoshark.gemfile +0 -4
- data/gems/rails3.gemfile +0 -5
- data/gems/rails4.gemfile +0 -4
- data/gems/rails5.gemfile +0 -4
- data/gems/rails6.gemfile +0 -4
- data/lib/scout_apm/agent/exit_handler.rb +0 -65
- data/lib/scout_apm/agent/preconditions.rb +0 -81
- data/lib/scout_apm/agent_context.rb +0 -261
- data/lib/scout_apm/auto_instrument/instruction_sequence.rb +0 -31
- data/lib/scout_apm/auto_instrument/layer.rb +0 -23
- data/lib/scout_apm/auto_instrument/parser.rb +0 -27
- data/lib/scout_apm/auto_instrument/rails.rb +0 -175
- data/lib/scout_apm/auto_instrument.rb +0 -5
- data/lib/scout_apm/background_job_integrations/legacy_sneakers.rb +0 -55
- data/lib/scout_apm/background_job_integrations/que.rb +0 -134
- data/lib/scout_apm/background_job_integrations/resque.rb +0 -88
- data/lib/scout_apm/background_job_integrations/shoryuken.rb +0 -124
- data/lib/scout_apm/background_job_integrations/sneakers.rb +0 -87
- data/lib/scout_apm/background_recorder.rb +0 -48
- data/lib/scout_apm/db_query_metric_set.rb +0 -97
- data/lib/scout_apm/db_query_metric_stats.rb +0 -102
- data/lib/scout_apm/debug.rb +0 -37
- data/lib/scout_apm/detailed_trace.rb +0 -217
- data/lib/scout_apm/error.rb +0 -27
- data/lib/scout_apm/error_service/error_buffer.rb +0 -39
- data/lib/scout_apm/error_service/error_record.rb +0 -211
- data/lib/scout_apm/error_service/ignored_exceptions.rb +0 -66
- data/lib/scout_apm/error_service/middleware.rb +0 -32
- data/lib/scout_apm/error_service/notifier.rb +0 -33
- data/lib/scout_apm/error_service/payload.rb +0 -47
- data/lib/scout_apm/error_service/periodic_work.rb +0 -17
- data/lib/scout_apm/error_service/railtie.rb +0 -11
- data/lib/scout_apm/error_service/sidekiq.rb +0 -80
- data/lib/scout_apm/error_service.rb +0 -32
- data/lib/scout_apm/extensions/config.rb +0 -87
- data/lib/scout_apm/extensions/transaction_callback_payload.rb +0 -74
- data/lib/scout_apm/git_revision.rb +0 -59
- data/lib/scout_apm/instrument_manager.rb +0 -88
- data/lib/scout_apm/instruments/action_view.rb +0 -141
- data/lib/scout_apm/instruments/http.rb +0 -48
- data/lib/scout_apm/instruments/memcached.rb +0 -43
- data/lib/scout_apm/instruments/resque.rb +0 -39
- data/lib/scout_apm/instruments/samplers.rb +0 -11
- data/lib/scout_apm/layer_children_set.rb +0 -86
- data/lib/scout_apm/layer_converters/database_converter.rb +0 -70
- data/lib/scout_apm/layer_converters/find_layer_by_type.rb +0 -38
- data/lib/scout_apm/layer_converters/histograms.rb +0 -15
- data/lib/scout_apm/layer_converters/trace_converter.rb +0 -184
- data/lib/scout_apm/limited_layer.rb +0 -126
- data/lib/scout_apm/logger.rb +0 -158
- data/lib/scout_apm/periodic_work.rb +0 -47
- data/lib/scout_apm/rack.rb +0 -26
- data/lib/scout_apm/remote/message.rb +0 -27
- 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 -60
- data/lib/scout_apm/reporting.rb +0 -143
- data/lib/scout_apm/serializers/db_query_serializer_to_json.rb +0 -15
- data/lib/scout_apm/serializers/histograms_serializer_to_json.rb +0 -21
- data/lib/scout_apm/synchronous_recorder.rb +0 -30
- data/lib/scout_apm/tasks/doctor.rb +0 -75
- data/lib/scout_apm/tasks/support.rb +0 -22
- data/lib/scout_apm/transaction.rb +0 -13
- data/lib/scout_apm/transaction_time_consumed.rb +0 -51
- data/lib/scout_apm/utils/gzip_helper.rb +0 -24
- data/lib/scout_apm/utils/marshal_logging.rb +0 -90
- data/lib/scout_apm/utils/numbers.rb +0 -14
- data/lib/scout_apm/utils/scm.rb +0 -14
- data/lib/tasks/doctor.rake +0 -11
- data/test/tmp/README.md +0 -17
- data/test/unit/agent_context_test.rb +0 -15
- data/test/unit/auto_instrument/assignments-instrumented.rb +0 -31
- data/test/unit/auto_instrument/assignments.rb +0 -31
- data/test/unit/auto_instrument/controller-ast.txt +0 -57
- data/test/unit/auto_instrument/controller-instrumented.rb +0 -49
- data/test/unit/auto_instrument/controller.rb +0 -49
- data/test/unit/auto_instrument/rescue_from-instrumented.rb +0 -13
- data/test/unit/auto_instrument/rescue_from.rb +0 -13
- data/test/unit/auto_instrument_test.rb +0 -54
- data/test/unit/db_query_metric_set_test.rb +0 -67
- data/test/unit/db_query_metric_stats_test.rb +0 -113
- data/test/unit/error_service/error_buffer_test.rb +0 -25
- data/test/unit/error_service/ignored_exceptions_test.rb +0 -49
- data/test/unit/extensions/periodic_callbacks_test.rb +0 -58
- data/test/unit/extensions/transaction_callbacks_test.rb +0 -58
- data/test/unit/fake_store_test.rb +0 -10
- data/test/unit/git_revision_test.rb +0 -15
- data/test/unit/instruments/active_record_test.rb +0 -40
- data/test/unit/instruments/net_http_test.rb +0 -27
- data/test/unit/instruments/percentile_sampler_test.rb +0 -133
- data/test/unit/layer_children_set_test.rb +0 -97
- data/test/unit/layer_converters/depth_first_walker_test.rb +0 -70
- data/test/unit/layer_converters/metric_converter_test.rb +0 -22
- data/test/unit/layer_converters/stubs.rb +0 -33
- data/test/unit/limited_layer_test.rb +0 -53
- data/test/unit/logger_test.rb +0 -69
- 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/request_histograms_test.rb +0 -17
- data/test/unit/tracer_test.rb +0 -76
- data/test/unit/tracked_request_test.rb +0 -71
- data/test/unit/transaction_test.rb +0 -14
- data/test/unit/transaction_time_consumed_test.rb +0 -46
- data/test/unit/utils/numbers_test.rb +0 -15
- 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
|
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
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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.
|
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
|
-
|
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
|
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 =
|
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)
|
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
|
-
|
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 -
|
40
|
-
@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
|
-
|
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
|
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 =
|
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)
|
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
|
-
|
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 -
|
35
|
-
@hostname =
|
30
|
+
@seconds_since_startup = (Time.now - ScoutApm::Agent.instance.process_start_time)
|
31
|
+
@hostname = ScoutApm::Environment.instance.hostname
|
36
32
|
@score = score
|
37
|
-
|
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
|
|
data/lib/scout_apm/store.rb
CHANGED
@@ -3,52 +3,30 @@
|
|
3
3
|
# the layaway file for cross-process aggregation.
|
4
4
|
module ScoutApm
|
5
5
|
class Store
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
19
|
+
StoreReportingPeriodTimestamp.new
|
17
20
|
end
|
18
21
|
|
19
22
|
def current_period
|
20
|
-
|
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
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
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
|
-
|
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
|
-
|
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(
|
121
|
-
@samplers <<
|
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
|
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
|
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
|
-
|
208
|
-
|
209
|
-
def initialize(timestamp, context)
|
168
|
+
def initialize(timestamp)
|
210
169
|
@timestamp = timestamp
|
211
170
|
|
212
|
-
@request_traces = ScoredItemSet.new
|
213
|
-
@job_traces = ScoredItemSet.new
|
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
|
#################################
|