rackamole 0.3.1 → 0.3.2
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.
- data/HISTORY +6 -1
- data/lib/rackamole/mole.rb +38 -6
- data/lib/rackamole.rb +1 -1
- data/spec/rackamole/mole_spec.rb +60 -15
- metadata +2 -2
data/HISTORY
CHANGED
@@ -49,4 +49,9 @@
|
|
49
49
|
* Fixed issue with rails and params not being correctly recorded
|
50
50
|
|
51
51
|
0.3.1
|
52
|
-
* Bugs and cleanups
|
52
|
+
* Bugs and cleanups
|
53
|
+
|
54
|
+
0.3.2
|
55
|
+
* Fix issue with excluded_path being nil.
|
56
|
+
* Changed default excluded_path
|
57
|
+
* Added perf_excludes option to exempt alerts from being sent for known slower requests
|
data/lib/rackamole/mole.rb
CHANGED
@@ -47,9 +47,16 @@ module Rack
|
|
47
47
|
#
|
48
48
|
# :mole_excludes :: Exclude some of the paramaters that the mole would normaly include. The list of
|
49
49
|
# customizable paramaters is: software, ip, browser type, url, path, status, headers and body.
|
50
|
-
# This options takes an array of symbols. Defaults to [:body].
|
50
|
+
# This options takes an array of symbols. Defaults to [:body].
|
51
|
+
# :perf_excludes :: Specifies a set of paths that will be excluded when a performance issue is detected.
|
52
|
+
# This is useful when certain requests are known to be slow. When a match is found an
|
53
|
+
# alert won't be issued but the context will still be moled.
|
54
|
+
# ==
|
55
|
+
# Don't send an alert when perf is found on /blee/fred. Don't alert on /duh unless the request took longer than 10 secs
|
56
|
+
# :perf_excludes => [ {:context => '/blee/fred}, {:context => /^\/duh.*/, :threshold => 10 } ]
|
57
|
+
# ==
|
51
58
|
# :excluded_paths:: Exclude paths that you do not wish to mole by specifying an array of regular expresssions.
|
52
|
-
# :param_excludes:: Exempt
|
59
|
+
# :param_excludes:: Exempt certain sensitive request parameters from being logged to the mole. Specify an array of keys as
|
53
60
|
# as symbols ie [:password, :card_number].
|
54
61
|
# :session_excludes:: Exempt session params from being logged by the mole. Specify an array of keys as symbols
|
55
62
|
# ie [:fred, :blee] to exclude session[:fred] and session[:blee] from being stored.
|
@@ -126,7 +133,7 @@ module Rack
|
|
126
133
|
:log_level => :info,
|
127
134
|
:expiration => 60*60, # 1 hour
|
128
135
|
:environment => 'development',
|
129
|
-
:excluded_paths => [
|
136
|
+
:excluded_paths => [/.*?\/stylesheets\/.*/, /.*?\/javascripts\/.*/,/\.*?\/images\/.*/ ],
|
130
137
|
:mole_excludes => [:body],
|
131
138
|
:perf_threshold => 10.0,
|
132
139
|
:store => Rackamole::Store::Log.new
|
@@ -199,10 +206,34 @@ module Rack
|
|
199
206
|
|
200
207
|
# Check if we've seen this perf issue before. If so stash it
|
201
208
|
if attrs[:type] == Rackamole.perf
|
209
|
+
# Don't send alert if exempted
|
210
|
+
return true if perf_exempt?( attrs[:path], attrs[:request_time])
|
202
211
|
return stash.stash_perf( path, attrs[:request_time], now.utc )
|
203
212
|
end
|
204
213
|
end
|
205
214
|
|
215
|
+
# Check if request should be exempted from perf alert
|
216
|
+
def perf_exempt?( path, req_time )
|
217
|
+
return false unless option_defined?( :perf_excludes )
|
218
|
+
options[:perf_excludes].each do |hash|
|
219
|
+
context = hash[:context]
|
220
|
+
threshold = hash[:threshold]
|
221
|
+
time_trip = (threshold ? req_time <= threshold : true)
|
222
|
+
|
223
|
+
if context.is_a? String
|
224
|
+
return true if path == context and time_trip
|
225
|
+
elsif context.is_a? Regexp
|
226
|
+
return true if path.match(context) and time_trip
|
227
|
+
end
|
228
|
+
end
|
229
|
+
false
|
230
|
+
end
|
231
|
+
|
232
|
+
# Check if an option is defined
|
233
|
+
def option_defined?( key )
|
234
|
+
options.has_key?(key) and options[key]
|
235
|
+
end
|
236
|
+
|
206
237
|
# Check if an options is set and configured
|
207
238
|
def configured?( key, configs, optional=true )
|
208
239
|
return false if optional and !options.has_key?(key)
|
@@ -225,8 +256,10 @@ module Rack
|
|
225
256
|
|
226
257
|
# Check if this request should be moled according to the exclude filters
|
227
258
|
def mole_request?( request )
|
228
|
-
options[:excluded_paths]
|
229
|
-
|
259
|
+
if options.has_key?( :excluded_paths ) and options[:excluded_paths]
|
260
|
+
options[:excluded_paths].each do |exclude_path|
|
261
|
+
return false if request.path =~ exclude_path
|
262
|
+
end
|
230
263
|
end
|
231
264
|
true
|
232
265
|
end
|
@@ -329,7 +362,6 @@ module Rack
|
|
329
362
|
|
330
363
|
# check exclusion to see if the information should be moled
|
331
364
|
def mole?( key, stash, value )
|
332
|
-
# puts "Checking #{key} -- #{options[:mole_excludes].inspect}"
|
333
365
|
return stash[key] = value if !options[:mole_excludes] or options[:mole_excludes].empty?
|
334
366
|
stash[key] = (options[:mole_excludes].include?( key ) ? nil : value)
|
335
367
|
end
|
data/lib/rackamole.rb
CHANGED
data/spec/rackamole/mole_spec.rb
CHANGED
@@ -15,7 +15,6 @@ describe Rack::Mole do
|
|
15
15
|
@opts = {
|
16
16
|
:app_name => "Test App",
|
17
17
|
:environment => :test,
|
18
|
-
:excluded_paths => ['/should_bail'],
|
19
18
|
:perf_threshold => 0.1,
|
20
19
|
:user_key => :username,
|
21
20
|
:store => @test_store
|
@@ -66,7 +65,7 @@ describe Rack::Mole do
|
|
66
65
|
get "/", nil, @test_env
|
67
66
|
rescue
|
68
67
|
last_request.env['mole.stash'].should_not be_nil
|
69
|
-
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:
|
68
|
+
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:44:in `error_app'" )
|
70
69
|
fault.should_not be_nil
|
71
70
|
fault.count.should == 1
|
72
71
|
end
|
@@ -79,7 +78,7 @@ describe Rack::Mole do
|
|
79
78
|
get "/", nil, env
|
80
79
|
rescue
|
81
80
|
last_request.env['mole.stash'].should_not be_nil
|
82
|
-
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:
|
81
|
+
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:44:in `error_app'" )
|
83
82
|
fault.should_not be_nil
|
84
83
|
fault.count.should == i+1
|
85
84
|
env = last_request.env
|
@@ -95,7 +94,7 @@ describe Rack::Mole do
|
|
95
94
|
get "/#{i}", nil, env
|
96
95
|
rescue => boom
|
97
96
|
last_request.env['mole.stash'].should_not be_nil
|
98
|
-
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:
|
97
|
+
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:44:in `error_app'" )
|
99
98
|
fault.should_not be_nil
|
100
99
|
fault.count.should == i+1
|
101
100
|
env = last_request.env
|
@@ -103,7 +102,45 @@ describe Rack::Mole do
|
|
103
102
|
end
|
104
103
|
end
|
105
104
|
end
|
105
|
+
|
106
|
+
# ---------------------------------------------------------------------------
|
107
|
+
describe "perfomance exemptions" do
|
108
|
+
it "should exempt a string path correctly" do
|
109
|
+
rack = Rack::Mole.new( nil, :app_name => "test app", :perf_excludes => [ {:context => "/fred/blee" } ] )
|
110
|
+
rack.send( :perf_exempt?, "/fred/blee", 10 ).should == true
|
111
|
+
rack.send( :perf_exempt?, "/fred/blee1", 10 ).should == false
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should exempt a regex path correctly" do
|
115
|
+
rack = Rack::Mole.new( nil, :app_name => "test app", :perf_excludes => [ {:context => /^\/fred\/?.*/ } ] )
|
116
|
+
rack.send( :perf_exempt?, "/fred/blee", 10 ).should == true
|
117
|
+
rack.send( :perf_exempt?, "/fred", 10 ).should == true
|
118
|
+
rack.send( :perf_exempt?, "/fred/blee/bubba", 10 ).should == true
|
119
|
+
rack.send( :perf_exempt?, "/freud", 10 ).should == false
|
120
|
+
end
|
106
121
|
|
122
|
+
it "should exempt path with threshold correctly" do
|
123
|
+
rack = Rack::Mole.new( nil, :app_name => "test app", :perf_excludes => [ {:context => /^\/fred\/?.*/, :threshold => 15 } ] )
|
124
|
+
rack.send( :perf_exempt?, "/fred/blee", 10 ).should == true
|
125
|
+
rack.send( :perf_exempt?, "/fred/blee", 16 ).should == false
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should exempt an array of path correctly" do
|
129
|
+
excludes = [
|
130
|
+
{ :context => "/duh/1" , :threshold => 5 },
|
131
|
+
{ :context => /^\/fred\/?.*/, :threshold => 15 },
|
132
|
+
]
|
133
|
+
rack = Rack::Mole.new( nil, :app_name => "test app", :perf_excludes => excludes )
|
134
|
+
rack.send( :perf_exempt?, "/fred/blee", 10 ).should == true
|
135
|
+
rack.send( :perf_exempt?, "/crap/10/fred", 10 ).should == false
|
136
|
+
rack.send( :perf_exempt?, "/fred/blee", 16 ).should == false
|
137
|
+
|
138
|
+
rack.send( :perf_exempt?, "/duh/1", 5 ).should == true
|
139
|
+
rack.send( :perf_exempt?, "/duh/1", 6 ).should == false
|
140
|
+
rack.send( :perf_exempt?, "/duh/2", 6 ).should == false
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
107
144
|
# ---------------------------------------------------------------------------
|
108
145
|
describe "performance duplicate" do
|
109
146
|
before( :each ) do
|
@@ -156,7 +193,7 @@ describe Rack::Mole do
|
|
156
193
|
rescue
|
157
194
|
@test_store.mole_result[:stack].should have(4).items
|
158
195
|
last_request.env['mole.stash'].should_not be_nil
|
159
|
-
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:
|
196
|
+
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:44:in `error_app'" )
|
160
197
|
fault.should_not be_nil
|
161
198
|
fault.count.should == 1
|
162
199
|
end
|
@@ -236,7 +273,7 @@ describe Rack::Mole do
|
|
236
273
|
@test_store.mole_result[:stack].should have(4).items
|
237
274
|
@test_store.mole_result[:fault].should == 'Oh snap!'
|
238
275
|
last_request.env['mole.stash'].should_not be_nil
|
239
|
-
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:
|
276
|
+
fault = last_request.env['mole.stash'].send( :find_fault, "/", "./spec/rackamole/mole_spec.rb:268" )
|
240
277
|
fault.should_not be_nil
|
241
278
|
fault.count.should == 1
|
242
279
|
end
|
@@ -246,8 +283,16 @@ describe Rack::Mole do
|
|
246
283
|
get "/", { :blee => 'duh' }, @test_env
|
247
284
|
@test_store.mole_result[:params].should == { :blee => "duh".to_json }
|
248
285
|
end
|
286
|
+
|
287
|
+
it "should not mole a standard exclusion" do
|
288
|
+
%w(/stylesheets/style.css /javascripts/blee.js /images/fred.png).each do |path|
|
289
|
+
get path, nil, @test_env
|
290
|
+
@test_store.mole_result.should be_nil
|
291
|
+
end
|
292
|
+
end
|
249
293
|
|
250
|
-
it "should not mole
|
294
|
+
it "should not mole a custom exclusion" do
|
295
|
+
@opts[:excluded_paths] = [/\/should_bail/]
|
251
296
|
get '/should_bail', nil, @test_env
|
252
297
|
@test_store.mole_result.should be_nil
|
253
298
|
end
|
@@ -274,15 +319,15 @@ describe Rack::Mole do
|
|
274
319
|
describe "rails env" do
|
275
320
|
it "should find route info correctly" do
|
276
321
|
pending do
|
277
|
-
|
278
|
-
|
279
|
-
|
322
|
+
RAILS_ENV = true
|
323
|
+
ActionController::Routing::Routes.stub!( :recognize_path ).and_return( { :controller => 'fred', :action => 'blee' } )
|
324
|
+
rack = Rack::Mole.new( nil, :app_name => "test app" )
|
280
325
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
326
|
+
# routes.should_receive( 'recognize_path' ).with( 'fred', { :method => 'blee' } ).and_return( )
|
327
|
+
res = rack.send( :get_route, OpenStruct.new( :path => "/", :request_method => "GET") )
|
328
|
+
res.should_not be_nil
|
329
|
+
res[:controller].should == 'fred'
|
330
|
+
res[:action].should == 'blee'
|
286
331
|
end
|
287
332
|
end
|
288
333
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rackamole
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fernand Galiana
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-02-
|
12
|
+
date: 2010-02-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|