genki-newrelic_rpm 2.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/CHANGELOG +316 -0
  2. data/LICENSE +37 -0
  3. data/Manifest +156 -0
  4. data/README.md +138 -0
  5. data/Rakefile +22 -0
  6. data/bin/mongrel_rpm +33 -0
  7. data/bin/newrelic_cmd +4 -0
  8. data/cert/cacert.pem +34 -0
  9. data/genki-newrelic_rpm.gemspec +32 -0
  10. data/init.rb +38 -0
  11. data/install.rb +37 -0
  12. data/lib/new_relic/agent.rb +280 -0
  13. data/lib/new_relic/agent/agent.rb +627 -0
  14. data/lib/new_relic/agent/chained_call.rb +13 -0
  15. data/lib/new_relic/agent/collection_helper.rb +61 -0
  16. data/lib/new_relic/agent/error_collector.rb +125 -0
  17. data/lib/new_relic/agent/instrumentation/active_merchant.rb +18 -0
  18. data/lib/new_relic/agent/instrumentation/active_record_instrumentation.rb +83 -0
  19. data/lib/new_relic/agent/instrumentation/authlogic.rb +8 -0
  20. data/lib/new_relic/agent/instrumentation/controller_instrumentation.rb +368 -0
  21. data/lib/new_relic/agent/instrumentation/data_mapper.rb +90 -0
  22. data/lib/new_relic/agent/instrumentation/dispatcher_instrumentation.rb +132 -0
  23. data/lib/new_relic/agent/instrumentation/memcache.rb +21 -0
  24. data/lib/new_relic/agent/instrumentation/merb/controller.rb +26 -0
  25. data/lib/new_relic/agent/instrumentation/merb/dispatcher.rb +13 -0
  26. data/lib/new_relic/agent/instrumentation/merb/errors.rb +8 -0
  27. data/lib/new_relic/agent/instrumentation/net.rb +12 -0
  28. data/lib/new_relic/agent/instrumentation/passenger_instrumentation.rb +20 -0
  29. data/lib/new_relic/agent/instrumentation/rack.rb +77 -0
  30. data/lib/new_relic/agent/instrumentation/rails/action_controller.rb +59 -0
  31. data/lib/new_relic/agent/instrumentation/rails/action_web_service.rb +27 -0
  32. data/lib/new_relic/agent/instrumentation/rails/dispatcher.rb +38 -0
  33. data/lib/new_relic/agent/instrumentation/rails/errors.rb +27 -0
  34. data/lib/new_relic/agent/instrumentation/sinatra.rb +39 -0
  35. data/lib/new_relic/agent/method_tracer.rb +277 -0
  36. data/lib/new_relic/agent/patch_const_missing.rb +125 -0
  37. data/lib/new_relic/agent/sampler.rb +12 -0
  38. data/lib/new_relic/agent/samplers/cpu_sampler.rb +49 -0
  39. data/lib/new_relic/agent/samplers/memory_sampler.rb +137 -0
  40. data/lib/new_relic/agent/samplers/mongrel_sampler.rb +22 -0
  41. data/lib/new_relic/agent/shim_agent.rb +21 -0
  42. data/lib/new_relic/agent/stats_engine.rb +24 -0
  43. data/lib/new_relic/agent/stats_engine/metric_stats.rb +111 -0
  44. data/lib/new_relic/agent/stats_engine/samplers.rb +71 -0
  45. data/lib/new_relic/agent/stats_engine/transactions.rb +155 -0
  46. data/lib/new_relic/agent/transaction_sampler.rb +319 -0
  47. data/lib/new_relic/agent/worker_loop.rb +118 -0
  48. data/lib/new_relic/commands/deployments.rb +145 -0
  49. data/lib/new_relic/commands/new_relic_commands.rb +30 -0
  50. data/lib/new_relic/control.rb +436 -0
  51. data/lib/new_relic/control/external.rb +13 -0
  52. data/lib/new_relic/control/merb.rb +22 -0
  53. data/lib/new_relic/control/rails.rb +143 -0
  54. data/lib/new_relic/control/ruby.rb +34 -0
  55. data/lib/new_relic/control/sinatra.rb +14 -0
  56. data/lib/new_relic/histogram.rb +89 -0
  57. data/lib/new_relic/local_environment.rb +285 -0
  58. data/lib/new_relic/merbtasks.rb +6 -0
  59. data/lib/new_relic/metric_data.rb +44 -0
  60. data/lib/new_relic/metric_parser.rb +120 -0
  61. data/lib/new_relic/metric_parser/action_mailer.rb +9 -0
  62. data/lib/new_relic/metric_parser/active_merchant.rb +26 -0
  63. data/lib/new_relic/metric_parser/active_record.rb +25 -0
  64. data/lib/new_relic/metric_parser/controller.rb +54 -0
  65. data/lib/new_relic/metric_parser/controller_cpu.rb +38 -0
  66. data/lib/new_relic/metric_parser/errors.rb +6 -0
  67. data/lib/new_relic/metric_parser/external.rb +50 -0
  68. data/lib/new_relic/metric_parser/mem_cache.rb +12 -0
  69. data/lib/new_relic/metric_parser/view.rb +61 -0
  70. data/lib/new_relic/metric_parser/web_frontend.rb +14 -0
  71. data/lib/new_relic/metric_parser/web_service.rb +9 -0
  72. data/lib/new_relic/metric_spec.rb +52 -0
  73. data/lib/new_relic/metrics.rb +7 -0
  74. data/lib/new_relic/noticed_error.rb +25 -0
  75. data/lib/new_relic/rack/metric_app.rb +56 -0
  76. data/lib/new_relic/rack/newrelic.ru +25 -0
  77. data/lib/new_relic/rack/newrelic.yml +25 -0
  78. data/lib/new_relic/rack_app.rb +5 -0
  79. data/lib/new_relic/recipes.rb +82 -0
  80. data/lib/new_relic/stats.rb +360 -0
  81. data/lib/new_relic/transaction_analysis.rb +121 -0
  82. data/lib/new_relic/transaction_sample.rb +583 -0
  83. data/lib/new_relic/version.rb +54 -0
  84. data/lib/new_relic_api.rb +315 -0
  85. data/lib/newrelic_rpm.rb +40 -0
  86. data/lib/tasks/all.rb +4 -0
  87. data/lib/tasks/install.rake +7 -0
  88. data/lib/tasks/tests.rake +13 -0
  89. data/newrelic.yml +214 -0
  90. data/recipes/newrelic.rb +6 -0
  91. data/test/active_record_fixtures.rb +55 -0
  92. data/test/config/newrelic.yml +46 -0
  93. data/test/config/test_control.rb +39 -0
  94. data/test/new_relic/agent/active_record_instrumentation_test.rb +234 -0
  95. data/test/new_relic/agent/agent_controller_test.rb +107 -0
  96. data/test/new_relic/agent/agent_test.rb +117 -0
  97. data/test/new_relic/agent/agent_test_controller.rb +44 -0
  98. data/test/new_relic/agent/classloader_patch_test.rb +56 -0
  99. data/test/new_relic/agent/collection_helper_test.rb +118 -0
  100. data/test/new_relic/agent/dispatcher_instrumentation_test.rb +76 -0
  101. data/test/new_relic/agent/error_collector_test.rb +155 -0
  102. data/test/new_relic/agent/method_tracer_test.rb +335 -0
  103. data/test/new_relic/agent/metric_data_test.rb +56 -0
  104. data/test/new_relic/agent/mock_ar_connection.rb +40 -0
  105. data/test/new_relic/agent/mock_scope_listener.rb +23 -0
  106. data/test/new_relic/agent/net_instrumentation_test.rb +51 -0
  107. data/test/new_relic/agent/stats_engine/metric_stats_test.rb +79 -0
  108. data/test/new_relic/agent/stats_engine/samplers_test.rb +78 -0
  109. data/test/new_relic/agent/stats_engine/stats_engine_test.rb +177 -0
  110. data/test/new_relic/agent/task_instrumentation_test.rb +67 -0
  111. data/test/new_relic/agent/testable_agent.rb +13 -0
  112. data/test/new_relic/agent/transaction_sample_builder_test.rb +195 -0
  113. data/test/new_relic/agent/transaction_sample_test.rb +146 -0
  114. data/test/new_relic/agent/transaction_sampler_test.rb +387 -0
  115. data/test/new_relic/agent/worker_loop_test.rb +103 -0
  116. data/test/new_relic/control_test.rb +94 -0
  117. data/test/new_relic/deployments_api_test.rb +68 -0
  118. data/test/new_relic/environment_test.rb +75 -0
  119. data/test/new_relic/metric_parser_test.rb +172 -0
  120. data/test/new_relic/metric_spec_test.rb +177 -0
  121. data/test/new_relic/shim_agent_test.rb +9 -0
  122. data/test/new_relic/stats_test.rb +291 -0
  123. data/test/new_relic/version_number_test.rb +74 -0
  124. data/test/test_helper.rb +38 -0
  125. data/test/ui/newrelic_controller_test.rb +14 -0
  126. data/test/ui/newrelic_helper_test.rb +53 -0
  127. data/ui/controllers/newrelic_controller.rb +214 -0
  128. data/ui/helpers/google_pie_chart.rb +55 -0
  129. data/ui/helpers/newrelic_helper.rb +314 -0
  130. data/ui/views/layouts/newrelic_default.rhtml +47 -0
  131. data/ui/views/newrelic/_explain_plans.rhtml +27 -0
  132. data/ui/views/newrelic/_sample.rhtml +15 -0
  133. data/ui/views/newrelic/_segment.rhtml +28 -0
  134. data/ui/views/newrelic/_segment_limit_message.rhtml +1 -0
  135. data/ui/views/newrelic/_segment_row.rhtml +14 -0
  136. data/ui/views/newrelic/_show_sample_detail.rhtml +24 -0
  137. data/ui/views/newrelic/_show_sample_sql.rhtml +20 -0
  138. data/ui/views/newrelic/_show_sample_summary.rhtml +3 -0
  139. data/ui/views/newrelic/_sql_row.rhtml +11 -0
  140. data/ui/views/newrelic/_stack_trace.rhtml +30 -0
  141. data/ui/views/newrelic/_table.rhtml +12 -0
  142. data/ui/views/newrelic/explain_sql.rhtml +42 -0
  143. data/ui/views/newrelic/images/arrow-close.png +0 -0
  144. data/ui/views/newrelic/images/arrow-open.png +0 -0
  145. data/ui/views/newrelic/images/blue_bar.gif +0 -0
  146. data/ui/views/newrelic/images/file_icon.png +0 -0
  147. data/ui/views/newrelic/images/gray_bar.gif +0 -0
  148. data/ui/views/newrelic/images/new_relic_rpm_desktop.gif +0 -0
  149. data/ui/views/newrelic/images/textmate.png +0 -0
  150. data/ui/views/newrelic/index.rhtml +45 -0
  151. data/ui/views/newrelic/javascript/prototype-scriptaculous.js +7288 -0
  152. data/ui/views/newrelic/javascript/transaction_sample.js +107 -0
  153. data/ui/views/newrelic/sample_not_found.rhtml +2 -0
  154. data/ui/views/newrelic/show_sample.rhtml +77 -0
  155. data/ui/views/newrelic/show_source.rhtml +3 -0
  156. data/ui/views/newrelic/stylesheets/style.css +433 -0
  157. data/ui/views/newrelic/threads.rhtml +52 -0
  158. metadata +327 -0
