copperegg-apm 1.0.0.pre1 → 1.0.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53c18884499d7d5cb6bcbc25cf3343c60347926d
4
- data.tar.gz: db57ee020032965afd5b93c00379a66faf594580
3
+ metadata.gz: 01666a19555290a47e741f5884e7afe8b5e5c0c7
4
+ data.tar.gz: a0f33f3a3ed6913846fc8c28dbcd767f5b23a19b
5
5
  SHA512:
6
- metadata.gz: 334e0e654618769b5bf5c524c092e7585cd9ebf7700ba3e0f87c8f042876a7a614f2b2e2033f2918a9c1bf01e4b7ab857429c1f7380fdd2625e9f0c94000f10c
7
- data.tar.gz: ac15445e1ec1e33cc262a58c97d133e8b2c0e854b3d0d10738e234ae12b79cc4e8db5f835c658fd5d3fe37f49560c0781b205845c91952317b95b48d060bd4e2
6
+ metadata.gz: a571b109adf12783cae3e8c3ae67704eee8590dcf8e6d0a28c29166c17acb1a19711d60c0cd1f0ec938e93ebc8c5291d66f4c6f82455ae16939cea13d3c56ca5
7
+ data.tar.gz: 48ed4e805a26421b8bd3260e78f4b20833e8a60d855dac893613d7818b1479358069a245f5bd5df2bd4abd7b3bfcf9ce8935e0b732e1c9d5a9a37fa56a32e271
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- copperegg-apm (1.0.0.pre1)
4
+ copperegg-apm (1.0.0.pre2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -62,17 +62,17 @@ end
62
62
 
63
63
  ### Automatic Method Benchmarking
64
64
 
65
- For performance reasons, automatic method benchmarking is disabled by default. When enabled, *CopperEgg::APM* intelligently adds benchmarking to public and protected methods defined within your codebase. By default, methods whose names begin with an underscore (_) or end with a question mark (?) are not benchmarked.
65
+ For performance reasons, automatic method benchmarking is disabled by default. When enabled, `CopperEgg::APM` intelligently adds benchmarking to public and protected methods defined within your codebase. By default, methods whose names begin with an underscore (_) or end with a question mark (?) are not benchmarked.
66
66
 
67
67
  #### Configuring Automatic Method Benchmarking
68
68
 
69
- Automatic method benchmarking is enabled by calling `config.benchmark_methods` within the configuration block. It expects a level which is represented by a symbol whose value is either :disabled, :basic, :moderate, :full, or :custom.
69
+ Automatic method benchmarking is enabled by calling `config.benchmark_methods` within the configuration block. It expects a level which is represented by a symbol whose value is either `:disabled`, `:basic`, `:moderate`, `:full`, or `:custom`.
70
70
 
71
- The levls *basic* and *moderate* are Rails-specific. With the *basic* level only controller methods are automatically benchmarked. The *moderate* level benchmarks all controller methods as well as methods of classes that descend from *ActiveRecord::Base*. Note that for controller actions, benchmarks also include rendering time.
71
+ The levels `:basic` and `:moderate` are Rails-specific. With the `:basic` level only controller methods are automatically benchmarked. The `:moderate` level benchmarks all controller methods as well as methods of classes that descend from *ActiveRecord::Base*. Note that for controller actions, benchmarks also include rendering time.
72
72
 
73
- A level *full* benchmarks all methods within your project. For non-Rails projects, the *basic* and *moderate* levels will behave like the *full* level.
73
+ A level `:full` benchmarks all methods within your project. For non-Rails projects, the `:basic` and `:moderate` levels will behave like the `:full` level.
74
74
 
75
- The *custom* level allows you to explicitly set which methods to benchmark. When setting `benchmark_methods` to :custom a second argument is expected which is an array of strings representing the methods to benchmark. The format of these strings is explained in the following section.
75
+ The `:custom` level allows you to explicitly set which methods to benchmark. When setting `benchmark_methods` to :custom a second argument is expected which is an array of strings representing the methods to benchmark. The format of these strings is explained in the following section.
76
76
 
77
77
  #### Inclusions and Exclusions
78
78
 
@@ -80,15 +80,15 @@ With automatic method benchmarking enabled, you can fine-tune the list of method
80
80
 
81
81
  The hash must have keys named either :include or :exclude which are set to an array of strings.
82
82
 
83
- Each string in these arrays must follow the pattern *Class.class_method*, *Class#instance_method*, *Class*, or *method_name*.
83
+ Each string in these arrays must follow the pattern *method_name*, *Class*, *ClassNameSpace::*, *Class.class_method*, *Class#instance_method*.
84
84
 
85
85
  The following is an example configuration that only benchmarks a discreet set of methods:
86
86
 
87
87
  ```ruby
88
- config.benchmark_methods :custom, %w(User.authenticate! run)
88
+ config.benchmark_methods :custom, %w(User.authenticate! run MyApp::)
89
89
  ```
90
90
 
91
- In the example above, the only methods benchmarked will be the method 'authenticate!' in class 'User' and any method named 'run' in any instance or class defined in your project.
91
+ In the example above, the only methods benchmarked will be the method 'authenticate!' in class 'User', any method named 'run' in any instance or class defined in your project, and any method defined in a class having a namespace 'MyApp::'. So any method defined in a class named MyApp::MiddleWare or Api::MyApp::StatisticsController would be benchmarked.
92
92
 
93
93
  By contrast, you can benchmark all methods defined in your project except for a discreet set:
94
94
 
@@ -160,15 +160,11 @@ When exception benchmarking is enabled, any exception raised in your project wil
160
160
 
161
161
  ## Disable Gem Functionality
162
162
 
163
- To temporarily disable all functionality of this gem, set all `config.benchmark_` values to false in the configuration file and then restart your application:
163
+ To disable all functionality of this gem, call `config.disable` in the configuration block and then restart your application:
164
164
 
165
165
  ```ruby
166
166
  CopperEgg::APM.configure do |config|
167
- config.instrument_key = "IOFiZ4cslRiV5SXl"
168
- config.benchmark_sql = false
169
- config.benchmark_http = false
170
- config.benchmark_exceptions = false
171
- config.benchmark_methods = false
167
+ config.disable
172
168
  end
173
169
  ```
174
170
 
Binary file
data/lib/copperegg/apm.rb CHANGED
@@ -7,7 +7,6 @@ end
7
7
 
8
8
  %w(
9
9
  benchmark
10
- action_controller/base
11
10
  active_record/connection_adapters/abstract_adapter
12
11
  configuration
13
12
  errors
@@ -25,4 +24,4 @@ end
25
24
  version
26
25
  ).each { |file| require "copperegg/apm/#{file}" }
27
26
 
28
- require 'copperegg/apm/engine' if defined?(::Rails::Engine)
27
+ require 'copperegg/apm/engine' if defined?(::Rails::Engine)
@@ -24,6 +24,7 @@ module CopperEgg
24
24
  @@exclude_methods = []
25
25
  @@include_methods = []
26
26
  @@logger = nil
27
+ @@disabled = false
27
28
 
28
29
  def self.udp_port
29
30
  @@udp_port
@@ -151,6 +152,10 @@ module CopperEgg
151
152
  end
152
153
  end
153
154
 
155
+ def self.disable
156
+ @@disabled = true
157
+ end
158
+
154
159
  def self.configure(&block)
155
160
  yield(self)
156
161
 
@@ -162,7 +167,15 @@ module CopperEgg
162
167
  end
163
168
  end
164
169
 
165
- CopperEgg::APM.add_method_benchmarking if @@benchmark_methods_level != :disabled
170
+ if @@disabled
171
+ @@benchmark_sql = @@benchmark_active_record = @@benchmark_http = @@benchmark_exceptions = false
172
+ @@benchmark_methods_level = :disabled
173
+ @@only_methods = []
174
+ @@exclude_methods = []
175
+ @@include_methods = []
176
+ elsif @@benchmark_methods_level != :disabled
177
+ CopperEgg::APM.add_method_benchmarking
178
+ end
166
179
  end
167
180
 
168
181
  class <<self
@@ -20,6 +20,10 @@ module CopperEgg
20
20
  parent_class.instance_methods.include?("#{name}=".to_sym)
21
21
  end
22
22
 
23
+ def name_begins_with_underscore_or_ends_with_question_mark?
24
+ name =~ /\A_/ || name =~ /\A[\w\d]+\?\z/
25
+ end
26
+
23
27
  def source_filename
24
28
  @source_filename ||= if respond_to?(:source_location)
25
29
  source_location.to_a.first
@@ -39,7 +43,11 @@ module CopperEgg
39
43
  def display_filename
40
44
  return @display_filename if @display_filename
41
45
  @display_filename = "#{source_filename}:#{source_line}"
42
- @display_filename.sub! CopperEgg::APM::Configuration.app_root, "..."
46
+
47
+ if defined?(::Rails)
48
+ @display_filename.sub!(::Rails.configuration.root.to_s, "...")
49
+ end
50
+ @display_filename
43
51
  end
44
52
 
45
53
  def display_name
@@ -86,6 +94,9 @@ module CopperEgg
86
94
  return false if CopperEgg::APM::Configuration.only_methods.include?(parent_class.to_s)
87
95
  return false if CopperEgg::APM::Configuration.only_methods.include?(display_name)
88
96
  return false if CopperEgg::APM::Configuration.only_methods.include?(name)
97
+ CopperEgg::APM::Configuration.only_methods.each do |value|
98
+ return false if value =~ /::\Z/ && parent_class.to_s.include?(value)
99
+ end
89
100
 
90
101
  if CopperEgg::APM::Configuration.only_methods.length > 0
91
102
  return true if !CopperEgg::APM::Configuration.only_methods.include?(parent_class.to_s) && !CopperEgg::APM::Configuration.only_methods.include?(display_name) && !CopperEgg::APM::Configuration.only_methods.include?(name)
@@ -94,13 +105,18 @@ module CopperEgg
94
105
  return true if CopperEgg::APM::Configuration.exclude_methods.include?(parent_class.to_s)
95
106
  return true if CopperEgg::APM::Configuration.exclude_methods.include?(display_name)
96
107
  return true if CopperEgg::APM::Configuration.exclude_methods.include?(display_name)
108
+ CopperEgg::APM::Configuration.exclude_methods.each do |value|
109
+ return true if value =~ /::\Z/ && parent_class.to_s.include?(value)
110
+ end
97
111
 
98
- return false if CopperEgg::APM::Configuration.include_methods.include?(parent_class.to_s)
112
+ return false if CopperEgg::APM::Configuration.include_methods.include?(parent_class.to_s) && !name_begins_with_underscore_or_ends_with_question_mark?
99
113
  return false if CopperEgg::APM::Configuration.include_methods.include?(display_name)
100
114
  return false if CopperEgg::APM::Configuration.include_methods.include?(name)
115
+ CopperEgg::APM::Configuration.include_methods.each do |value|
116
+ return false if value =~ /::\Z/ && parent_class.to_s.include?(value) && !name_begins_with_underscore_or_ends_with_question_mark?
117
+ end
101
118
 
102
- return true if name =~ /\A_/
103
- return true if name =~ /\A[\w\d]+\?\z/
119
+ return true if name_begins_with_underscore_or_ends_with_question_mark?
104
120
 
105
121
  return false if benchmark_levels.include?(CopperEgg::APM::Configuration.benchmark_methods_level)
106
122
 
@@ -1,5 +1,5 @@
1
1
  module CopperEgg
2
2
  module APM
3
- GEM_VERSION = '1.0.0.pre1'
3
+ GEM_VERSION = '1.0.0.pre2'
4
4
  end
5
5
  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 File.dirname(__FILE__) + '/helpers/rails'
4
3
  require 'spec_helper'
4
+ require File.dirname(__FILE__) + '/helpers/rails'
5
5
 
6
6
  RSpec.configure do |c|
7
7
  c.infer_base_class_for_anonymous_controllers = true
@@ -11,16 +11,10 @@ class ApplicationController < ActionController::Base
11
11
  include Rails.application.routes.url_helpers
12
12
  end
13
13
 
14
- class ExceptionController < ApplicationController; end
15
-
16
- class BenchmarkAllActionsController < ApplicationController; end
17
-
18
- class BenchmarkOnlyActionsController < ApplicationController; end
14
+ class ApplicationControllerSubclass < ApplicationController; end
19
15
 
20
- class BenchmarkExceptActionsController < ApplicationController; end
21
-
22
- describe ExceptionController, :type => :controller do
23
- controller(ExceptionController) do
16
+ describe ApplicationControllerSubclass, :type => :controller do
17
+ controller(ApplicationControllerSubclass) do
24
18
  def index
25
19
  @count = 1/0
26
20
  end
@@ -35,105 +29,8 @@ describe ExceptionController, :type => :controller do
35
29
  expect(hash.keys.sort).to eq ["excp", "id"]
36
30
  expect(hash["id"]).to match(/\A[0-1a-z]{16}\z/i)
37
31
  expect(hash["excp"].keys.sort).to eq ["error", "stacktrace", "ts"]
38
- expect(hash["excp"]["error"]).to match(/\AZeroDivisionError\|/)
39
- expect(hash["excp"]["error"]).to match(/\{Ruby\}\Z/)
32
+ expect(hash["excp"]["error"]).to match(/ZeroDivisionError\|/)
40
33
  expect(hash["excp"]["stacktrace"]).to match(/\Adivided by 0\n/)
41
34
  expect(hash["excp"]["ts"]).to be_an_instance_of(Fixnum)
42
35
  end
43
36
  end
44
-
45
- describe BenchmarkAllActionsController, :type => :controller do
46
- controller(BenchmarkAllActionsController) do
47
- add_benchmarks
48
-
49
- def index
50
- 100.times.reduce(:+)
51
- render :nothing => true
52
- end
53
- alias_method :create, :index
54
- end
55
-
56
- it "should benchmark all actions" do
57
- get :index
58
-
59
- last_payload = CopperEgg::APM.send(:class_variable_get, :@@payload_cache).split("\x00").select {|i| i.size > 2}.map {|i| i.sub(/^[^\{]+/,'')}.last
60
- hash = JSON.parse last_payload
61
-
62
- expect(hash.keys.sort).to eq ["id", "inst"]
63
- expect(hash["id"]).to match(/\A[0-1a-z]{16}\z/i)
64
- expect(hash["inst"].keys.sort).to eq ["method", "time"]
65
- expect(hash["inst"]["method"]).to match(/#index \{Ruby\}/)
66
- expect(hash["inst"]["time"].to_s).to match(/\A\d+\Z/)
67
-
68
- post :create
69
-
70
- last_payload = CopperEgg::APM.send(:class_variable_get, :@@payload_cache).split("\x00").select {|i| i.size > 2}.map {|i| i.sub(/^[^\{]+/,'')}.last
71
- hash = JSON.parse last_payload
72
-
73
- expect(hash["inst"]["method"]).to match(/#create \{Ruby\}/)
74
- end
75
- end
76
-
77
- describe BenchmarkOnlyActionsController, :type => :controller do
78
- controller(BenchmarkOnlyActionsController) do
79
- add_benchmarks :only => [:index]
80
-
81
- def index
82
- 100.times.reduce(:+)
83
- render :nothing => true
84
- end
85
- alias_method :create, :index
86
- end
87
-
88
- it "should benchmark all actions" do
89
- get :index
90
-
91
- last_payload = CopperEgg::APM.send(:class_variable_get, :@@payload_cache).split("\x00").select {|i| i.size > 2}.map {|i| i.sub(/^[^\{]+/,'')}.last
92
- hash = JSON.parse last_payload
93
-
94
- expect(hash.keys.sort).to eq ["id", "inst"]
95
- expect(hash["id"]).to match(/\A[0-1a-z]{16}\z/i)
96
- expect(hash["inst"].keys.sort).to eq ["method", "time"]
97
- expect(hash["inst"]["method"]).to match(/#index \{Ruby\}/)
98
- expect(hash["inst"]["time"].to_s).to match(/\A\d+\Z/)
99
-
100
- post :create
101
-
102
- last_payload = CopperEgg::APM.send(:class_variable_get, :@@payload_cache).split("\x00").select {|i| i.size > 2}.map {|i| i.sub(/^[^\{]+/,'')}.last
103
- hash = JSON.parse last_payload
104
-
105
- expect(hash["inst"]["method"]).to match(/#index \{Ruby\}/)
106
- end
107
- end
108
-
109
- describe BenchmarkExceptActionsController, :type => :controller do
110
- controller(BenchmarkExceptActionsController) do
111
- add_benchmarks :except => [:create]
112
-
113
- def index
114
- 100.times.reduce(:+)
115
- render :nothing => true
116
- end
117
- alias_method :create, :index
118
- end
119
-
120
- it "should benchmark all actions" do
121
- get :index
122
-
123
- last_payload = CopperEgg::APM.send(:class_variable_get, :@@payload_cache).split("\x00").select {|i| i.size > 2}.map {|i| i.sub(/^[^\{]+/,'')}.last
124
- hash = JSON.parse last_payload
125
-
126
- expect(hash.keys.sort).to eq ["id", "inst"]
127
- expect(hash["id"]).to match(/\A[0-1a-z]{16}\z/i)
128
- expect(hash["inst"].keys.sort).to eq ["method", "time"]
129
- expect(hash["inst"]["method"]).to match(/#index \{Ruby\}/)
130
- expect(hash["inst"]["time"].to_s).to match(/\A\d+\Z/)
131
-
132
- post :create
133
-
134
- last_payload = CopperEgg::APM.send(:class_variable_get, :@@payload_cache).split("\x00").select {|i| i.size > 2}.map {|i| i.sub(/^[^\{]+/,'')}.last
135
- hash = JSON.parse last_payload
136
-
137
- expect(hash["inst"]["method"]).to match(/#index \{Ruby\}/)
138
- end
139
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copperegg-apm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre1
4
+ version: 1.0.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Bradford
@@ -189,13 +189,11 @@ files:
189
189
  - ./bin/copperegg-apm-init
190
190
  - ./bin/copperegg-apm-methods
191
191
  - ./CHANGELOG.md
192
- - ./copperegg-apm-1.0.0.pre1.gem
193
192
  - ./copperegg-apm.gemspec
194
193
  - ./copperegg_apm_test.db
195
194
  - ./ext/mkrf_conf.rb
196
195
  - ./Gemfile
197
196
  - ./Gemfile.lock
198
- - ./lib/copperegg/apm/action_controller/base.rb
199
197
  - ./lib/copperegg/apm/active_record/connection_adapters/abstract_adapter.rb
200
198
  - ./lib/copperegg/apm/benchmark.rb
201
199
  - ./lib/copperegg/apm/benchmark_methods_table.rb
@@ -204,7 +202,6 @@ files:
204
202
  - ./lib/copperegg/apm/errors.rb
205
203
  - ./lib/copperegg/apm/ethon/easy/operations.rb
206
204
  - ./lib/copperegg/apm/kernel.rb
207
- - ./lib/copperegg/apm/middleware.rb
208
205
  - ./lib/copperegg/apm/mysql.rb
209
206
  - ./lib/copperegg/apm/mysql2/client.rb
210
207
  - ./lib/copperegg/apm/net/http.rb
@@ -294,7 +291,7 @@ rubyforge_project:
294
291
  rubygems_version: 2.0.3
295
292
  signing_key:
296
293
  specification_version: 4
297
- summary: copperegg-apm-1.0.0.pre1
294
+ summary: copperegg-apm-1.0.0.pre2
298
295
  test_files:
299
296
  - spec/action_controller_spec.rb
300
297
  - spec/apm_spec.rb
Binary file
@@ -1,31 +0,0 @@
1
- module CopperEgg
2
- module APM
3
- module ActionController
4
- module Base
5
- def self.included(klass)
6
- klass.class_eval do
7
- def self.add_benchmarks(options={})
8
- raise ArgumentError.new("hash expected") if !options.is_a?(Hash)
9
- around_filter :ce_benchmark_controller_actions, options
10
- end
11
-
12
- def ce_benchmark_controller_actions
13
- starttime = (Time.now.to_f * 1000.0).to_i
14
- yield
15
- time = (Time.now.to_f * 1000.0).to_i - starttime
16
- CopperEgg::APM.send_payload({:method => "#{self.to_s.sub!(/:[a-z0-9]x[^>]+>/, "").sub!("#<","")}##{action_name}", :time => time})
17
- end
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
24
-
25
- if defined?(::ActionController::Base)
26
-
27
- class ActionController::Base
28
- include CopperEgg::APM::ActionController::Base
29
- end
30
-
31
- end
@@ -1,20 +0,0 @@
1
- module CopperEgg
2
- module APM
3
- class Middleware
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