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,31 +0,0 @@
|
|
1
|
-
|
2
|
-
class Assignments
|
3
|
-
def test_op_asgn
|
4
|
-
foo.bar += User.size
|
5
|
-
foo.bar -= User.size
|
6
|
-
end
|
7
|
-
|
8
|
-
def nested_assignment
|
9
|
-
@email ||= if (email = session["email"]).present?
|
10
|
-
User.where(email: email).first
|
11
|
-
else
|
12
|
-
nil
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def paginate_collection(coll)
|
17
|
-
page = (params[:page].present? ? params[:page].to_i : 1)
|
18
|
-
per_page = (params[:per_page].present? ? params[:per_page].to_i : 20)
|
19
|
-
pagination, self.collection = pagy(
|
20
|
-
coll,
|
21
|
-
items: per_page,
|
22
|
-
page: page
|
23
|
-
)
|
24
|
-
headers[PAGINATION_TOTAL_HEADER] = pagination.count.to_s
|
25
|
-
headers[PAGINATION_TOTAL_PAGES_HEADER] = pagination.pages.to_s
|
26
|
-
headers[PAGINATION_PER_PAGE_HEADER] = per_page.to_s
|
27
|
-
headers[PAGINATION_PAGE_HEADER] = pagination.page.to_s
|
28
|
-
headers[PAGINATION_NEXT_PAGE_HEADER] = pagination.next.to_s
|
29
|
-
collection
|
30
|
-
end
|
31
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
s(:class,
|
2
|
-
s(:const, nil, :ClientsController),
|
3
|
-
s(:const, nil, :ApplicationController),
|
4
|
-
s(:begin,
|
5
|
-
s(:send, nil, :before_action,
|
6
|
-
s(:sym, :check_authorization)),
|
7
|
-
s(:def, :index,
|
8
|
-
s(:args),
|
9
|
-
s(:if,
|
10
|
-
s(:send,
|
11
|
-
s(:send,
|
12
|
-
s(:send, nil, :params), :[],
|
13
|
-
s(:sym, :status)), :==,
|
14
|
-
s(:str, "activated")),
|
15
|
-
s(:ivasgn, :@clients,
|
16
|
-
s(:send,
|
17
|
-
s(:const, nil, :Client), :activated)),
|
18
|
-
s(:ivasgn, :@clients,
|
19
|
-
s(:send,
|
20
|
-
s(:const, nil, :Client), :inactivated)))),
|
21
|
-
s(:def, :create,
|
22
|
-
s(:args),
|
23
|
-
s(:begin,
|
24
|
-
s(:ivasgn, :@client,
|
25
|
-
s(:send,
|
26
|
-
s(:const, nil, :Client), :new,
|
27
|
-
s(:send,
|
28
|
-
s(:send, nil, :params), :[],
|
29
|
-
s(:sym, :client)))),
|
30
|
-
s(:if,
|
31
|
-
s(:send,
|
32
|
-
s(:ivar, :@client), :save),
|
33
|
-
s(:send, nil, :redirect_to,
|
34
|
-
s(:ivar, :@client)),
|
35
|
-
s(:send, nil, :render,
|
36
|
-
s(:str, "new"))))),
|
37
|
-
s(:def, :edit,
|
38
|
-
s(:args),
|
39
|
-
s(:begin,
|
40
|
-
s(:ivasgn, :@client,
|
41
|
-
s(:send,
|
42
|
-
s(:const, nil, :Client), :new,
|
43
|
-
s(:send,
|
44
|
-
s(:send, nil, :params), :[],
|
45
|
-
s(:sym, :client)))),
|
46
|
-
s(:if,
|
47
|
-
s(:send,
|
48
|
-
s(:send, nil, :request), :post?),
|
49
|
-
s(:block,
|
50
|
-
s(:send,
|
51
|
-
s(:ivar, :@client), :transaction),
|
52
|
-
s(:args),
|
53
|
-
s(:send,
|
54
|
-
s(:ivar, :@client), :update_attributes,
|
55
|
-
s(:send,
|
56
|
-
s(:send, nil, :params), :[],
|
57
|
-
s(:sym, :client)))), nil)))))
|
@@ -1,49 +0,0 @@
|
|
1
|
-
|
2
|
-
class ClientsController < ApplicationController
|
3
|
-
before_action :check_authorization
|
4
|
-
|
5
|
-
def index
|
6
|
-
if ::ScoutApm::AutoInstrument("params[:status] == \"activated\"",["ROOT/test/unit/auto_instrument/controller.rb:6:in `index'"]){params[:status] == "activated"}
|
7
|
-
@clients = ::ScoutApm::AutoInstrument("Client.activated",["ROOT/test/unit/auto_instrument/controller.rb:7:in `index'"]){Client.activated}
|
8
|
-
else
|
9
|
-
@clients = ::ScoutApm::AutoInstrument("Client.inactivated",["ROOT/test/unit/auto_instrument/controller.rb:9:in `index'"]){Client.inactivated}
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def create
|
14
|
-
@client = ::ScoutApm::AutoInstrument("Client.new(params[:client])",["ROOT/test/unit/auto_instrument/controller.rb:14:in `create'"]){Client.new(params[:client])}
|
15
|
-
if ::ScoutApm::AutoInstrument("@client.save",["ROOT/test/unit/auto_instrument/controller.rb:15:in `create'"]){@client.save}
|
16
|
-
::ScoutApm::AutoInstrument("redirect_to @client",["ROOT/test/unit/auto_instrument/controller.rb:16:in `create'"]){redirect_to @client}
|
17
|
-
else
|
18
|
-
# This line overrides the default rendering behavior, which
|
19
|
-
# would have been to render the "create" view.
|
20
|
-
::ScoutApm::AutoInstrument("render \"new\"",["ROOT/test/unit/auto_instrument/controller.rb:20:in `create'"]){render "new"}
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def edit
|
25
|
-
@client = ::ScoutApm::AutoInstrument("Client.new(params[:client])",["ROOT/test/unit/auto_instrument/controller.rb:25:in `edit'"]){Client.new(params[:client])}
|
26
|
-
|
27
|
-
if ::ScoutApm::AutoInstrument("request.post?",["ROOT/test/unit/auto_instrument/controller.rb:27:in `edit'"]){request.post?}
|
28
|
-
::ScoutApm::AutoInstrument("@client.transaction do...",["ROOT/test/unit/auto_instrument/controller.rb:28:in `edit'"]){@client.transaction do
|
29
|
-
@client.update_attributes(params[:client])
|
30
|
-
end}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def data
|
35
|
-
@clients = ::ScoutApm::AutoInstrument("Client.all",["ROOT/test/unit/auto_instrument/controller.rb:35:in `data'"]){Client.all}
|
36
|
-
|
37
|
-
formatter = ::ScoutApm::AutoInstrument("proc do |row|...",["ROOT/test/unit/auto_instrument/controller.rb:37:in `data'"]){proc do |row|
|
38
|
-
row.to_json
|
39
|
-
end}
|
40
|
-
|
41
|
-
::ScoutApm::AutoInstrument("respond_with @clients.each(&formatter).join(\"\\n\"), :content_type => 'application/json; boundary=NL'",["ROOT/test/unit/auto_instrument/controller.rb:41:in `data'"]){respond_with @clients.each(&formatter).join("\n"), :content_type => 'application/json; boundary=NL'}
|
42
|
-
end
|
43
|
-
|
44
|
-
def things
|
45
|
-
x = {}
|
46
|
-
x[:this] ||= 'foo'
|
47
|
-
x[:that] &&= ::ScoutApm::AutoInstrument("'foo'.size",["ROOT/test/unit/auto_instrument/controller.rb:47:in `things'"]){'foo'.size}
|
48
|
-
end
|
49
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
|
2
|
-
class ClientsController < ApplicationController
|
3
|
-
before_action :check_authorization
|
4
|
-
|
5
|
-
def index
|
6
|
-
if params[:status] == "activated"
|
7
|
-
@clients = Client.activated
|
8
|
-
else
|
9
|
-
@clients = Client.inactivated
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def create
|
14
|
-
@client = Client.new(params[:client])
|
15
|
-
if @client.save
|
16
|
-
redirect_to @client
|
17
|
-
else
|
18
|
-
# This line overrides the default rendering behavior, which
|
19
|
-
# would have been to render the "create" view.
|
20
|
-
render "new"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def edit
|
25
|
-
@client = Client.new(params[:client])
|
26
|
-
|
27
|
-
if request.post?
|
28
|
-
@client.transaction do
|
29
|
-
@client.update_attributes(params[:client])
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def data
|
35
|
-
@clients = Client.all
|
36
|
-
|
37
|
-
formatter = proc do |row|
|
38
|
-
row.to_json
|
39
|
-
end
|
40
|
-
|
41
|
-
respond_with @clients.each(&formatter).join("\n"), :content_type => 'application/json; boundary=NL'
|
42
|
-
end
|
43
|
-
|
44
|
-
def things
|
45
|
-
x = {}
|
46
|
-
x[:this] ||= 'foo'
|
47
|
-
x[:that] &&= 'foo'.size
|
48
|
-
end
|
49
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
|
2
|
-
class BrokenController < ApplicationController
|
3
|
-
rescue_from Exception do |e|
|
4
|
-
if e.is_a? Pundit::NotAuthorizedError
|
5
|
-
unauthorized_error
|
6
|
-
elsif e.is_a? ActionController::ParameterMissing
|
7
|
-
error(status: 422, message: e.message)
|
8
|
-
else
|
9
|
-
log_error(e)
|
10
|
-
error message: 'Internal error', exception: e
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
|
2
|
-
class BrokenController < ApplicationController
|
3
|
-
rescue_from Exception do |e|
|
4
|
-
if e.is_a? Pundit::NotAuthorizedError
|
5
|
-
unauthorized_error
|
6
|
-
elsif e.is_a? ActionController::ParameterMissing
|
7
|
-
error(status: 422, message: e.message)
|
8
|
-
else
|
9
|
-
log_error(e)
|
10
|
-
error message: 'Internal error', exception: e
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'scout_apm/auto_instrument'
|
4
|
-
|
5
|
-
class AutoInstrumentTest < Minitest::Test
|
6
|
-
ROOT = File.expand_path("../../", __dir__)
|
7
|
-
|
8
|
-
def source_path(name)
|
9
|
-
File.expand_path("auto_instrument/#{name}.rb", __dir__)
|
10
|
-
end
|
11
|
-
|
12
|
-
def instrumented_path(name)
|
13
|
-
File.expand_path("auto_instrument/#{name}-instrumented.rb", __dir__)
|
14
|
-
end
|
15
|
-
|
16
|
-
def instrumented_source(name)
|
17
|
-
File.read(instrumented_path(name))
|
18
|
-
end
|
19
|
-
|
20
|
-
# Autoinstruments adds a backtrace to each created layer. This is the full path to the
|
21
|
-
# test controller.rb file, which will be different on different environments.
|
22
|
-
# This normalizes backtraces across environments.
|
23
|
-
def normalize_backtrace(string)
|
24
|
-
string.gsub(ROOT, "ROOT")
|
25
|
-
end
|
26
|
-
|
27
|
-
# Use this to automatically update the test fixtures.
|
28
|
-
def update_instrumented_source(name)
|
29
|
-
source = ::ScoutApm::AutoInstrument::Rails.rewrite(source_path(name))
|
30
|
-
source = normalize_backtrace(source)
|
31
|
-
File.write(instrumented_path(name),source)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_controller_rewrite
|
35
|
-
# update_instrumented_source("controller")
|
36
|
-
|
37
|
-
assert_equal instrumented_source("controller"),
|
38
|
-
normalize_backtrace(::ScoutApm::AutoInstrument::Rails.rewrite(source_path("controller")))
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_rescue_from_rewrite
|
42
|
-
# update_instrumented_source("rescue_from")
|
43
|
-
|
44
|
-
assert_equal instrumented_source("rescue_from"),
|
45
|
-
normalize_backtrace(::ScoutApm::AutoInstrument::Rails.rewrite(source_path("rescue_from")))
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_assignments_rewrite
|
49
|
-
# update_instrumented_source("assignments")
|
50
|
-
|
51
|
-
assert_equal instrumented_source("assignments"),
|
52
|
-
normalize_backtrace(::ScoutApm::AutoInstrument::Rails.rewrite(source_path("assignments")))
|
53
|
-
end
|
54
|
-
end if defined? ScoutApm::AutoInstrument
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'scout_apm/db_query_metric_set'
|
4
|
-
|
5
|
-
module ScoutApm
|
6
|
-
class DbQueryMetricSetTest < Minitest::Test
|
7
|
-
def test_hard_limit
|
8
|
-
config = make_fake_config(
|
9
|
-
'database_metric_limit' => 5, # The hard limit on db metrics
|
10
|
-
'database_metric_report_limit' => 2
|
11
|
-
)
|
12
|
-
context = ScoutApm::AgentContext.new().tap{|c| c.config = config }
|
13
|
-
set = DbQueryMetricSet.new(context)
|
14
|
-
|
15
|
-
set << fake_stat("a", 10)
|
16
|
-
set << fake_stat("b", 20)
|
17
|
-
set << fake_stat("c", 30)
|
18
|
-
set << fake_stat("d", 40)
|
19
|
-
set << fake_stat("e", 50)
|
20
|
-
set << fake_stat("f", 60)
|
21
|
-
|
22
|
-
assert_equal 5, set.metrics.size
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_report_limit
|
26
|
-
config = make_fake_config(
|
27
|
-
'database_metric_limit' => 50, # much larger max, uninterested in hitting it.
|
28
|
-
'database_metric_report_limit' => 2
|
29
|
-
)
|
30
|
-
context = ScoutApm::AgentContext.new().tap{|c| c.config = config }
|
31
|
-
set = DbQueryMetricSet.new(context)
|
32
|
-
set << fake_stat("a", 10)
|
33
|
-
set << fake_stat("b", 20)
|
34
|
-
set << fake_stat("c", 30)
|
35
|
-
set << fake_stat("d", 40)
|
36
|
-
set << fake_stat("e", 50)
|
37
|
-
set << fake_stat("f", 60)
|
38
|
-
|
39
|
-
assert_equal 2, set.metrics_to_report.size
|
40
|
-
assert_equal ["f","e"], set.metrics_to_report.map{|m| m.key}
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_combine
|
44
|
-
config = make_fake_config(
|
45
|
-
'database_metric_limit' => 5, # The hard limit on db metrics
|
46
|
-
'database_metric_report_limit' => 2
|
47
|
-
)
|
48
|
-
context = ScoutApm::AgentContext.new().tap{|c| c.config = config }
|
49
|
-
set1 = DbQueryMetricSet.new(context)
|
50
|
-
set1 << fake_stat("a", 10)
|
51
|
-
set1 << fake_stat("b", 20)
|
52
|
-
set2 = DbQueryMetricSet.new(context)
|
53
|
-
set2 << fake_stat("c", 10)
|
54
|
-
set2 << fake_stat("d", 20)
|
55
|
-
|
56
|
-
combined = set1.combine!(set2)
|
57
|
-
assert_equal ["a", "b", "c", "d"], combined.metrics.map{|_k, m| m.key}.sort
|
58
|
-
end
|
59
|
-
|
60
|
-
def fake_stat(key, call_time)
|
61
|
-
OpenStruct.new(
|
62
|
-
:key => key,
|
63
|
-
:call_time => call_time
|
64
|
-
)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'scout_apm/db_query_metric_stats'
|
4
|
-
|
5
|
-
module ScoutApm
|
6
|
-
class DbQueryMetricStatsTest < Minitest::Test
|
7
|
-
def test_as_json_empty_stats
|
8
|
-
stat = build("table", "op", "Controller/public/index", 1, 10, 20)
|
9
|
-
|
10
|
-
assert_equal({
|
11
|
-
:model_name => "table",
|
12
|
-
:operation => "op",
|
13
|
-
:call_count => 1,
|
14
|
-
:transaction_count => 0,
|
15
|
-
:scope => "Controller/public/index",
|
16
|
-
:histogram => [[10.0, 1]],
|
17
|
-
|
18
|
-
:max_call_time => 10.0,
|
19
|
-
:min_call_time => 10.0,
|
20
|
-
:call_time => 10.0,
|
21
|
-
|
22
|
-
:max_rows_returned => 20,
|
23
|
-
:min_rows_returned => 20,
|
24
|
-
:rows_returned => 20,
|
25
|
-
}, stat.as_json)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_increment_transaction_count
|
29
|
-
stat = build()
|
30
|
-
assert_equal 0, stat.transaction_count
|
31
|
-
|
32
|
-
stat.increment_transaction_count!
|
33
|
-
|
34
|
-
assert_equal 1, stat.transaction_count
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_key_name
|
38
|
-
stat = build("User", "find", "Controller/public/index")
|
39
|
-
assert_equal ["User", "find", "Controller/public/index"], stat.key
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_combine_min_call_time_picks_smallest
|
43
|
-
stat1, stat2 = build_pair
|
44
|
-
assert_equal 5.1, stat1.combine!(stat2).min_call_time
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_combine_max_call_time_picks_largest
|
48
|
-
stat1, stat2 = build_pair
|
49
|
-
assert_equal 8.2, stat1.combine!(stat2).max_call_time
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_combine_call_counts_adds
|
53
|
-
stat1, stat2 = build_pair
|
54
|
-
assert_equal 5, stat1.combine!(stat2).call_count
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_combine_transaction_count_adds
|
58
|
-
stat1, stat2 = build_pair
|
59
|
-
2.times { stat1.increment_transaction_count! }
|
60
|
-
3.times { stat2.increment_transaction_count! }
|
61
|
-
|
62
|
-
assert_equal 5, stat1.combine!(stat2).call_count
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_combine_doesnt_merge_with_self
|
66
|
-
stat = build
|
67
|
-
merged = stat.combine!(stat)
|
68
|
-
|
69
|
-
assert_equal DEFAULTS[:call_count], merged.call_count
|
70
|
-
assert_equal DEFAULTS[:call_time], merged.call_time
|
71
|
-
assert_equal DEFAULTS[:rows_returned], merged.rows_returned
|
72
|
-
end
|
73
|
-
|
74
|
-
# A.combine!(B) should be the the same as B.combine!(A)
|
75
|
-
# Have to be a bit careful, since combine! is destructive, so make two pairs
|
76
|
-
# with same data to do both sides, then check that they result in the same
|
77
|
-
# answer
|
78
|
-
[:transaction_count, :call_count, :rows_returned, :min_rows_returned, :max_rows_returned, :max_call_time, :min_call_time].each do |attr|
|
79
|
-
define_method :"test_combine_#{attr}_is_symmetric" do
|
80
|
-
stat1_a, stat2_a = build_pair
|
81
|
-
stat1_b, stat2_b = build_pair
|
82
|
-
merged_a = stat1_a.combine!(stat2_a)
|
83
|
-
merged_b = stat2_b.combine!(stat1_b)
|
84
|
-
|
85
|
-
assert_equal merged_a.send(attr), merged_b.send(attr)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
#############
|
90
|
-
# Helpers #
|
91
|
-
#############
|
92
|
-
DEFAULTS = {
|
93
|
-
:call_count => 1,
|
94
|
-
:call_time => 10.0,
|
95
|
-
:rows_returned => 20,
|
96
|
-
}
|
97
|
-
|
98
|
-
def build(model_name="User",
|
99
|
-
operation="find",
|
100
|
-
scope="Controller/public/index",
|
101
|
-
call_count=DEFAULTS[:call_count],
|
102
|
-
call_time=DEFAULTS[:call_time],
|
103
|
-
rows_returned=DEFAULTS[:rows_returned])
|
104
|
-
DbQueryMetricStats.new(model_name, operation, scope, call_count, call_time, rows_returned)
|
105
|
-
end
|
106
|
-
|
107
|
-
def build_pair
|
108
|
-
stat1 = build("table", "op", "Controller/public/index", 2, 5.1, 10)
|
109
|
-
stat2 = build("table", "op", "Controller/public/index", 3, 8.2, 20)
|
110
|
-
[stat1, stat2]
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class ErrorBufferTest < Minitest::Test
|
4
|
-
class FakeError < StandardError
|
5
|
-
end
|
6
|
-
|
7
|
-
def test_captures_and_stores_exceptions_and_env
|
8
|
-
eb = ScoutApm::ErrorService::ErrorBuffer.new(context)
|
9
|
-
eb.capture(ex, env)
|
10
|
-
end
|
11
|
-
|
12
|
-
#### Helpers
|
13
|
-
|
14
|
-
def context
|
15
|
-
ScoutApm::AgentContext.new
|
16
|
-
end
|
17
|
-
|
18
|
-
def env
|
19
|
-
{}
|
20
|
-
end
|
21
|
-
|
22
|
-
def ex(msg="Whoops")
|
23
|
-
FakeError.new(msg)
|
24
|
-
end
|
25
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class IgnoredExceptionsTest < Minitest::Test
|
4
|
-
class FakeError < StandardError
|
5
|
-
end
|
6
|
-
|
7
|
-
class SubclassFakeError < FakeError
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_ignores_with_string_match
|
11
|
-
ig = ScoutApm::ErrorService::IgnoredExceptions.new(context, ["RuntimeError"])
|
12
|
-
assert ig.ignored?(RuntimeError.new("something went wrong"))
|
13
|
-
assert !ig.ignored?(FakeError.new("something went wrong"))
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_ignores_with_block
|
17
|
-
ig = ScoutApm::ErrorService::IgnoredExceptions.new(context, [])
|
18
|
-
ig.add_callback { |e| e.message == "ignore me" }
|
19
|
-
|
20
|
-
should_ignore = RuntimeError.new("ignore me")
|
21
|
-
should_not_ignore = RuntimeError.new("super legit")
|
22
|
-
|
23
|
-
assert ig.ignored?(should_ignore)
|
24
|
-
assert !ig.ignored?(should_not_ignore)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_ignores_subclasses
|
28
|
-
ig = ScoutApm::ErrorService::IgnoredExceptions.new(context, ["IgnoredExceptionsTest::FakeError"])
|
29
|
-
assert ig.ignored?(SubclassFakeError.new("Subclass"))
|
30
|
-
end
|
31
|
-
|
32
|
-
# Check that a bad exception in the list doesn't stop the whole thing from working
|
33
|
-
def test_does_not_consider_unknown_errors
|
34
|
-
ig = ScoutApm::ErrorService::IgnoredExceptions.new(context, ["ThisDoesNotExist", "IgnoredExceptionsTest::FakeError"])
|
35
|
-
assert ig.ignored?(FakeError.new("ignore this one"))
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_add_module
|
39
|
-
ig = ScoutApm::ErrorService::IgnoredExceptions.new(context, [])
|
40
|
-
ig.add(IgnoredExceptionsTest::FakeError)
|
41
|
-
assert ig.ignored?(FakeError.new("ignore this one"))
|
42
|
-
end
|
43
|
-
|
44
|
-
#### Helpers
|
45
|
-
|
46
|
-
def context
|
47
|
-
ScoutApm::AgentContext.new
|
48
|
-
end
|
49
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class PeriodicCallbacksTest < Minitest::Test
|
4
|
-
|
5
|
-
# We don't have a test that ensures we actually report data to the server, so we can't be 100% sure this doesn't break
|
6
|
-
# reporting.
|
7
|
-
def test_broken_callback_does_not_throw_exception
|
8
|
-
ScoutApm::Extensions::Config.add_periodic_callback(BrokenCallback.new)
|
9
|
-
# Runs via agent context as calling +add_periodic_callback+ initializing the context + extension config.
|
10
|
-
ScoutApm::Agent.instance.context.extensions.run_periodic_callbacks(reporting_period,metadata)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_callback_runs
|
14
|
-
Thread.current[:periodic_callback_output] = nil
|
15
|
-
ScoutApm::Extensions::Config.add_periodic_callback(PeriodicCallback.new)
|
16
|
-
ScoutApm::Agent.instance.context.extensions.run_periodic_callbacks(reporting_period,metadata)
|
17
|
-
assert Thread.current[:periodic_callback_output]
|
18
|
-
end
|
19
|
-
|
20
|
-
def run_proc_callback
|
21
|
-
Thread.current[:proc_periodic] = nil
|
22
|
-
ScoutApm::Extensions::Config.add_periodic_callback(Proc.new { |reporting_period, metadata| Thread.current[:proc_periodic] = Time.at(metadata[:agent_time].to_i) })
|
23
|
-
ScoutApm::Agent.instance.context.extensions.run_periodic_callbacks(reporting_period,metadata)
|
24
|
-
assert Thread.current[:proc_periodic]
|
25
|
-
end
|
26
|
-
|
27
|
-
# Doesn't respond to +call+.
|
28
|
-
class BrokenCallback
|
29
|
-
end
|
30
|
-
|
31
|
-
# Sets a Thread local so we can verify that the callback ran.
|
32
|
-
class PeriodicCallback
|
33
|
-
def call(reporting_period,metadata)
|
34
|
-
Thread.current[:periodic_callback_output] = true
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def reporting_period
|
41
|
-
rp = ScoutApm::StoreReportingPeriod.new(Time.at(metadata[:agent_time].to_i), ScoutApm::AgentContext.new)
|
42
|
-
rp.absorb_metrics!(metrics)
|
43
|
-
end
|
44
|
-
|
45
|
-
def metrics
|
46
|
-
meta = ScoutApm::MetricMeta.new("Controller/users/index")
|
47
|
-
stats = ScoutApm::MetricStats.new
|
48
|
-
stats.update!(0.1)
|
49
|
-
{
|
50
|
-
meta => stats
|
51
|
-
}
|
52
|
-
end
|
53
|
-
|
54
|
-
def metadata
|
55
|
-
{:app_root=>"/srv/rails_app", :unique_id=>"ID", :agent_version=>"2.4.10", :agent_time=>"1523287920", :agent_pid=>21581, :platform=>"ruby"}
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class TransactionCallbacksTest < Minitest::Test
|
4
|
-
|
5
|
-
def setup
|
6
|
-
# Another test could set the recorder to +FakeRecorder+, which does not call +TrackedRequest#record!+.
|
7
|
-
ScoutApm::Agent.instance.context.recorder = ScoutApm::RecorderFactory.build(ScoutApm::Agent.instance.context)
|
8
|
-
end
|
9
|
-
|
10
|
-
# This is more of an integration test to ensure that we don't break TrackedRequest.
|
11
|
-
def test_broken_callback_does_not_break_tracked_request
|
12
|
-
ScoutApm::Extensions::Config.add_transaction_callback(BrokenCallback.new)
|
13
|
-
|
14
|
-
controller_layer = ScoutApm::Layer.new("Controller", "users/index")
|
15
|
-
# why doesn't this run? check if callbacks are configured
|
16
|
-
tr = ScoutApm::TrackedRequest.new(ScoutApm::Agent.instance.context, ScoutApm::FakeStore.new)
|
17
|
-
tr.start_layer(controller_layer)
|
18
|
-
tr.stop_layer
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_callback_runs
|
22
|
-
Thread.current[:transaction_callback_output] = nil
|
23
|
-
ScoutApm::Extensions::Config.add_transaction_callback(TransactionCallback.new)
|
24
|
-
|
25
|
-
controller_layer = ScoutApm::Layer.new("Controller", "users/index")
|
26
|
-
|
27
|
-
tr = ScoutApm::TrackedRequest.new(ScoutApm::Agent.instance.context, ScoutApm::FakeStore.new)
|
28
|
-
tr.start_layer(controller_layer)
|
29
|
-
tr.stop_layer
|
30
|
-
|
31
|
-
assert Thread.current[:transaction_callback_output]
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_run_proc_callback
|
35
|
-
Thread.current[:proc_transaction_duration] = nil
|
36
|
-
ScoutApm::Extensions::Config.add_transaction_callback(Proc.new { |payload| Thread.current[:proc_transaction_duration] = payload.duration_ms })
|
37
|
-
|
38
|
-
controller_layer = ScoutApm::Layer.new("Controller", "users/index")
|
39
|
-
|
40
|
-
tr = ScoutApm::TrackedRequest.new(ScoutApm::Agent.instance.context, ScoutApm::FakeStore.new)
|
41
|
-
tr.start_layer(controller_layer)
|
42
|
-
tr.stop_layer
|
43
|
-
|
44
|
-
assert Thread.current[:proc_transaction_duration]
|
45
|
-
end
|
46
|
-
|
47
|
-
# Doesn't respond to +call+.
|
48
|
-
class BrokenCallback
|
49
|
-
end
|
50
|
-
|
51
|
-
# Sets a Thread local so we can verify that the callback ran.
|
52
|
-
class TransactionCallback
|
53
|
-
def call(payload)
|
54
|
-
Thread.current[:transaction_callback_output] = true
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
require 'scout_apm/git_revision'
|
4
|
-
|
5
|
-
class GitRevisionTest < Minitest::Test
|
6
|
-
# TODO - other tests that would be nice:
|
7
|
-
# * ensure we only detect once, on initialize.
|
8
|
-
# * tests for reading cap files
|
9
|
-
|
10
|
-
def test_sha_from_heroku
|
11
|
-
ENV['HEROKU_SLUG_COMMIT'] = 'heroku_slug'
|
12
|
-
revision = ScoutApm::GitRevision.new(ScoutApm::AgentContext.new)
|
13
|
-
assert_equal 'heroku_slug', revision.sha
|
14
|
-
end
|
15
|
-
end
|