appoptics_apm 4.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (226) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +43 -0
  3. data/.dockerignore +5 -0
  4. data/.gitignore +23 -0
  5. data/.rubocop.yml +5 -0
  6. data/.travis.yml +82 -0
  7. data/CHANGELOG.md +769 -0
  8. data/CONFIG.md +33 -0
  9. data/Dockerfile +41 -0
  10. data/Dockerfile_test +66 -0
  11. data/Gemfile +41 -0
  12. data/LICENSE +193 -0
  13. data/README.md +351 -0
  14. data/Rakefile +202 -0
  15. data/Vagrantfile +67 -0
  16. data/appoptics_apm.gemspec +55 -0
  17. data/build_gems.sh +15 -0
  18. data/docker-compose.yml +73 -0
  19. data/examples/DNT.md +35 -0
  20. data/examples/carrying_context.rb +220 -0
  21. data/examples/instrumenting_metal_controller.rb +8 -0
  22. data/examples/puma_on_heroku_config.rb +17 -0
  23. data/examples/tracing_async_threads.rb +124 -0
  24. data/examples/tracing_background_jobs.rb +53 -0
  25. data/examples/tracing_forked_processes.rb +99 -0
  26. data/examples/unicorn_on_heroku_config.rb +28 -0
  27. data/ext/oboe_metal/extconf.rb +54 -0
  28. data/ext/oboe_metal/lib/.keep +0 -0
  29. data/ext/oboe_metal/lib/liboboe-1.0.so.0.0.0 +0 -0
  30. data/ext/oboe_metal/noop/noop.c +7 -0
  31. data/ext/oboe_metal/src/VERSION +1 -0
  32. data/ext/oboe_metal/src/bson/bson.h +221 -0
  33. data/ext/oboe_metal/src/bson/platform_hacks.h +91 -0
  34. data/ext/oboe_metal/src/oboe.h +883 -0
  35. data/ext/oboe_metal/src/oboe.hpp +793 -0
  36. data/ext/oboe_metal/src/oboe_debug.h +50 -0
  37. data/ext/oboe_metal/src/oboe_wrap.cxx +6088 -0
  38. data/ext/oboe_metal/tests/test.rb +11 -0
  39. data/gemfiles/delayed_job.gemfile +36 -0
  40. data/gemfiles/frameworks.gemfile +44 -0
  41. data/gemfiles/instrumentation_mocked.gemfile +29 -0
  42. data/gemfiles/libraries.gemfile +85 -0
  43. data/gemfiles/rails23.gemfile +39 -0
  44. data/gemfiles/rails30.gemfile +42 -0
  45. data/gemfiles/rails31.gemfile +44 -0
  46. data/gemfiles/rails32.gemfile +54 -0
  47. data/gemfiles/rails40.gemfile +27 -0
  48. data/gemfiles/rails41.gemfile +27 -0
  49. data/gemfiles/rails42.gemfile +35 -0
  50. data/gemfiles/rails50.gemfile +44 -0
  51. data/gemfiles/rails51.gemfile +44 -0
  52. data/get_version.rb +5 -0
  53. data/init.rb +4 -0
  54. data/lib/appoptics_apm/api/layerinit.rb +39 -0
  55. data/lib/appoptics_apm/api/logging.rb +359 -0
  56. data/lib/appoptics_apm/api/memcache.rb +34 -0
  57. data/lib/appoptics_apm/api/profiling.rb +201 -0
  58. data/lib/appoptics_apm/api/tracing.rb +152 -0
  59. data/lib/appoptics_apm/api/util.rb +128 -0
  60. data/lib/appoptics_apm/api.rb +18 -0
  61. data/lib/appoptics_apm/base.rb +252 -0
  62. data/lib/appoptics_apm/config.rb +281 -0
  63. data/lib/appoptics_apm/frameworks/grape.rb +93 -0
  64. data/lib/appoptics_apm/frameworks/padrino/templates.rb +58 -0
  65. data/lib/appoptics_apm/frameworks/padrino.rb +52 -0
  66. data/lib/appoptics_apm/frameworks/rails/inst/action_controller.rb +106 -0
  67. data/lib/appoptics_apm/frameworks/rails/inst/action_controller2.rb +61 -0
  68. data/lib/appoptics_apm/frameworks/rails/inst/action_controller3.rb +58 -0
  69. data/lib/appoptics_apm/frameworks/rails/inst/action_controller4.rb +48 -0
  70. data/lib/appoptics_apm/frameworks/rails/inst/action_controller5.rb +50 -0
  71. data/lib/appoptics_apm/frameworks/rails/inst/action_controller_api.rb +50 -0
  72. data/lib/appoptics_apm/frameworks/rails/inst/action_view.rb +58 -0
  73. data/lib/appoptics_apm/frameworks/rails/inst/action_view_2x.rb +56 -0
  74. data/lib/appoptics_apm/frameworks/rails/inst/action_view_30.rb +50 -0
  75. data/lib/appoptics_apm/frameworks/rails/inst/active_record.rb +27 -0
  76. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/mysql.rb +43 -0
  77. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/mysql2.rb +28 -0
  78. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/postgresql.rb +30 -0
  79. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils.rb +120 -0
  80. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils5x.rb +101 -0
  81. data/lib/appoptics_apm/frameworks/rails.rb +116 -0
  82. data/lib/appoptics_apm/frameworks/sinatra/templates.rb +56 -0
  83. data/lib/appoptics_apm/frameworks/sinatra.rb +71 -0
  84. data/lib/appoptics_apm/inst/bunny-client.rb +148 -0
  85. data/lib/appoptics_apm/inst/bunny-consumer.rb +92 -0
  86. data/lib/appoptics_apm/inst/curb.rb +329 -0
  87. data/lib/appoptics_apm/inst/dalli.rb +85 -0
  88. data/lib/appoptics_apm/inst/delayed_job.rb +92 -0
  89. data/lib/appoptics_apm/inst/em-http-request.rb +105 -0
  90. data/lib/appoptics_apm/inst/excon.rb +130 -0
  91. data/lib/appoptics_apm/inst/faraday.rb +77 -0
  92. data/lib/appoptics_apm/inst/http.rb +83 -0
  93. data/lib/appoptics_apm/inst/httpclient.rb +176 -0
  94. data/lib/appoptics_apm/inst/memcache.rb +102 -0
  95. data/lib/appoptics_apm/inst/memcached.rb +94 -0
  96. data/lib/appoptics_apm/inst/mongo.rb +242 -0
  97. data/lib/appoptics_apm/inst/mongo2.rb +225 -0
  98. data/lib/appoptics_apm/inst/moped.rb +466 -0
  99. data/lib/appoptics_apm/inst/rack.rb +146 -0
  100. data/lib/appoptics_apm/inst/redis.rb +275 -0
  101. data/lib/appoptics_apm/inst/resque.rb +151 -0
  102. data/lib/appoptics_apm/inst/rest-client.rb +50 -0
  103. data/lib/appoptics_apm/inst/sequel.rb +178 -0
  104. data/lib/appoptics_apm/inst/sidekiq-client.rb +53 -0
  105. data/lib/appoptics_apm/inst/sidekiq-worker.rb +67 -0
  106. data/lib/appoptics_apm/inst/twitter-cassandra.rb +294 -0
  107. data/lib/appoptics_apm/inst/typhoeus.rb +113 -0
  108. data/lib/appoptics_apm/instrumentation.rb +22 -0
  109. data/lib/appoptics_apm/legacy_method_profiling.rb +97 -0
  110. data/lib/appoptics_apm/loading.rb +66 -0
  111. data/lib/appoptics_apm/logger.rb +41 -0
  112. data/lib/appoptics_apm/method_profiling.rb +33 -0
  113. data/lib/appoptics_apm/ruby.rb +35 -0
  114. data/lib/appoptics_apm/support.rb +135 -0
  115. data/lib/appoptics_apm/test.rb +94 -0
  116. data/lib/appoptics_apm/thread_local.rb +26 -0
  117. data/lib/appoptics_apm/util.rb +312 -0
  118. data/lib/appoptics_apm/version.rb +15 -0
  119. data/lib/appoptics_apm/xtrace.rb +103 -0
  120. data/lib/appoptics_apm.rb +72 -0
  121. data/lib/joboe_metal.rb +214 -0
  122. data/lib/oboe/README +2 -0
  123. data/lib/oboe/backward_compatibility.rb +80 -0
  124. data/lib/oboe/inst/rack.rb +11 -0
  125. data/lib/oboe.rb +7 -0
  126. data/lib/oboe_metal.rb +187 -0
  127. data/lib/rails/generators/appoptics_apm/install_generator.rb +45 -0
  128. data/lib/rails/generators/appoptics_apm/templates/appoptics_apm_initializer.rb +222 -0
  129. data/ruby_setup.sh +47 -0
  130. data/run_docker_build_gem_upload_to_packagecloud.sh +20 -0
  131. data/run_tests_docker.rb +32 -0
  132. data/test/benchmark/README.md +65 -0
  133. data/test/benchmark/logging_bench.rb +54 -0
  134. data/test/benchmark/with_libraries_gemfile/bunny_bench.rb +69 -0
  135. data/test/benchmark/with_rails5x_gemfile/action_controller5x_bench.rb +43 -0
  136. data/test/frameworks/apps/grape_nested.rb +33 -0
  137. data/test/frameworks/apps/grape_simple.rb +80 -0
  138. data/test/frameworks/apps/padrino_simple.rb +80 -0
  139. data/test/frameworks/apps/sinatra_simple.rb +55 -0
  140. data/test/frameworks/grape_test.rb +286 -0
  141. data/test/frameworks/padrino_test.rb +222 -0
  142. data/test/frameworks/rails3x_test.rb +554 -0
  143. data/test/frameworks/rails4x_test.rb +570 -0
  144. data/test/frameworks/rails5x_api_test.rb +210 -0
  145. data/test/frameworks/rails5x_test.rb +376 -0
  146. data/test/frameworks/rails_shared_tests.rb +172 -0
  147. data/test/frameworks/sinatra_test.rb +140 -0
  148. data/test/instrumentation/bunny_client_test.rb +276 -0
  149. data/test/instrumentation/bunny_consumer_test.rb +204 -0
  150. data/test/instrumentation/curb_test.rb +398 -0
  151. data/test/instrumentation/dalli_test.rb +177 -0
  152. data/test/instrumentation/em_http_request_test.rb +89 -0
  153. data/test/instrumentation/excon_test.rb +231 -0
  154. data/test/instrumentation/faraday_test.rb +228 -0
  155. data/test/instrumentation/http_test.rb +143 -0
  156. data/test/instrumentation/httpclient_test.rb +320 -0
  157. data/test/instrumentation/memcache_test.rb +260 -0
  158. data/test/instrumentation/memcached_test.rb +229 -0
  159. data/test/instrumentation/mongo_v1_test.rb +479 -0
  160. data/test/instrumentation/mongo_v2_index_test.rb +124 -0
  161. data/test/instrumentation/mongo_v2_test.rb +584 -0
  162. data/test/instrumentation/mongo_v2_view_test.rb +435 -0
  163. data/test/instrumentation/moped_test.rb +517 -0
  164. data/test/instrumentation/rack_test.rb +165 -0
  165. data/test/instrumentation/redis_hashes_test.rb +268 -0
  166. data/test/instrumentation/redis_keys_test.rb +321 -0
  167. data/test/instrumentation/redis_lists_test.rb +310 -0
  168. data/test/instrumentation/redis_misc_test.rb +163 -0
  169. data/test/instrumentation/redis_sets_test.rb +296 -0
  170. data/test/instrumentation/redis_sortedsets_test.rb +328 -0
  171. data/test/instrumentation/redis_strings_test.rb +349 -0
  172. data/test/instrumentation/resque_test.rb +185 -0
  173. data/test/instrumentation/rest-client_test.rb +288 -0
  174. data/test/instrumentation/sequel_mysql2_test.rb +353 -0
  175. data/test/instrumentation/sequel_mysql_test.rb +334 -0
  176. data/test/instrumentation/sequel_pg_test.rb +336 -0
  177. data/test/instrumentation/sidekiq-client_test.rb +159 -0
  178. data/test/instrumentation/sidekiq-worker_test.rb +180 -0
  179. data/test/instrumentation/twitter-cassandra_test.rb +424 -0
  180. data/test/instrumentation/typhoeus_test.rb +284 -0
  181. data/test/jobs/delayed_job/db_worker_job.rb +29 -0
  182. data/test/jobs/delayed_job/error_worker_job.rb +10 -0
  183. data/test/jobs/delayed_job/remote_call_worker_job.rb +20 -0
  184. data/test/jobs/resque/db_worker_job.rb +29 -0
  185. data/test/jobs/resque/error_worker_job.rb +10 -0
  186. data/test/jobs/resque/remote_call_worker_job.rb +20 -0
  187. data/test/jobs/sidekiq/db_worker_job.rb +29 -0
  188. data/test/jobs/sidekiq/error_worker_job.rb +10 -0
  189. data/test/jobs/sidekiq/remote_call_worker_job.rb +20 -0
  190. data/test/minitest_helper.rb +276 -0
  191. data/test/mocked/curb_mocked_test.rb +311 -0
  192. data/test/mocked/excon_mocked_test.rb +166 -0
  193. data/test/mocked/faraday_mocked_test.rb +93 -0
  194. data/test/mocked/http_mocked_test.rb +129 -0
  195. data/test/mocked/httpclient_mocked_test.rb +245 -0
  196. data/test/mocked/rest_client_mocked_test.rb +103 -0
  197. data/test/mocked/typhoeus_mocked_test.rb +192 -0
  198. data/test/models/widget.rb +36 -0
  199. data/test/profiling/legacy_method_profiling_test.rb +201 -0
  200. data/test/profiling/method_profiling_test.rb +631 -0
  201. data/test/queues/delayed_job-client_test.rb +95 -0
  202. data/test/queues/delayed_job-worker_test.rb +91 -0
  203. data/test/reporter/reporter_test.rb +14 -0
  204. data/test/servers/delayed_job.rb +107 -0
  205. data/test/servers/rackapp_8101.rb +29 -0
  206. data/test/servers/rails3x_8140.rb +96 -0
  207. data/test/servers/rails4x_8140.rb +96 -0
  208. data/test/servers/rails5x_8140.rb +95 -0
  209. data/test/servers/rails5x_api_8150.rb +78 -0
  210. data/test/servers/sidekiq.rb +29 -0
  211. data/test/servers/sidekiq.yml +7 -0
  212. data/test/servers/sidekiq_initializer.rb +25 -0
  213. data/test/settings +0 -0
  214. data/test/support/auto_tracing_test.rb +50 -0
  215. data/test/support/backcompat_test.rb +276 -0
  216. data/test/support/config_test.rb +149 -0
  217. data/test/support/dnt_test.rb +98 -0
  218. data/test/support/init_report_test.rb +25 -0
  219. data/test/support/liboboe_settings_test.rb +110 -0
  220. data/test/support/logging_test.rb +130 -0
  221. data/test/support/noop_test.rb +88 -0
  222. data/test/support/sql_sanitize_test.rb +55 -0
  223. data/test/support/tracing_mode_test.rb +33 -0
  224. data/test/support/tvalias_test.rb +15 -0
  225. data/test/support/xtrace_test.rb +41 -0
  226. metadata +475 -0