@@ -0,0 +1,335 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+ require 'new_relic/agent/mock_scope_listener'
3
+
4
+ class Module
5
+ def method_traced?(method_name, metric_name)
6
+ traced_method_prefix = _traced_method_name(method_name, metric_name)
7
+
8
+ method_defined? traced_method_prefix
9
+ end
10
+ end
11
+
12
+ class Insider
13
+ def initialize(stats_engine)
14
+ @stats_engine = stats_engine
15
+ end
16
+ def catcher(level=0)
17
+ thrower(level) if level>0
18
+ end
19
+ def thrower(level)
20
+ if level == 0
21
+ # don't use a real sampler because we can't instantiate one
22
+ # sampler = NewRelic::Agent::TransactionSampler.new(NewRelic::Agent.instance)
23
+ sampler = "<none>"
24
+ begin
25
+ @stats_engine.transaction_sampler = sampler
26
+ fail "This should not have worked."
27
+ rescue; end
28
+ else
29
+ thrower(level-1)
30
+ end
31
+ end
32
+ end
33
+
34
+ module NewRelic
35
+ module Agent
36
+ extend self
37
+ def module_method_to_be_traced (x, testcase)
38
+ testcase.assert x == "x"
39
+ testcase.assert testcase.stats_engine.peek_scope.name == "x"
40
+ end
41
+ end
42
+ end
43
+
44
+ class NewRelic::Agent::MethodTracerTest < Test::Unit::TestCase
45
+ attr_reader :stats_engine
46
+
47
+ def setup
48
+ NewRelic::Agent.manual_start
49
+ @stats_engine = NewRelic::Agent.instance.stats_engine
50
+ @stats_engine.clear_stats
51
+ @scope_listener = NewRelic::Agent::MockScopeListener.new
52
+ @stats_engine.transaction_sampler = @scope_listener
53
+ end
54
+
55
+ def teardown
56
+ self.class.remove_method_tracer :method_to_be_traced, @metric_name if @metric_name
57
+ @metric_name = nil
58
+ end
59
+
60
+ def test_basic
61
+ metric = "hello"
62
+ t1 = Time.now
63
+ self.class.trace_execution_scoped metric do
64
+ sleep 1
65
+ assert metric == @stats_engine.peek_scope.name
66
+ end
67
+ elapsed = Time.now - t1
68
+
69
+ stats = @stats_engine.get_stats(metric)
70
+ check_time stats.total_call_time, elapsed
71
+ assert stats.call_count == 1
72
+ end
73
+
74
+ def test_basic__original_api
75
+ metric = "hello"
76
+ t1 = Time.now
77
+ self.class.trace_method_execution metric, true, true, true do
78
+ sleep 1
79
+ assert metric == @stats_engine.peek_scope.name
80
+ end
81
+ elapsed = Time.now - t1
82
+
83
+ stats = @stats_engine.get_stats(metric)
84
+ check_time stats.total_call_time, elapsed
85
+ assert stats.call_count == 1
86
+ end
87
+
88
+ METRIC = "metric"
89
+ def test_add_method_tracer
90
+ @metric_name = METRIC
91
+ self.class.add_method_tracer :method_to_be_traced, METRIC
92
+
93
+ t1 = Time.now
94
+ method_to_be_traced 1,2,3,true,METRIC
95
+ elapsed = Time.now - t1
96
+
97
+ stats = @stats_engine.get_stats(METRIC)
98
+ check_time stats.total_call_time, elapsed
99
+ assert stats.call_count == 1
100
+ end
101
+
102
+ def test_add_method_tracer__default
103
+ self.class.add_method_tracer :simple_method
104
+
105
+ simple_method
106
+
107
+ stats = @stats_engine.get_stats("Custom/#{self.class.name}/simple_method")
108
+ assert stats.call_count == 1
109
+
110
+ end
111
+ def test_add_method_tracer__reentry
112
+ self.class.add_method_tracer :simple_method
113
+ self.class.add_method_tracer :simple_method
114
+ self.class.add_method_tracer :simple_method
115
+
116
+ simple_method
117
+
118
+ stats = @stats_engine.get_stats("Custom/#{self.class.name}/simple_method")
119
+ assert stats.call_count == 1
120
+
121
+ end
122
+
123
+ def test_method_traced?
124
+ assert !self.class.method_traced?(:method_to_be_traced, METRIC)
125
+ self.class.add_method_tracer :method_to_be_traced, METRIC
126
+ assert self.class.method_traced?(:method_to_be_traced, METRIC)
127
+ end
128
+
129
+ def test_tt_only
130
+
131
+ assert_nil @scope_listener.scope["c2"]
132
+ self.class.add_method_tracer :method_c1, "c1", true
133
+
134
+ self.class.add_method_tracer :method_c2, "c2", :metric => false
135
+ self.class.add_method_tracer :method_c3, "c3", false
136
+
137
+ method_c1
138
+
139
+ assert_not_nil @stats_engine.lookup_stat("c1")
140
+ assert_nil @stats_engine.lookup_stat("c2")
141
+ assert_not_nil @stats_engine.lookup_stat("c3")
142
+
143
+ assert_not_nil @scope_listener.scope["c2"]
144
+ end
145
+
146
+ def test_nested_scope_tracer
147
+ Insider.add_method_tracer :catcher, "catcher", :push_scope => true
148
+ Insider.add_method_tracer :thrower, "thrower", :push_scope => true
149
+ sampler = NewRelic::Agent.instance.transaction_sampler
150
+ mock = Insider.new(@stats_engine)
151
+ mock.catcher(0)
152
+ mock.catcher(5)
153
+ stats = @stats_engine.get_stats("catcher")
154
+ assert_equal 2, stats.call_count
155
+ stats = @stats_engine.get_stats("thrower")
156
+ assert_equal 6, stats.call_count
157
+ sample = sampler.harvest
158
+ assert_not_nil sample
159
+ end
160
+
161
+ def test_add_same_tracer_twice
162
+ @metric_name = METRIC
163
+ self.class.add_method_tracer :method_to_be_traced, METRIC
164
+ self.class.add_method_tracer :method_to_be_traced, METRIC
165
+
166
+ t1 = Time.now
167
+ method_to_be_traced 1,2,3,true,METRIC
168
+ elapsed = Time.now - t1
169
+
170
+ stats = @stats_engine.get_stats(METRIC)
171
+ check_time stats.total_call_time, elapsed
172
+ assert stats.call_count == 1
173
+ end
174
+
175
+ def test_add_tracer_with_dynamic_metric
176
+ metric_code = '#{args[0]}.#{args[1]}'
177
+ @metric_name = metric_code
178
+ expected_metric = "1.2"
179
+ self.class.add_method_tracer :method_to_be_traced, metric_code
180
+
181
+ t1 = Time.now
182
+ method_to_be_traced 1,2,3,true,expected_metric
183
+ elapsed = Time.now - t1
184
+
185
+ stats = @stats_engine.get_stats(expected_metric)
186
+ check_time stats.total_call_time, elapsed
187
+ assert stats.call_count == 1
188
+ end
189
+
190
+ def test_trace_method_with_block
191
+ self.class.add_method_tracer :method_with_block, METRIC
192
+
193
+ t1 = Time.now
194
+ method_with_block(1,2,3,true,METRIC) do |scope|
195
+ assert scope == METRIC
196
+ end
197
+ elapsed = Time.now - t1
198
+
199
+ stats = @stats_engine.get_stats(METRIC)
200
+ check_time stats.total_call_time, elapsed
201
+ assert stats.call_count == 1
202
+ end
203
+
204
+ def test_trace_module_method
205
+ NewRelic::Agent.add_method_tracer :module_method_to_be_traced, '#{args[0]}'
206
+ NewRelic::Agent.module_method_to_be_traced "x", self
207
+ NewRelic::Agent.remove_method_tracer :module_method_to_be_traced, '#{args[0]}'
208
+ end
209
+
210
+ def test_remove
211
+ self.class.add_method_tracer :method_to_be_traced, METRIC
212
+ self.class.remove_method_tracer :method_to_be_traced, METRIC
213
+
214
+ t1 = Time.now
215
+ method_to_be_traced 1,2,3,false,METRIC
216
+ elapsed = Time.now - t1
217
+
218
+ stats = @stats_engine.get_stats(METRIC)
219
+ assert stats.call_count == 0
220
+ end
221
+
222
+ def self.static_method(x, testcase, is_traced)
223
+ testcase.assert x == "x"
224
+ testcase.assert((testcase.stats_engine.peek_scope.name == "x") == is_traced)
225
+ end
226
+
227
+ def trace_trace_static_method
228
+ self.add_method_tracer :static_method, '#{args[0]}'
229
+ self.class.static_method "x", self, true
230
+ self.remove_method_tracer :static_method, '#{args[0]}'
231
+ self.class.static_method "x", self, false
232
+ end
233
+
234
+ def test_multiple_metrics__scoped
235
+ metrics = %w[first second third]
236
+ self.class.trace_execution_scoped metrics do
237
+ sleep 0.05
238
+ end
239
+ elapsed = @stats_engine.get_stats('first').average_call_time
240
+ metrics.map{|name| @stats_engine.get_stats name}.each do | m |
241
+ assert_equal 1, m.call_count
242
+ assert_equal elapsed, m.total_call_time
243
+ end
244
+ end
245
+ def test_multiple_metrics__unscoped
246
+ metrics = %w[first second third]
247
+ self.class.trace_execution_unscoped metrics do
248
+ sleep 0.05
249
+ end
250
+ elapsed = @stats_engine.get_stats('first').average_call_time
251
+ metrics.map{|name| @stats_engine.get_stats name}.each do | m |
252
+ assert_equal 1, m.call_count
253
+ assert_equal elapsed, m.total_call_time
254
+ end
255
+ end
256
+ def test_exception
257
+ begin
258
+ metric = "hey"
259
+ self.class.trace_execution_scoped metric do
260
+ assert @stats_engine.peek_scope.name == metric
261
+ throw Exception.new
262
+ end
263
+
264
+ assert false # should never get here
265
+ rescue Exception
266
+ # make sure the scope gets popped
267
+ assert @stats_engine.peek_scope == nil
268
+ end
269
+
270
+ stats = @stats_engine.get_stats metric
271
+ assert stats.call_count == 1
272
+ end
273
+
274
+ def test_add_multiple_tracers
275
+ self.class.add_method_tracer :method_to_be_traced, 'X', :push_scope => false
276
+ method_to_be_traced 1,2,3,true,nil
277
+ self.class.add_method_tracer :method_to_be_traced, 'Y'
278
+ method_to_be_traced 1,2,3,true,'Y'
279
+ self.class.remove_method_tracer :method_to_be_traced, 'Y'
280
+ method_to_be_traced 1,2,3,true,nil
281
+ self.class.remove_method_tracer :method_to_be_traced, 'X'
282
+ method_to_be_traced 1,2,3,false,'X'
283
+ end
284
+
285
+ def trace_no_push_scope
286
+ self.class.add_method_tracer :method_to_be_traced, 'X', :push_scope => false
287
+ method_to_be_traced 1,2,3,true,nil
288
+ self.class.remove_method_tracer :method_to_be_traced, 'X'
289
+ method_to_be_traced 1,2,3,false,'X'
290
+ end
291
+
292
+ def check_time (t1, t2)
293
+ assert((t2-t1).abs < 0.01, "Times not close: #{t1} ~ #{t2}")
294
+ end
295
+
296
+ # =======================================================
297
+ # test methods to be traced
298
+ def method_to_be_traced(x, y, z, is_traced, expected_metric)
299
+ sleep 0.1
300
+ assert x == 1
301
+ assert y == 2
302
+ assert z == 3
303
+ scope_name = @stats_engine.peek_scope ? @stats_engine.peek_scope.name : nil
304
+ if is_traced
305
+ assert_equal expected_metric, scope_name
306
+ else
307
+ assert_not_equal expected_metric, scope_name
308
+ end
309
+ end
310
+
311
+ def method_with_block(x, y, z, is_traced, expected_metric, &block)
312
+ sleep 0.1
313
+ assert x == 1
314
+ assert y == 2
315
+ assert z == 3
316
+ block.call(@stats_engine.peek_scope.name)
317
+
318
+ scope_name = @stats_engine.peek_scope ? @stats_engine.peek_scope.name : nil
319
+ assert((expected_metric == scope_name) == is_traced)
320
+ end
321
+
322
+ def method_c1
323
+ method_c2
324
+ end
325
+
326
+ def method_c2
327
+ method_c3
328
+ end
329
+
330
+ def method_c3
331
+ end
332
+
333
+ def simple_method
334
+ end
335
+ end
@@ -0,0 +1,56 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__),'..','..','test_helper'))
2
+ require 'test/unit'
3
+
4
+
5
+ class NewRelic::Agent::MetricDataTest < Test::Unit::TestCase
6
+
7
+
8
+ # test to make sure the MetricData class can serialize to json
9
+ def test_json
10
+ spec = NewRelic::MetricSpec.new("controller", "metric#find")
11
+
12
+ import = ActiveSupport::JSON.decode(spec.to_json)
13
+
14
+ compare_spec(spec, import)
15
+
16
+ stats = NewRelic::MethodTraceStats.new
17
+
18
+ import = ActiveSupport::JSON.decode(stats.to_json)
19
+
20
+ compare_stat(stats, import)
21
+
22
+ metric_data = NewRelic::MetricData.new(spec, stats, 10)
23
+
24
+ import = ActiveSupport::JSON.decode(metric_data.to_json)
25
+
26
+ compare_metric_data(metric_data, import)
27
+ end
28
+
29
+
30
+ private
31
+
32
+ def compare_spec(spec, import)
33
+ assert_equal 2, import.length
34
+ assert_equal spec.name, import['name']
35
+ assert_equal spec.scope, import['scope']
36
+ end
37
+
38
+ def compare_stat(stats, import)
39
+ assert_equal 6, import.length
40
+ assert_equal stats.total_call_time, import['total_call_time']
41
+ assert_equal stats.max_call_time, import['max_call_time']
42
+ assert_equal stats.min_call_time, import['min_call_time']
43
+ assert_equal stats.sum_of_squares, import['sum_of_squares']
44
+ assert_equal stats.call_count, import['call_count']
45
+ assert_equal stats.total_exclusive_time, import['total_exclusive_time']
46
+ end
47
+
48
+ def compare_metric_data(metric_data, import)
49
+ assert_equal 3, import.length
50
+ compare_spec(metric_data.metric_spec, import['metric_spec'])
51
+ compare_stat(metric_data.stats, import['stats'])
52
+ assert_equal metric_data.metric_id, import['metric_id']
53
+ end
54
+
55
+ end
56
+
@@ -0,0 +1,40 @@
1
+ module ActiveRecord
2
+ class Base
3
+ class << self
4
+ def test_connection(config)
5
+ @connect ||= Connection.new
6
+ end
7
+ end
8
+ end
9
+
10
+ class Connection
11
+ attr_accessor :throw
12
+ attr_reader :disconnected
13
+
14
+ def initialize
15
+ @disconnected = false
16
+ @throw = false
17
+ end
18
+
19
+ def disconnect!()
20
+ @disconnected = true
21
+ end
22
+
23
+ def find()
24
+ # used to test that we've instrumented this...
25
+ end
26
+
27
+ def select_rows(s)
28
+ execute(s)
29
+ end
30
+ def execute(s)
31
+ fail "" if @throw
32
+ if s != "EXPLAIN #{::SQL_STATEMENT}"
33
+ fail "Unexpected sql statement #{s}"
34
+ end
35
+ s
36
+ end
37
+ end
38
+ end
39
+
40
+
@@ -0,0 +1,23 @@
1
+
2
+ class NewRelic::Agent::MockScopeListener
3
+
4
+ attr_reader :scope
5
+
6
+ def initialize
7
+ @scope = {}
8
+ end
9
+
10
+ def notice_first_scope_push(time)
11
+ end
12
+
13
+ def notice_push_scope(scope, time)
14
+ @scope[scope] = true
15
+ end
16
+
17
+ def notice_pop_scope(scope, time)
18
+ end
19
+
20
+ def notice_scope_empty(time)
21
+
22
+ end
23
+ end