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
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'sqlite3'
|
3
|
-
require 'active_record'
|
4
|
-
|
5
|
-
begin
|
6
|
-
require 'octoshark'
|
7
|
-
rescue LoadError
|
8
|
-
# Ignore
|
9
|
-
end
|
10
|
-
|
11
|
-
class ActiveRecordTest < Minitest::Test
|
12
|
-
def database_path
|
13
|
-
File.expand_path('test.sqlite3', DATA_FILE_DIR)
|
14
|
-
end
|
15
|
-
|
16
|
-
def setup
|
17
|
-
database = SQLite3::Database.new(database_path)
|
18
|
-
database.execute("DROP TABLE IF EXISTS users;")
|
19
|
-
database.execute("CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(100));")
|
20
|
-
|
21
|
-
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => database_path)
|
22
|
-
end
|
23
|
-
|
24
|
-
class User < ActiveRecord::Base
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_instrumentation
|
28
|
-
recorder = FakeRecorder.new
|
29
|
-
agent_context.recorder = recorder
|
30
|
-
|
31
|
-
instrument = ScoutApm::Instruments::ActiveRecord.new(agent_context)
|
32
|
-
instrument.install
|
33
|
-
|
34
|
-
ScoutApm::Tracer.instrument("Controller", "foo/bar") do
|
35
|
-
user = User.create
|
36
|
-
end
|
37
|
-
|
38
|
-
assert 1, recorder.requests.size
|
39
|
-
end
|
40
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'scout_apm/instruments/net_http'
|
4
|
-
|
5
|
-
require 'addressable/uri'
|
6
|
-
|
7
|
-
class NetHttpTest < Minitest::Test
|
8
|
-
def setup
|
9
|
-
@context = ScoutApm::AgentContext.new
|
10
|
-
ScoutApm::Instruments::NetHttp.new(@context).install
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_request_scout_description_for_uri
|
14
|
-
if RUBY_VERSION <= '1.9.3'
|
15
|
-
req = Net::HTTP::Get.new('/here')
|
16
|
-
else
|
17
|
-
req = Net::HTTP::Get.new(URI('http://example.org/here'))
|
18
|
-
end
|
19
|
-
|
20
|
-
assert_equal '/here', Net::HTTP.new('').request_scout_description(req)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_request_scout_description_for_addressable
|
24
|
-
req = Net::HTTP::Get.new(Addressable::URI.parse('http://example.org/here'))
|
25
|
-
assert_equal '/here', Net::HTTP.new('').request_scout_description(req)
|
26
|
-
end
|
27
|
-
end
|
@@ -1,133 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'scout_apm/instruments/percentile_sampler'
|
4
|
-
|
5
|
-
class PercentileSamplerTest < Minitest::Test
|
6
|
-
PercentileSampler = ScoutApm::Instruments::PercentileSampler
|
7
|
-
HistogramReport = ScoutApm::Instruments::HistogramReport
|
8
|
-
|
9
|
-
attr_reader :subject
|
10
|
-
|
11
|
-
def setup
|
12
|
-
@context = ScoutApm::AgentContext.new
|
13
|
-
@subject = PercentileSampler.new(@context)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_initialize_with_logger_and_histogram_set
|
17
|
-
assert_equal subject.logger, @context.logger
|
18
|
-
assert_equal subject.histograms, @context.request_histograms_by_time
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_implements_instrument_interface
|
22
|
-
assert subject.respond_to?(:human_name)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_percentiles_returns_one_percentile_per_endpoint_at_time
|
26
|
-
histograms[time].add("foo", 10)
|
27
|
-
histograms[time].add("bar", 15)
|
28
|
-
histograms[time2].add("baz", 15)
|
29
|
-
|
30
|
-
assert_equal subject.percentiles(time).length, 2
|
31
|
-
assert_equal subject.percentiles(time2).length, 1
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_percentiles_clears_time_from_hash
|
35
|
-
histograms[time].add("foo", 10)
|
36
|
-
histograms[time2].add("baz", 15)
|
37
|
-
|
38
|
-
subject.percentiles(time)
|
39
|
-
|
40
|
-
assert_false histograms.key?(time)
|
41
|
-
assert histograms.key?(time + 10)
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_percentiles_returns_histogram_reports
|
45
|
-
histograms[time].add("foo", 10)
|
46
|
-
|
47
|
-
assert subject.percentiles(time).
|
48
|
-
all?{ |item| item.is_a?(HistogramReport) }
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_percentiles_returns_correct_histogram_report
|
52
|
-
histograms[time].add("foo", 100)
|
53
|
-
histograms[time].add("foo", 200)
|
54
|
-
histograms[time].add("foo", 100)
|
55
|
-
histograms[time].add("foo", 300)
|
56
|
-
|
57
|
-
report = subject.percentiles(time).first
|
58
|
-
histogram = report.histogram
|
59
|
-
|
60
|
-
assert_equal "foo", report.name
|
61
|
-
assert_equal 4, histogram.total
|
62
|
-
assert_equal [[2, 100], [1, 200], [1, 300]],
|
63
|
-
histogram.bins.map{|bin| [bin.count, bin.value] }
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_metrics_saves_histogram_to_store
|
67
|
-
store = mock
|
68
|
-
store.expects(:track_histograms!)
|
69
|
-
subject.metrics(ScoutApm::StoreReportingPeriodTimestamp.new(time), store)
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
################################################################################
|
74
|
-
# HistogramReport Test
|
75
|
-
################################################################################
|
76
|
-
def test_histogram_report_combine_refuses_to_combine_mismatched_name
|
77
|
-
assert_raises { HistogramReport.new("foo", histogram).combine!(HistogramReport.new("bar", histogram)) }
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_histogram_report_merge_keeps_name
|
81
|
-
report1 = HistogramReport.new("foo", histogram)
|
82
|
-
report2 = HistogramReport.new("foo", histogram)
|
83
|
-
combined = report1.combine!(report2)
|
84
|
-
|
85
|
-
assert "foo", combined.name
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_histogram_report_combine_merges_histograms
|
89
|
-
histogram1 = histogram
|
90
|
-
histogram2 = histogram
|
91
|
-
histogram1.add(1)
|
92
|
-
histogram1.add(2)
|
93
|
-
histogram2.add(2)
|
94
|
-
histogram2.add(3)
|
95
|
-
|
96
|
-
report1 = HistogramReport.new("foo", histogram1)
|
97
|
-
report2 = HistogramReport.new("foo", histogram2)
|
98
|
-
combined = report1.combine!(report2)
|
99
|
-
|
100
|
-
assert_equal 4, combined.histogram.total
|
101
|
-
assert_equal [[1, 1], [2, 2], [1, 3]],
|
102
|
-
combined.histogram.bins.map{|bin| [bin.count, bin.value.to_i] }
|
103
|
-
end
|
104
|
-
|
105
|
-
################################################################################
|
106
|
-
# Test Helpers
|
107
|
-
################################################################################
|
108
|
-
def logger
|
109
|
-
@logger ||= begin
|
110
|
-
@logger_io = StringIO.new
|
111
|
-
Logger.new(@logger_io)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def histograms
|
116
|
-
@context.request_histograms_by_time
|
117
|
-
end
|
118
|
-
|
119
|
-
def histogram
|
120
|
-
max_bins = 20
|
121
|
-
ScoutApm::NumericHistogram.new(max_bins)
|
122
|
-
end
|
123
|
-
|
124
|
-
# An arbitrary time
|
125
|
-
def time
|
126
|
-
@time ||= Time.now
|
127
|
-
end
|
128
|
-
|
129
|
-
def time2
|
130
|
-
time + 10
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'scout_apm/layer_children_set'
|
3
|
-
|
4
|
-
class LayerChildrenSetTest < Minitest::Test
|
5
|
-
SET = ScoutApm::LayerChildrenSet
|
6
|
-
|
7
|
-
def test_limit_default
|
8
|
-
assert_equal SET::DEFAULT_UNIQUE_CUTOFF, SET.new.unique_cutoff
|
9
|
-
end
|
10
|
-
|
11
|
-
# Add 5, make sure they're all in the children list we get back.
|
12
|
-
def test_add_layer_before_limit
|
13
|
-
s = SET.new(5)
|
14
|
-
|
15
|
-
5.times do
|
16
|
-
s << make_layer("LayerType", "LayerName")
|
17
|
-
end
|
18
|
-
|
19
|
-
children = s.to_a
|
20
|
-
assert_equal 5, children.size
|
21
|
-
|
22
|
-
# Don't care about order
|
23
|
-
(0..4).each do |i|
|
24
|
-
assert children.include?(lookup_layer(i))
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_add_layer_after_limit
|
29
|
-
s = SET.new(5)
|
30
|
-
|
31
|
-
10.times do
|
32
|
-
s << make_layer("LayerType", "LayerName")
|
33
|
-
end
|
34
|
-
|
35
|
-
children = s.to_a
|
36
|
-
# 6 = 5 real ones + 1 merged.
|
37
|
-
assert_equal 6, children.size
|
38
|
-
|
39
|
-
# Don't care about order
|
40
|
-
(0..4).each do |i|
|
41
|
-
assert children.include?(lookup_layer(i))
|
42
|
-
end
|
43
|
-
|
44
|
-
# Don't care about order
|
45
|
-
(5..9).each do |i|
|
46
|
-
assert ! children.include?(lookup_layer(i))
|
47
|
-
end
|
48
|
-
|
49
|
-
limited_layer = children.last
|
50
|
-
assert_equal ScoutApm::LimitedLayer, limited_layer.class
|
51
|
-
assert_equal 5, limited_layer.count
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_add_layer_with_different_type_after_limit
|
55
|
-
s = SET.new(5)
|
56
|
-
|
57
|
-
# Add 20 items
|
58
|
-
10.times do
|
59
|
-
s << make_layer("LayerType", "LayerName")
|
60
|
-
s << make_layer("DifferentLayerType", "LayerName")
|
61
|
-
end
|
62
|
-
|
63
|
-
children = s.to_a
|
64
|
-
|
65
|
-
# Tyo types, so 2 distinct limitdlayer objects
|
66
|
-
limited_layers = children.select{ |l| ScoutApm::LimitedLayer === l }
|
67
|
-
assert_equal 2, limited_layers.length
|
68
|
-
|
69
|
-
# 5 unchanged children each for the two layer types, plus the 2 limitd when each overran their limit
|
70
|
-
assert_equal 12, children.length
|
71
|
-
limited_layers.each { |ml| assert_equal 5, ml.count }
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_works_with_marshal
|
75
|
-
s = SET.new(5)
|
76
|
-
10.times do
|
77
|
-
s << make_layer("LayerType", "LayerName")
|
78
|
-
end
|
79
|
-
|
80
|
-
Marshal.dump(s)
|
81
|
-
end
|
82
|
-
|
83
|
-
#############
|
84
|
-
# Helpers #
|
85
|
-
#############
|
86
|
-
|
87
|
-
def make_layer(type, name)
|
88
|
-
@made_layers ||= []
|
89
|
-
l = ScoutApm::Layer.new(type, name)
|
90
|
-
@made_layers << l
|
91
|
-
l
|
92
|
-
end
|
93
|
-
|
94
|
-
def lookup_layer(i)
|
95
|
-
@made_layers[i]
|
96
|
-
end
|
97
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module ScoutApm
|
4
|
-
class DepthFirstWalkerTest < Minitest::Test
|
5
|
-
def test_walk_single_node_calls_callbacks_in_order
|
6
|
-
calls = []
|
7
|
-
layer = Layer.new("A", "x")
|
8
|
-
|
9
|
-
walker = LayerConverters::DepthFirstWalker.new(layer)
|
10
|
-
walker.before { |l| calls << :before }
|
11
|
-
walker.after { |l| calls << :after }
|
12
|
-
walker.on { |l| calls << :on }
|
13
|
-
|
14
|
-
walker.walk
|
15
|
-
|
16
|
-
assert_equal [:before, :on, :after], calls
|
17
|
-
end
|
18
|
-
|
19
|
-
# Tree looks like:
|
20
|
-
# A
|
21
|
-
# |
|
22
|
-
# B
|
23
|
-
# / \ \
|
24
|
-
# C D E
|
25
|
-
# / \
|
26
|
-
# F G
|
27
|
-
def test_walk_interesting_tree
|
28
|
-
# The test could be rewritten to support 1.8.7, but it would likely be much
|
29
|
-
# harder to read.
|
30
|
-
skip "Lack of set ordering in Ruby 1.8.7 prevents this test from running correctly" if RUBY_VERSION.start_with?("1.8.")
|
31
|
-
|
32
|
-
calls = []
|
33
|
-
a = Layer.new("A", "x")
|
34
|
-
b = Layer.new("B", "x")
|
35
|
-
c = Layer.new("C", "x")
|
36
|
-
d = Layer.new("D", "x")
|
37
|
-
e = Layer.new("E", "x")
|
38
|
-
f = Layer.new("F", "x")
|
39
|
-
g = Layer.new("G", "x")
|
40
|
-
a.add_child(b)
|
41
|
-
b.add_child(c)
|
42
|
-
b.add_child(d)
|
43
|
-
b.add_child(e)
|
44
|
-
c.add_child(f)
|
45
|
-
c.add_child(g)
|
46
|
-
|
47
|
-
root_layer = a
|
48
|
-
|
49
|
-
walker = LayerConverters::DepthFirstWalker.new(root_layer)
|
50
|
-
walker.before { |l| calls << "#{l.type} before" }
|
51
|
-
walker.after { |l| calls << "#{l.type} after" }
|
52
|
-
walker.on { |l| calls << "#{l.type} on" }
|
53
|
-
|
54
|
-
walker.walk
|
55
|
-
|
56
|
-
assert_equal [
|
57
|
-
"A before", "A on", # before & on always line up next to each other
|
58
|
-
"B before", "B on",
|
59
|
-
"C before", "C on",
|
60
|
-
"F before", "F on", "F after", # leaf nodes run all 3
|
61
|
-
"G before", "G on", "G after",
|
62
|
-
"C after", # once all children are done, do a node's after
|
63
|
-
"D before", "D on", "D after",
|
64
|
-
"E before", "E on", "E after",
|
65
|
-
"B after",
|
66
|
-
"A after"
|
67
|
-
], calls
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require File.join(File.dirname(__FILE__), 'stubs')
|
3
|
-
|
4
|
-
module ScoutApm
|
5
|
-
module LayerConverters
|
6
|
-
class MetricConverterTest < Minitest::Test
|
7
|
-
include Stubs
|
8
|
-
|
9
|
-
def test_register_adds_hooks
|
10
|
-
mc = MetricConverter.new(agent_context, faux_request, faux_layer_finder, faux_store)
|
11
|
-
faux_walker.expects(:on)
|
12
|
-
mc.register_hooks(faux_walker)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_record
|
16
|
-
mc = MetricConverter.new(agent_context, faux_request, faux_layer_finder, faux_store)
|
17
|
-
faux_store.expects(:track!)
|
18
|
-
mc.record!
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
####################################
|
2
|
-
# Stubs for LayerConverter Tests #
|
3
|
-
####################################
|
4
|
-
module ScoutApm
|
5
|
-
module LayerConverters
|
6
|
-
module Stubs
|
7
|
-
def faux_walker(subscope_stubs = true)
|
8
|
-
@w ||= stub
|
9
|
-
|
10
|
-
if subscope_stubs && !@w_set_subscope_stubs
|
11
|
-
@w_set_subscope_stubs = true
|
12
|
-
@w.expects(:before)
|
13
|
-
@w.expects(:after)
|
14
|
-
end
|
15
|
-
@w
|
16
|
-
end
|
17
|
-
|
18
|
-
def faux_request
|
19
|
-
@req ||= stub(:root_layer => stub)
|
20
|
-
end
|
21
|
-
|
22
|
-
def faux_layer_finder
|
23
|
-
@layer_finder ||= stub
|
24
|
-
@layer_finder.stubs(:scope => stub)
|
25
|
-
@layer_finder
|
26
|
-
end
|
27
|
-
|
28
|
-
def faux_store
|
29
|
-
@store ||= stub
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'ostruct'
|
3
|
-
|
4
|
-
class LimitedLayerTest < Minitest::Test
|
5
|
-
|
6
|
-
def test_counts_while_absorbing
|
7
|
-
ll = ScoutApm::LimitedLayer.new("ActiveRecord")
|
8
|
-
assert_equal 0, ll.count
|
9
|
-
|
10
|
-
ll.absorb faux_layer("ActiveRecord", "User#Find", 2, 1, 200, 100)
|
11
|
-
assert_equal 1, ll.count
|
12
|
-
|
13
|
-
ll.absorb faux_layer("ActiveRecord", "User#Find", 2, 1, 200, 100)
|
14
|
-
assert_equal 2, ll.count
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_sums_values_while_absorbing
|
18
|
-
ll = ScoutApm::LimitedLayer.new("ActiveRecord")
|
19
|
-
|
20
|
-
ll.absorb faux_layer("ActiveRecord", "User#Find", 2, 1, 200, 100)
|
21
|
-
assert_equal 1, ll.total_exclusive_time
|
22
|
-
assert_equal 2, ll.total_call_time
|
23
|
-
assert_equal 100, ll.total_exclusive_allocations
|
24
|
-
assert_equal 200, ll.total_allocations
|
25
|
-
|
26
|
-
|
27
|
-
ll.absorb faux_layer("ActiveRecord", "User#Find", 4, 3, 400, 300)
|
28
|
-
assert_equal 4, ll.total_exclusive_time # 3 + 1
|
29
|
-
assert_equal 6, ll.total_call_time # 4 + 2
|
30
|
-
assert_equal 400, ll.total_exclusive_allocations # 300 + 100
|
31
|
-
assert_equal 600, ll.total_allocations # 400 + 200
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_the_name
|
35
|
-
ll = ScoutApm::LimitedLayer.new("ActiveRecord")
|
36
|
-
assert_equal "ActiveRecord/Limited", ll.legacy_metric_name
|
37
|
-
end
|
38
|
-
|
39
|
-
#############
|
40
|
-
# Helpers #
|
41
|
-
#############
|
42
|
-
|
43
|
-
def faux_layer(type, name, tct, tet, a_tct, a_tet)
|
44
|
-
OpenStruct.new(
|
45
|
-
:type => type,
|
46
|
-
:name => name,
|
47
|
-
:total_call_time => tct,
|
48
|
-
:total_exclusive_time => tet,
|
49
|
-
:total_allocations => a_tct,
|
50
|
-
:total_exclusive_allocations => a_tet
|
51
|
-
)
|
52
|
-
end
|
53
|
-
end
|
data/test/unit/logger_test.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
require 'scout_apm/logger'
|
5
|
-
|
6
|
-
class LoggerTest < Minitest::Test
|
7
|
-
def setup
|
8
|
-
@env_root = Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), "..", "..")))
|
9
|
-
FileUtils.mkdir_p(@env_root + "log")
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_detect_stdout
|
13
|
-
logger = ScoutApm::Logger.new("", { :log_file_path => "STDOUT"})
|
14
|
-
assert logger.stdout?
|
15
|
-
assert_equal STDOUT, logger.log_destination
|
16
|
-
|
17
|
-
# and lowercase
|
18
|
-
logger = ScoutApm::Logger.new("", { :log_file_path => "stdout"})
|
19
|
-
assert logger.stdout?
|
20
|
-
assert_equal STDOUT, logger.log_destination
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_force_stdout
|
24
|
-
logger = ScoutApm::Logger.new("", { :stdout => true })
|
25
|
-
assert logger.stdout?
|
26
|
-
assert_equal STDOUT, logger.log_destination
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_pick_log_file_with_no_options
|
30
|
-
logger = ScoutApm::Logger.new(@env_root, { })
|
31
|
-
assert_equal (@env_root + "log" + "scout_apm.log").to_s, logger.log_destination
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_pick_log_file_with_different_dir
|
35
|
-
logger = ScoutApm::Logger.new(@env_root, { :log_file_path => "/tmp" })
|
36
|
-
assert_equal "/tmp/scout_apm.log", logger.log_destination
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_pick_log_file_invalid_dir
|
40
|
-
logger = ScoutApm::Logger.new(@env_root, { :log_file_path => "/not_a_real_dir" })
|
41
|
-
assert_equal STDOUT, logger.log_destination
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_pick_log_dir_not_writable
|
45
|
-
Dir.mktmpdir { |dir|
|
46
|
-
# An unwritable dir
|
47
|
-
FileUtils.chmod(0000, dir)
|
48
|
-
logger = ScoutApm::Logger.new(@env_root, { :log_file_path => dir })
|
49
|
-
assert_equal STDOUT, logger.log_destination
|
50
|
-
|
51
|
-
# so it can be deleted
|
52
|
-
FileUtils.chmod(0700, dir)
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_set_log_level
|
57
|
-
logger = ScoutApm::Logger.new(@env_root, { :log_level => "debug" })
|
58
|
-
assert_equal ::Logger::DEBUG, logger.log_level
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_set_log_level_after
|
62
|
-
logger = ScoutApm::Logger.new(@env_root, { :log_level => "debug" })
|
63
|
-
logger.log_level = "info"
|
64
|
-
assert_equal ::Logger::INFO, logger.log_level
|
65
|
-
|
66
|
-
logger.log_level = ::Logger::ERROR
|
67
|
-
assert_equal ::Logger::ERROR, logger.log_level
|
68
|
-
end
|
69
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class MessageTest < Minitest::Test
|
4
|
-
def test_message_encode_decode_roundtrip
|
5
|
-
message = ScoutApm::Remote::Message.new('type', 'command', ['arg'])
|
6
|
-
encoded = message.encode
|
7
|
-
decoded = ScoutApm::Remote::Message.decode(encoded)
|
8
|
-
assert_equal message.type, decoded.type
|
9
|
-
assert_equal message.command, decoded.command
|
10
|
-
assert_equal message.args, decoded.args
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class RouterTest < Minitest::Test
|
4
|
-
def test_router_handles_record
|
5
|
-
recorder = stub
|
6
|
-
router = ScoutApm::Remote::Router.new(recorder, logger)
|
7
|
-
message = ScoutApm::Remote::Message.new("record", "foo", 1, 2).encode
|
8
|
-
|
9
|
-
recorder.expects(:foo).with(1, 2)
|
10
|
-
|
11
|
-
router.handle(message)
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_router_raises_on_unknown_types
|
15
|
-
recorder = stub
|
16
|
-
router = ScoutApm::Remote::Router.new(recorder, logger)
|
17
|
-
message = ScoutApm::Remote::Message.new("something_else", "foo", 1, 2).encode
|
18
|
-
|
19
|
-
recorder.expects(:foo).never
|
20
|
-
assert_raises do
|
21
|
-
router.handle(message)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def logger
|
26
|
-
@logger ||= Logger.new(logger_io)
|
27
|
-
end
|
28
|
-
|
29
|
-
def logger_io
|
30
|
-
@logger_io ||= StringIO.new
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TestRemoteServer < Minitest::Test
|
4
|
-
def test_start_and_bind
|
5
|
-
bind = "127.0.0.1"
|
6
|
-
port = 8938
|
7
|
-
router = stub(:router)
|
8
|
-
logger_io = StringIO.new
|
9
|
-
server = ScoutApm::Remote::Server.new(bind, port, router, Logger.new(logger_io))
|
10
|
-
|
11
|
-
server.start
|
12
|
-
sleep 0.01 # Let the server finish starting. The assert should instead allow a time
|
13
|
-
assert server.running?
|
14
|
-
end
|
15
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'scout_apm/request_histograms'
|
4
|
-
|
5
|
-
class RequestHistogramsTest < Minitest::Test
|
6
|
-
def test_as_json_without_activesupport
|
7
|
-
rh = ScoutApm::RequestHistograms.new
|
8
|
-
|
9
|
-
rh.add("foo", 1)
|
10
|
-
rh.add("foo", 2)
|
11
|
-
rh.add("bar", 3)
|
12
|
-
|
13
|
-
j = rh.as_json
|
14
|
-
assert_equal 2, j.size
|
15
|
-
assert_equal ["bar", "foo"], j.keys.sort
|
16
|
-
end
|
17
|
-
end
|