copperegg-apm 1.0.0.pre5 → 1.0.0.pre6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e143cece9e590383a13e4f8a29a5f3e6a8a39fe
4
- data.tar.gz: b4fc0574c45b9dd1a838b54e515c5c79178d8b3e
3
+ metadata.gz: 25fc7205faebae36a3c3900d91b3cd4f9b546cdc
4
+ data.tar.gz: 62b6fc328ed9103b6d6b2da9b1530c0e1f88a9dc
5
5
  SHA512:
6
- metadata.gz: 64aec00ee6e653dd59884633de9824fce8ee4327e2328e8580a45939e8b69aeddc1bffb5c02914028a354515243d42af849ad823a82c7ada0ab0a9b6e1442487
7
- data.tar.gz: 77dc00611f2344497ed8621b3f185025cfe59faf60bd31a050128e5dcc26d883d7f8ba56c434c0471eb7d1a96c8a23daf4da2cb93397f52fab52e3ad1832ff57
6
+ metadata.gz: d9aeef33236e8d6d4a0a97ad9e7e75646fffb3e256670f4ecab417fcdb7fa064dbaaf6b06f3305b9faaaa4c36df0602b4618a6b63e1f5c6a40476ac74443d47d
7
+ data.tar.gz: f2fbbe012180b90691727279be8837957886d20c6f22ede1d31a52d4f9620142ab2d615dcaec15565638bde3ea7157c2577c75fd234feb53af0f3624cdf73366
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- copperegg-apm (1.0.0.pre4)
4
+ copperegg-apm (1.0.0.pre6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
Binary file
@@ -0,0 +1,20 @@
1
+ module CopperEgg
2
+ module APM
3
+ class BenchmarkMiddleware
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ CopperEgg::APM.benchmark(:url => env['REQUEST_URI'].gsub(/\/\/[^:]+:[^@]@/,"//").gsub(/\?.*/,"")) do
10
+ @status, @headers, @response = @app.call(env)
11
+ end
12
+ [@status, @headers, self]
13
+ end
14
+
15
+ def each(&block)
16
+ @response.each(&block)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -158,11 +158,13 @@ module CopperEgg
158
158
  yield(self)
159
159
 
160
160
  if @@app_root.empty?
161
- if defined?(::Rails) && ::Rails.respond_to?(:configuration)
162
- @@app_root = ::Rails.configuration.root.to_s
163
- else
164
- @@app_root = File.dirname(caller[1])
165
- end
161
+ @@app_root = if defined?(::Rails) && Rails.respond_to?(:root)
162
+ Rails.root.to_s
163
+ elsif defined?(RAILS_ROOT)
164
+ RAILS_ROOT
165
+ else
166
+ File.dirname(caller[1])
167
+ end
166
168
  end
167
169
 
168
170
  if @@disabled
@@ -1,15 +1,15 @@
1
1
  module CopperEgg
2
2
  module APM
3
3
  module Kernel
4
- alias_method :raise_without_ce_instrumentation, :raise
5
-
6
4
  def raise(*args)
7
- super(ArgumentError, "wrong number of arguments", caller) if args.size > 3
8
5
  CopperEgg::APM.capture_exception(*args) if CopperEgg::APM::Configuration.benchmark_exceptions?
9
- raise_without_ce_instrumentation(*args)
6
+ super
7
+ end
8
+
9
+ def fail(*args)
10
+ CopperEgg::APM.capture_exception(*args) if CopperEgg::APM::Configuration.benchmark_exceptions?
11
+ super
10
12
  end
11
-
12
- alias_method :fail, :raise
13
13
  end
14
14
  end
15
15
  end
@@ -0,0 +1,45 @@
1
+ require 'rack'
2
+
3
+ module CopperEgg
4
+ module APM
5
+ class RumMiddleware
6
+ RUM_INJECTED_KEY = "COPPEREGG_APM_RUM_INJECTED"
7
+
8
+ def initialize(app)
9
+ @app = app
10
+ end
11
+
12
+ def call(evn)
13
+ status, headers, response = @app.call(env)
14
+
15
+ if status != 200 || rum_injected?(env) || !html_request?(env)
16
+ return [status, headers, response]
17
+ elsif has_head_tag?(response)
18
+ # if html request, extract <head>...</head> from request
19
+
20
+ # if <head> is extracted, insert rum <script> tag at the bottom
21
+ else
22
+ return [status, headers, response]
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def rum_injected?(env)
29
+ env[RUM_INJECTED_KEY]
30
+ end
31
+
32
+ def html_request?(env)
33
+ env["Content-Type"] && env["Content-Type"] =~ /text\/html/
34
+ end
35
+
36
+ def has_head_tag?(response)
37
+
38
+ end
39
+
40
+ def inject_rum(response, headers)
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,5 +1,5 @@
1
1
  module CopperEgg
2
2
  module APM
3
- GEM_VERSION = '1.0.0.pre5'
3
+ GEM_VERSION = '1.0.0.pre6' unless defined? GEM_VERSION
4
4
  end
5
5
  end
@@ -12,7 +12,7 @@ module Copperegg
12
12
  private
13
13
 
14
14
  def instrument_key
15
- @instrument_key = ask("Enter your app key:")
15
+ @instrument_key = ask("Enter your instrument key:")
16
16
  end
17
17
  end
18
18
  end
@@ -1,7 +1,7 @@
1
1
  # Props to @relishapp (http://www.relishapp.com/rspec/rspec-rails/docs/controller-specs/anonymous-controller) and
2
2
  # @AlexandrZaytsev (http://say26.com/rspec-testing-controllers-outside-of-a-rails-application) for their helpful blog posts
3
- require 'spec_helper'
4
3
  require File.dirname(__FILE__) + '/helpers/rails'
4
+ require 'spec_helper'
5
5
 
6
6
  RSpec.configure do |c|
7
7
  c.infer_base_class_for_anonymous_controllers = true
@@ -11,10 +11,10 @@ class ApplicationController < ActionController::Base
11
11
  include Rails.application.routes.url_helpers
12
12
  end
13
13
 
14
- class ApplicationControllerSubclass < ApplicationController; end
14
+ class ExceptionController < ApplicationController; end
15
15
 
16
- describe ApplicationControllerSubclass, :type => :controller do
17
- controller(ApplicationControllerSubclass) do
16
+ describe ExceptionController, :type => :controller do
17
+ controller(ExceptionController) do
18
18
  def index
19
19
  @count = 1/0
20
20
  end
@@ -29,7 +29,8 @@ describe ApplicationControllerSubclass, :type => :controller do
29
29
  expect(hash.keys.sort).to eq ["excp", "id"]
30
30
  expect(hash["id"]).to match(/\A[0-1a-z]{16}\z/i)
31
31
  expect(hash["excp"].keys.sort).to eq ["error", "stacktrace", "ts"]
32
- expect(hash["excp"]["error"]).to match(/ZeroDivisionError\|/)
32
+ expect(hash["excp"]["error"]).to match(/\AZeroDivisionError\|/)
33
+ expect(hash["excp"]["error"]).to match(/\{Ruby\}\Z/)
33
34
  expect(hash["excp"]["stacktrace"]).to match(/\Adivided by 0\n/)
34
35
  expect(hash["excp"]["ts"]).to be_an_instance_of(Fixnum)
35
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copperegg-apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre5
4
+ version: 1.0.0.pre6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Bradford
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-04 00:00:00.000000000 Z
11
+ date: 2013-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -197,6 +197,7 @@ files:
197
197
  - ./lib/copperegg/apm/active_record/connection_adapters/abstract_adapter.rb
198
198
  - ./lib/copperegg/apm/benchmark.rb
199
199
  - ./lib/copperegg/apm/benchmark_methods_table.rb
200
+ - ./lib/copperegg/apm/benchmark_middleware.rb
200
201
  - ./lib/copperegg/apm/configuration.rb
201
202
  - ./lib/copperegg/apm/errors.rb
202
203
  - ./lib/copperegg/apm/ethon/easy/operations.rb
@@ -208,6 +209,7 @@ files:
208
209
  - ./lib/copperegg/apm/railtie.rb
209
210
  - ./lib/copperegg/apm/restclient/request.rb
210
211
  - ./lib/copperegg/apm/rum.rb
212
+ - ./lib/copperegg/apm/rum_middleware.rb
211
213
  - ./lib/copperegg/apm/sqlite3/database.rb
212
214
  - ./lib/copperegg/apm/tasks.rb
213
215
  - ./lib/copperegg/apm/typhoeus/hydra.rb
@@ -217,9 +219,6 @@ files:
217
219
  - ./lib/copperegg-apm.rb
218
220
  - ./lib/generators/copperegg/apm/init_generator.rb
219
221
  - ./lib/generators/copperegg/apm/templates/config.rb
220
- - ./lib/helpers/benchmark_methods_table.rb
221
- - ./lib/helpers/reveal_cloud.rb
222
- - ./performance/mysql2.rb
223
222
  - ./Rakefile
224
223
  - ./README.md
225
224
  - ./screenshot01.png
@@ -294,7 +293,7 @@ rubyforge_project:
294
293
  rubygems_version: 2.0.3
295
294
  signing_key:
296
295
  specification_version: 4
297
- summary: copperegg-apm-1.0.0.pre5
296
+ summary: copperegg-apm-1.0.0.pre6
298
297
  test_files:
299
298
  - spec/action_controller_spec.rb
300
299
  - spec/apm_spec.rb
@@ -1,65 +0,0 @@
1
- module CopperEgg
2
- module APM
3
- class BenchmarkMethodsTable
4
- def benchmarkable_methods
5
- @benchmarkable_methods ||= CopperEgg::APM.benchmarkable_methods.sort_by(&:display_name)
6
- end
7
-
8
- def excluded_methods
9
- benchmarkable_methods.select {|method| method.excluded?}
10
- end
11
-
12
- def method_column_width
13
- benchmarkable_methods.reduce(0) do |memo, method|
14
- method.display_name.size > memo ? method.display_name.size : memo
15
- end + column_padding
16
- end
17
-
18
- def source_filename_column_width
19
- benchmarkable_methods.reduce(0) do |memo, method|
20
- method.display_filename.size > memo ? method.display_filename.size : memo
21
- end + column_padding
22
- end
23
-
24
- def column_padding
25
- 2
26
- end
27
-
28
- def separator
29
- "+" + "-"*(method_column_width+1) + "+" + "-"*(source_filename_column_width+1) + "+" + "--------------+"
30
- end
31
-
32
- def header_columns
33
- "| Method" + " "*(method_column_width - 6).abs + "| Source Location" + " "*(source_filename_column_width - 15).abs + "| Benchmarked? |"
34
- end
35
-
36
- def method_columns(method)
37
- "| #{method.display_name}" + " "*(method_column_width - method.display_name.size) + "| #{method.display_filename}" + " "*(source_filename_column_width - method.display_filename.size) + "| #{method.excluded? ? "NO " : "YES"} |"
38
- end
39
-
40
- def classes_count
41
- benchmarkable_methods.map(&:owner).uniq!.size
42
- end
43
-
44
- def file_count
45
- benchmarkable_methods.map(&:source_filename).uniq!.size
46
- end
47
-
48
- def print_table
49
- if RUBY_VERSION < "1.9"
50
- puts "Method benchmarking is not available in Ruby #{RUBY_VERSION}. It is only available in Ruby 1.9 or later."
51
- elsif CopperEgg::APM::Configuration.benchmark_methods_level == :disabled
52
- puts "Method benchmarking is disabled. You can enable method benchmarking by setting the benchmark_methods configuration value."
53
- elsif benchmarkable_methods.size == 0
54
- puts "No methods benchmarked"
55
- else
56
- puts
57
- puts "#{separator}\n#{header_columns}\n#{separator}\n#{benchmarkable_methods.map {|method| method_columns(method)}.join("\n")}\n#{separator}"
58
- puts "#{benchmarkable_methods.size} methods defined in #{classes_count} classes across #{file_count} files. #{benchmarkable_methods.size - excluded_methods.size == 1 ? "1 method" : "#{benchmarkable_methods.size - excluded_methods.size} methods"} benchmarked."
59
- puts
60
- end
61
- end
62
-
63
- end
64
- end
65
- end
@@ -1,19 +0,0 @@
1
- module CopperEgg
2
- module APM
3
- class RevealCloud
4
-
5
- def self.installed?
6
- end
7
-
8
- def self.api_url
9
- end
10
-
11
- def self.api_key
12
- end
13
-
14
- def self.supports_instrumentation?
15
- end
16
-
17
- end
18
- end
19
- end
@@ -1,44 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/../spec/helpers/mysql2_setup'
3
- require 'copperegg/apm'
4
- require 'benchmark'
5
-
6
- CopperEgg::APM.configure do |config|
7
- config.instrument_key = "key"
8
- config.benchmark_sql = false
9
- end
10
-
11
- client = Mysql2::Client.new :host => "localhost", :database => "copperegg_apm_test", :username => ENV["MYSQL_USER"]
12
- sql = "UPDATE `users` SET `details` = '512.777.9311', `updated_at` = '#{Time.now.strftime('%Y-%m-%d %H:%M%S')}' WHERE `users`.`id` = 1"
13
- n = 10000
14
-
15
- puts "\nFor \"#{sql}\"\n\n"
16
-
17
- Benchmark.bm(31) do |x|
18
- x.report("#{n} queries w/o instrumentation") { n.times { client.query(sql) } }
19
- end
20
-
21
- puts
22
-
23
- CopperEgg::APM.configure do |config|
24
- config.instrument_key = "key"
25
- config.benchmark_sql = true
26
- end
27
-
28
- Benchmark.bm(31) do |x|
29
- x.report("#{n} queries w/ sql obfuscation") { n.times { client.query(sql) } }
30
- end
31
-
32
- puts
33
-
34
- # class String
35
- # def bytesize
36
- # 1025
37
- # end
38
- # end
39
-
40
- Benchmark.bm(31) do |x|
41
- x.report("#{n} queries w/o sql obfuscation") { n.times { client.query(sql) } }
42
- end
43
-
44
- puts