@@ -0,0 +1,95 @@
1
+ # Copyright (c) 2016 SolarWinds, LLC.
2
+ # All rights reserved.
3
+
4
+ require 'minitest_helper'
5
+ require_relative "../jobs/delayed_job/remote_call_worker_job"
6
+ require_relative "../jobs/delayed_job/db_worker_job"
7
+ require_relative "../jobs/delayed_job/error_worker_job"
8
+ require_relative '../models/widget'
9
+
10
+ # Delete all pre-existing jobs before we start
11
+ Delayed::Job.delete_all
12
+
13
+ class DelayedJobClientTest < Minitest::Test
14
+ def setup
15
+ clear_all_traces
16
+ @collect_backtraces = AppOpticsAPM::Config[:delayed_jobclient][:collect_backtraces]
17
+ @log_args = AppOpticsAPM::Config[:delayed_jobclient][:log_args]
18
+ end
19
+
20
+ def teardown
21
+ AppOpticsAPM::Config[:delayed_jobclient][:collect_backtraces] = @collect_backtraces
22
+ AppOpticsAPM::Config[:delayed_jobclient][:log_args] = @log_args
23
+ end
24
+
25
+ def test_delay
26
+ w = Widget.new(:name => 'blah', :description => 'This is a wonderful widget.')
27
+ w.save
28
+
29
+ AppOpticsAPM::API.start_trace('dj_delay') do
30
+ w.delay.do_work(1, 2, 3)
31
+ end
32
+
33
+ sleep 15
34
+
35
+ traces = get_all_traces
36
+ assert valid_edges?(traces), "Invalid edge in traces"
37
+
38
+ assert_equal 'dj_delay', traces[0]['Layer']
39
+ assert_equal 'entry', traces[0]['Label']
40
+ assert_equal 'delayed_job-client', traces[1]['Layer']
41
+ assert_equal 'entry', traces[1]['Label']
42
+ assert_equal 'pushq', traces[1]['Spec']
43
+ assert_equal 'DelayedJob', traces[1]['Flavor']
44
+ assert_equal 'Widget#do_work', traces[1]['JobName']
45
+ assert_equal 'delayed_job-client', traces[2]['Layer']
46
+ assert_equal 'exit', traces[2]['Label']
47
+ assert_equal 'dj_delay', traces[3]['Layer']
48
+ assert_equal 'exit', traces[3]['Label']
49
+
50
+ end
51
+
52
+ def test_collect_backtraces_default_value
53
+ assert_equal AppOpticsAPM::Config[:delayed_jobclient][:collect_backtraces], false, "default backtrace collection"
54
+ end
55
+
56
+ def test_log_args_default_value
57
+ assert_equal AppOpticsAPM::Config[:delayed_jobclient][:log_args], true, "log_args default "
58
+ end
59
+
60
+ def test_obey_collect_backtraces_when_false
61
+ AppOpticsAPM::Config[:delayed_jobclient][:collect_backtraces] = false
62
+
63
+ w = Widget.new(:name => 'blah', :description => 'This is a wonderful widget.')
64
+ w.save
65
+
66
+ AppOpticsAPM::API.start_trace('dj_delay') do
67
+ w.delay.do_work(1, 2, 3)
68
+ end
69
+
70
+ traces = get_all_traces
71
+ assert valid_edges?(traces), "Invalid edge in traces"
72
+
73
+ assert_equal 'delayed_job-client', traces[1]['Layer']
74
+ assert_equal 'entry', traces[1]['Label']
75
+ assert_equal false, traces[1].key?('Backtrace')
76
+ end
77
+
78
+ def test_obey_collect_backtraces_when_true
79
+ AppOpticsAPM::Config[:delayed_jobclient][:collect_backtraces] = true
80
+
81
+ w = Widget.new(:name => 'blah', :description => 'This is a wonderful widget.')
82
+ w.save
83
+
84
+ AppOpticsAPM::API.start_trace('dj_delay') do
85
+ w.delay.do_work(1, 2, 3)
86
+ end
87
+
88
+ traces = get_all_traces
89
+ assert valid_edges?(traces), "Invalid edge in traces"
90
+
91
+ assert_equal 'delayed_job-client', traces[1]['Layer']
92
+ assert_equal 'entry', traces[1]['Label']
93
+ assert_equal true, traces[1].key?('Backtrace')
94
+ end
95
+ end
@@ -0,0 +1,91 @@
1
+ # Copyright (c) 2016 SolarWinds, LLC.
2
+ # All rights reserved.
3
+
4
+ require 'minitest_helper'
5
+ require_relative '../jobs/delayed_job/remote_call_worker_job'
6
+ require_relative '../jobs/delayed_job/db_worker_job'
7
+ require_relative '../jobs/delayed_job/error_worker_job'
8
+ require_relative '../models/widget'
9
+
10
+ class DelayedJobWorkerTest < Minitest::Test
11
+ def setup
12
+ # Delete all pre-existing jobs before we start
13
+ Delayed::Job.delete_all
14
+
15
+ clear_all_traces
16
+ @collect_backtraces = AppOpticsAPM::Config[:delayed_jobworker][:collect_backtraces]
17
+ @log_args = AppOpticsAPM::Config[:delayed_jobworker][:log_args]
18
+ end
19
+
20
+ def teardown
21
+ AppOpticsAPM::Config[:delayed_jobworker][:collect_backtraces] = @collect_backtraces
22
+ AppOpticsAPM::Config[:delayed_jobworker][:log_args] = @log_args
23
+ end
24
+
25
+ def test_reports_version_init
26
+ init_kvs = ::AppOpticsAPM::Util.build_init_report
27
+ assert init_kvs.key?('Ruby.delayed_job.Version')
28
+ assert_equal Gem.loaded_specs['delayed_job'].version.to_s, init_kvs['Ruby.delayed_job.Version']
29
+ end
30
+
31
+ def test_job_run
32
+ w = Widget.new(:name => 'blah', :description => 'This is a wonderful wonderful widget.')
33
+ w.save
34
+
35
+ w.delay.do_work(1, 2, 3)
36
+
37
+ sleep 15
38
+
39
+ traces = get_all_traces
40
+ assert_equal 2, traces.count, "Trace count"
41
+ assert valid_edges?(traces), "Invalid edge in traces"
42
+
43
+ assert_equal 'delayed_job-worker', traces[0]['Layer']
44
+ assert_equal 'entry', traces[0]['Label']
45
+ assert_equal 'job', traces[0]['Spec']
46
+ assert_equal 'DelayedJob', traces[0]['Flavor']
47
+ assert_equal 'Widget#do_work', traces[0]['JobName']
48
+ assert_equal 0, traces[0]['priority']
49
+ assert_equal 0, traces[0]['attempts']
50
+ assert traces[0].key?('WorkerName'), "Worker Name"
51
+ assert traces[0].key?('SampleRate')
52
+ assert traces[0].key?('SampleSource')
53
+ assert_equal false, traces[0].key?('Backtrace')
54
+
55
+ assert_equal 'delayed_job-worker', traces[1]['Layer']
56
+ assert_equal 'exit', traces[1]['Label']
57
+ end
58
+
59
+ def test_jobs_with_errors
60
+ w = Widget.new(:name => 'blah', :description => 'This is a wonderful wonderful widget.')
61
+ w.save
62
+
63
+ w.delay.do_error(1, 2, 3)
64
+
65
+ sleep 15
66
+
67
+ traces = get_all_traces
68
+ assert_equal 3, traces.count, "Trace count"
69
+ assert valid_edges?(traces), "Invalid edge in traces"
70
+
71
+ assert_equal 'delayed_job-worker', traces[0]['Layer']
72
+ assert_equal 'entry', traces[0]['Label']
73
+
74
+ assert_equal 'error', traces[1]['Label']
75
+ assert_equal 'FakeTestError', traces[1]['ErrorMsg']
76
+ assert traces[1].key?('Backtrace')
77
+ assert traces[1].key?('ErrorClass')
78
+
79
+ assert_equal 'delayed_job-worker', traces[2]['Layer']
80
+ assert_equal 'exit', traces[2]['Label']
81
+
82
+ end
83
+
84
+ def test_collect_backtraces_default_value
85
+ assert_equal AppOpticsAPM::Config[:delayed_jobworker][:collect_backtraces], false, "default backtrace collection"
86
+ end
87
+
88
+ def test_log_args_default_value
89
+ assert_equal AppOpticsAPM::Config[:delayed_jobworker][:log_args], true, "log_args default "
90
+ end
91
+ end
@@ -0,0 +1,14 @@
1
+ # Copyright (c) 2016 SolarWinds, LLC.
2
+ # All rights reserved.
3
+
4
+ require 'minitest_helper'
5
+
6
+ class APPOPTICSReporterTest < Minitest::Test
7
+ def reporter_has_start_method
8
+ assert_equal true, AppOpticsAPM::Reporter.respond_to?(:start), "has restart method"
9
+ end
10
+
11
+ def reporter_has_restart_method
12
+ assert_equal true, AppOpticsAPM::Reporter.respond_to?(:restart), "has start method"
13
+ end
14
+ end
@@ -0,0 +1,107 @@
1
+ # Copyright (c) 2016 SolarWinds, LLC.
2
+ # All rights reserved.
3
+
4
+ # This is a Rails app that launches a DelayedJob worker
5
+ # in a background thread.
6
+ #
7
+ require "rails/all"
8
+ require "delayed_job"
9
+ require "action_controller/railtie"
10
+ require 'rack/handler/puma'
11
+ require File.expand_path(File.dirname(__FILE__) + '/../models/widget')
12
+
13
+ AppOpticsAPM.logger.level = Logger::DEBUG
14
+ AppOpticsAPM.logger.info "[appoptics_apm/info] Starting background utility rails app on localhost:8140."
15
+
16
+ AppOpticsAPM::Test.set_postgresql_env
17
+
18
+ ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
19
+
20
+ unless ActiveRecord::Base.connection.table_exists? :delayed_jobs
21
+ AppOpticsAPM.logger.info "[appoptics_apm/servers] Creating DelayedJob DB table."
22
+
23
+ dj_dir = Gem::Specification.find_by_name('delayed_job_active_record').gem_dir
24
+ template = File.open(File.join(dj_dir, "lib/generators/delayed_job/templates/migration.rb"))
25
+
26
+ migration_context = Class.new do
27
+ def get_binding
28
+ binding
29
+ end
30
+
31
+ private
32
+
33
+ def migration_version
34
+ if ActiveRecord::VERSION::MAJOR >= 5
35
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
36
+ end
37
+ end
38
+ end
39
+ migration_ruby = ERB.new(template.read).result(migration_context.new.get_binding)
40
+ eval migration_ruby
41
+
42
+ ActiveRecord::Migration.run(CreateDelayedJobs)
43
+ end
44
+
45
+ unless ActiveRecord::Base.connection.table_exists? 'widgets'
46
+ ActiveRecord::Migration.run(CreateWidgets)
47
+ end
48
+
49
+ class Rails40MetalStack < Rails::Application
50
+ routes.append do
51
+ get "/hello/world" => "hello#world"
52
+ get "/hello/metal" => "ferro#world"
53
+ end
54
+
55
+ config.cache_classes = true
56
+ config.eager_load = false
57
+ config.active_support.deprecation = :stderr
58
+ config.middleware.delete "Rack::Lock"
59
+ config.middleware.delete "ActionDispatch::Flash"
60
+ config.middleware.delete "ActionDispatch::BestStandardsSupport"
61
+ config.secret_token = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
62
+ config.secret_key_base = "2048671-96803948"
63
+ end
64
+
65
+ #################################################
66
+ # Controllers
67
+ #################################################
68
+
69
+ class HelloController < ActionController::Base
70
+ def world
71
+ render :text => "Hello world!"
72
+ end
73
+ end
74
+
75
+ class FerroController < ActionController::Metal
76
+ include AbstractController::Rendering
77
+
78
+ def world
79
+ render :text => "Hello world!"
80
+ end
81
+ end
82
+
83
+ Delayed::Job.delete_all
84
+
85
+ @worker_options = {
86
+ :min_priority => ENV['MIN_PRIORITY'],
87
+ :max_priority => ENV['MAX_PRIORITY'],
88
+ :queues => (ENV['QUEUES'] || ENV['QUEUE'] || '').split(','),
89
+ :quiet => ENV['QUIET']
90
+ }
91
+
92
+ @worker_options[:sleep_delay] = ENV['SLEEP_DELAY'].to_i if ENV['SLEEP_DELAY']
93
+ @worker_options[:read_ahead] = ENV['READ_AHEAD'].to_i if ENV['READ_AHEAD']
94
+
95
+ AppOpticsAPM.logger.info "[appoptics_apm/servers] Starting up background DelayedJob."
96
+
97
+ #Delayed::Worker.delay_jobs = false
98
+ Delayed::Worker.max_attempts = 1
99
+ Delayed::Worker.sleep_delay = 10
100
+
101
+ Thread.new do
102
+ Delayed::Worker.new(@worker_options).start
103
+ end
104
+
105
+ # Allow it to boot
106
+ AppOpticsAPM.logger.info "[appoptics_apm/servers] Waiting 5 seconds for DJ to boot..."
107
+ sleep 5
@@ -0,0 +1,29 @@
1
+ # Copyright (c) 2016 SolarWinds, LLC.
2
+ # All rights reserved.
3
+
4
+ # This is a Rack application that is booted in a background
5
+ # thread and listens on port 8101.
6
+ #
7
+ require 'rack/handler/puma'
8
+ require 'appoptics_apm/inst/rack'
9
+
10
+ AppOpticsAPM.logger.info "[appoptics_apm/info] Starting background utility rack app on localhost:8101."
11
+
12
+ Thread.new do
13
+ app = Rack::Builder.new {
14
+ use AppOpticsAPM::Rack
15
+ map "/" do
16
+ run Proc.new { [200, {"Content-Type" => "text/html"}, ['Hello AppOpticsAPM!']] }
17
+ end
18
+
19
+ map "/redirectme" do
20
+ run Proc.new { [301, {"Location" => "/", "Content-Type" => "text/html"}, ['']] }
21
+ end
22
+ }
23
+
24
+ Rack::Handler::Puma.run(app, {:Host => '127.0.0.1', :Port => 8101})
25
+ end
26
+
27
+ # Allow Thin to boot.
28
+ sleep(2)
29
+
@@ -0,0 +1,96 @@
1
+ ##
2
+ # Copyright (c) 2016 SolarWinds, LLC.
3
+ # All rights reserved.
4
+
5
+ # This is a Rails stack that launches on a background
6
+ # thread and listens on port 8140.
7
+ #
8
+ require "rails/all"
9
+ require "action_controller/railtie"
10
+ require 'rack/handler/puma'
11
+ require File.expand_path(File.dirname(__FILE__) + '/../models/widget')
12
+
13
+ AppOpticsAPM.logger.info "[appoptics_apm/info] Starting background utility rails app on localhost:8140."
14
+
15
+ if ENV['DBTYPE'] == 'mysql2'
16
+ AppOpticsAPM::Test.set_mysql2_env
17
+ elsif ENV['DBTYPE'] == 'mysql'
18
+ AppOpticsAPM::Test.set_mysql_env
19
+ else
20
+ AppOpticsAPM.logger.warn "Unidentified DBTYPE: #{ENV['DBTYPE']}" unless ENV['DBTYPE'] == "postgresql"
21
+ AppOpticsAPM.logger.debug "Defaulting to postgres DB for background Rails server."
22
+ AppOpticsAPM::Test.set_postgresql_env
23
+ end
24
+
25
+ ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
26
+
27
+ unless ActiveRecord::Base.connection.table_exists? 'widgets'
28
+ CreateWidgets.migrate(:up)
29
+ end
30
+
31
+ class Rails32MetalStack < Rails::Application
32
+ routes.append do
33
+ get "/hello/world" => "hello#world"
34
+ get "/hello/:id/show" => "hello#show"
35
+ get "/hello/metal" => "ferro#world"
36
+ get "/hello/db" => "hello#db"
37
+ get "/hello/servererror" => "hello#servererror"
38
+ end
39
+
40
+ config.cache_classes = true
41
+ config.eager_load = false
42
+ config.active_support.deprecation = :stderr
43
+ config.middleware.delete "Rack::Lock"
44
+ config.middleware.delete "ActionDispatch::Flash"
45
+ config.middleware.delete "ActionDispatch::BestStandardsSupport"
46
+ config.secret_token = "498374i49qkuweoiuoqwehisuakshdhksadhaisdy78o34y138974xyqu9rmye8yrpiokeuioqwzyo8uxftoyqiuxrhm3iou1hrzmjk"
47
+ config.secret_key_base = "2048671-96803948"
48
+ end
49
+
50
+ #################################################
51
+ # Controllers
52
+ #################################################
53
+
54
+ class HelloController < ActionController::Base
55
+ def world
56
+ render :text => "Hello world!"
57
+ end
58
+
59
+ def show
60
+ render :text => "Hello Number #{params[:id]}"
61
+ end
62
+
63
+ def db
64
+ # Create a widget
65
+ w1 = Widget.new(:name => 'blah', :description => 'This is an amazing widget.')
66
+ w1.save
67
+
68
+ # query for that widget
69
+ w2 = Widget.where(:name => 'blah').first
70
+ w2.delete
71
+
72
+ render :text => "Hello database!"
73
+ end
74
+
75
+ def servererror
76
+ render :plain => "broken", :status => 500
77
+ end
78
+ end
79
+
80
+ class FerroController < ActionController::Metal
81
+ include AbstractController::Rendering
82
+
83
+ def world
84
+ self.response_body = "Hello world!"
85
+ end
86
+ end
87
+
88
+ AppOpticsAPM::API.profile_method(FerroController, :world)
89
+
90
+ Rails32MetalStack.initialize!
91
+
92
+ Thread.new do
93
+ Rack::Handler::Puma.run(Rails32MetalStack.to_app, {:Host => '127.0.0.1', :Port => 8140})
94
+ end
95
+
96
+ sleep(2)
@@ -0,0 +1,96 @@
1
+ ##
2
+ # Copyright (c) 2016 SolarWinds, LLC.
3
+ # All rights reserved.
4
+
5
+ # This is a Rails stack that launches on a background
6
+ # thread and listens on port 8140.
7
+ #
8
+ require "rails/all"
9
+ require "action_controller/railtie"
10
+ require 'rack/handler/puma'
11
+ require File.expand_path(File.dirname(__FILE__) + '/../models/widget')
12
+
13
+ AppOpticsAPM.logger.info "[appoptics_apm/info] Starting background utility rails app on localhost:8140."
14
+
15
+ if ENV['DBTYPE'] == 'mysql2'
16
+ AppOpticsAPM::Test.set_mysql2_env
17
+ elsif ENV['DBTYPE'] == 'mysql'
18
+ AppOpticsAPM::Test.set_mysql_env
19
+ else
20
+ AppOpticsAPM.logger.warn "Unidentified DBTYPE: #{ENV['DBTYPE']}" unless ENV['DBTYPE'] == "postgresql"
21
+ AppOpticsAPM.logger.debug "Defaulting to postgres DB for background Rails server."
22
+ AppOpticsAPM::Test.set_postgresql_env
23
+ end
24
+
25
+ ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
26
+
27
+ unless ActiveRecord::Base.connection.table_exists? 'widgets'
28
+ ActiveRecord::Migration.run(CreateWidgets)
29
+ end
30
+
31
+ class Rails40MetalStack < Rails::Application
32
+ routes.append do
33
+ get "/hello/world" => "hello#world"
34
+ get "/hello/:id/show" => "hello#show"
35
+ get "/hello/metal" => "ferro#world"
36
+ get "/hello/db" => "hello#db"
37
+ get "/hello/servererror" => "hello#servererror"
38
+ end
39
+
40
+ config.cache_classes = true
41
+ config.eager_load = false
42
+ config.active_support.deprecation = :stderr
43
+ config.middleware.delete "Rack::Lock"
44
+ config.middleware.delete "ActionDispatch::Flash"
45
+ config.middleware.delete "ActionDispatch::BestStandardsSupport"
46
+ config.secret_token = "49830489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yypiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
47
+ config.secret_key_base = "2048671-96803948"
48
+ end
49
+
50
+ #################################################
51
+ # Controllers
52
+ #################################################
53
+
54
+ class HelloController < ActionController::Base
55
+ def world
56
+ render :text => "Hello world!"
57
+ end
58
+
59
+ def show
60
+ render :text => "Hello Number #{params[:id]}"
61
+ end
62
+
63
+ def db
64
+ # Create a widget
65
+ w1 = Widget.new(:name => 'blah', :description => 'This is an amazing widget.')
66
+ w1.save
67
+
68
+ # query for that widget
69
+ w2 = Widget.where(:name => 'blah').first
70
+ w2.delete
71
+
72
+ render :text => "Hello database!"
73
+ end
74
+
75
+ def servererror
76
+ render :plain => "broken", :status => 500
77
+ end
78
+ end
79
+
80
+ class FerroController < ActionController::Metal
81
+ include AbstractController::Rendering
82
+
83
+ def world
84
+ self.response_body = "Hello world!"
85
+ end
86
+ end
87
+
88
+ AppOpticsAPM::API.profile_method(FerroController, :world)
89
+
90
+ Rails40MetalStack.initialize!
91
+
92
+ Thread.new do
93
+ Rack::Handler::Puma.run(Rails40MetalStack.to_app, {:Host => '127.0.0.1', :Port => 8140, :Threads => "0:1"})
94
+ end
95
+
96
+ sleep(2)
@@ -0,0 +1,95 @@
1
+ ##
2
+ # Copyright (c) 2016 SolarWinds, LLC.
3
+ # All rights reserved.
4
+
5
+ # This is a Rails stack that launches on a background
6
+ # thread and listens on port 8140.
7
+ #
8
+ if ENV['DBTYPE'] == 'mysql2'
9
+ AppOpticsAPM::Test.set_mysql2_env
10
+ elsif ENV['DBTYPE'] == 'postgresql'
11
+ AppOpticsAPM::Test.set_postgresql_env
12
+ else
13
+ AppOpticsAPM.logger.warn "Unidentified DBTYPE: #{ENV['DBTYPE']}" unless ENV['DBTYPE'] == "postgresql"
14
+ AppOpticsAPM.logger.debug "Defaulting to postgres DB for background Rails server."
15
+ AppOpticsAPM::Test.set_postgresql_env
16
+ end
17
+
18
+ require "rails/all"
19
+ require "action_controller/railtie" # require more if needed
20
+ require 'rack/handler/puma'
21
+ require File.expand_path(File.dirname(__FILE__) + '/../models/widget')
22
+
23
+ AppOpticsAPM.logger.info "[appoptics_apm/info] Starting background utility rails app on localhost:8140."
24
+
25
+ ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
26
+
27
+ unless ActiveRecord::Base.connection.table_exists? 'widgets'
28
+ ActiveRecord::Migration.run(CreateWidgets)
29
+ end
30
+
31
+ class Rails50MetalStack < Rails::Application
32
+ routes.append do
33
+ get "/hello/world" => "hello#world"
34
+ get "/hello/:id/show" => "hello#show"
35
+ get "/hello/metal" => "ferro#world"
36
+ get "/hello/db" => "hello#db"
37
+ get "/hello/servererror" => "hello#servererror"
38
+ end
39
+
40
+ config.cache_classes = true
41
+ config.eager_load = false
42
+ config.active_support.deprecation = :stderr
43
+ config.middleware.delete Rack::Lock
44
+ config.middleware.delete ActionDispatch::Flash
45
+ config.secret_token = "49837489qkuweoiuoqwehisuakshdjksadhaisdy78o34y138974xyqp9rmye8yrpiokeuioqwzyoiuxftoyqiuxrhm3iou1hrzmjk"
46
+ config.secret_key_base = "2048671-96803948"
47
+ end
48
+
49
+ #################################################
50
+ # Controllers
51
+ #################################################
52
+
53
+ class HelloController < ActionController::Base
54
+ def world
55
+ render :plain => "Hello world!"
56
+ end
57
+
58
+ def show
59
+ render :plain => "Hello Number #{params[:id]}"
60
+ end
61
+
62
+ def db
63
+ # Create a widget
64
+ w1 = Widget.new(:name => 'blah', :description => 'This is an amazing widget.')
65
+ w1.save
66
+
67
+ # query for that widget
68
+ w2 = Widget.where(:name => 'blah').first
69
+ w2.delete
70
+
71
+ render :plain => "Hello database!"
72
+ end
73
+
74
+ def servererror
75
+ render :plain => "broken", :status => 500
76
+ end
77
+ end
78
+
79
+ class FerroController < ActionController::Metal
80
+ include AbstractController::Rendering
81
+
82
+ def world
83
+ render :plain => "Hello world!"
84
+ end
85
+ end
86
+
87
+ AppOpticsAPM::API.profile_method(FerroController, :world)
88
+
89
+ Rails50MetalStack.initialize!
90
+
91
+ Thread.new do
92
+ Rack::Handler::Puma.run(Rails50MetalStack.to_app, {:Host => '127.0.0.1', :Port => 8140})
93
+ end
94
+
95
+ sleep(2)