rack-request-profiler 0.1.0 → 0.1.1
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/.gitignore +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/README.md +2 -0
- data/Rakefile +4 -0
- data/lib/rack/request-profiler.rb +3 -1
- data/lib/rack/request-profiler/version.rb +1 -1
- data/spec/rack/profilers/stathat_spec.rb +7 -2
- data/spec/rack/profilers/statsd_spec.rb +18 -6
- data/spec/rack/request-profiler_spec.rb +23 -18
- data/spec/spec_helper.rb +2 -0
- metadata +5 -3
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
source :rubygems
|
2
2
|
|
3
|
+
gem 'rake'
|
4
|
+
|
3
5
|
group :test do
|
4
6
|
gem 'em-stathat'
|
7
|
+
gem 'mocha'
|
5
8
|
gem 'rack'
|
6
9
|
gem 'rspec', '>= 2.7'
|
7
10
|
gem 'rack-test', :require => 'rack/test'
|
11
|
+
gem 'sinatra', :require => 'sinatra/base'
|
8
12
|
gem 'statsd-ruby', :require => 'statsd'
|
9
13
|
end
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](http://travis-ci.org/ajsharp/rack-request-profiler)
|
2
|
+
|
1
3
|
This project provides a simple "framework" for profiling request / response times, and sending the data to another service. It includes a base class `Rack::RequestProfiler` for handling the logic of wrapping and timing the request / response cycle in a rack app.
|
2
4
|
|
3
5
|
By default, the `Rack::RequestProfiler` middleware does not do anything with the profiling data. Instead, this logic must be implemented by subclasses by defining the `handle_results` instance method. For example, you might send profiling data to an external web service (stathat, papertrail, loggly, etc), statsd, write to a logfile on disk, put it in a persistent store like redis or mongo, or really anything else your heart desires.
|
data/Rakefile
ADDED
@@ -4,11 +4,16 @@ describe Rack::Profilers::Stathat do
|
|
4
4
|
it "accepts callbacks" do
|
5
5
|
EM.run {
|
6
6
|
app = Rack::Builder.app do
|
7
|
-
use Rack::Profilers::Stathat, :callback => lambda { |req|
|
7
|
+
use Rack::Profilers::Stathat, :callback => lambda { |req| }
|
8
8
|
|
9
9
|
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['']]}
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
|
+
deferrable = mock("Deferrable")
|
13
|
+
deferrable.expects(:callback).returns(EM.stop)
|
14
|
+
EM::StatHat.any_instance.expects(:ez_value).returns(deferrable)
|
15
|
+
|
16
|
+
Rack::MockRequest.new(app).get('/zomg/this/is/a/test')
|
12
17
|
}
|
13
18
|
end
|
14
19
|
end
|
@@ -2,26 +2,38 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Rack::Profilers::Statsd do
|
4
4
|
include Rack::Test::Methods
|
5
|
-
$statsd = Statsd.new 'localhost'
|
6
5
|
|
7
6
|
it "sends stuff to statsd" do
|
7
|
+
statsd = Statsd.new 'localhost'
|
8
8
|
app = Rack::Builder.app do
|
9
|
-
use Rack::Profilers::Statsd,
|
9
|
+
use Rack::Profilers::Statsd, statsd
|
10
10
|
run lambda { |env| [200, {}, ['']]}
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
$statsd.should_receive(:timing)
|
13
|
+
statsd.expects(:timing)
|
15
14
|
response = Rack::MockRequest.new(app).get('/')
|
16
15
|
end
|
17
16
|
|
18
17
|
it "does not send stuff for ignored paths" do
|
18
|
+
statsd = Statsd.new 'localhost'
|
19
19
|
app = Rack::Builder.app do
|
20
|
-
use Rack::Profilers::Statsd,
|
20
|
+
use Rack::Profilers::Statsd, statsd, :ignore_path => /ignore-me/
|
21
21
|
run lambda { |env| [200, {}, ['']]}
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
statsd.expects(:timing).never
|
25
25
|
Rack::MockRequest.new(app).get('/ignore-me')
|
26
26
|
end
|
27
|
+
|
28
|
+
it "prepends the namespace if passed in" do
|
29
|
+
statsd = Statsd.new 'localhost'
|
30
|
+
app = Rack::Builder.app do
|
31
|
+
use Rack::Profilers::Statsd, statsd, :namespace => 'namespace.me.'
|
32
|
+
run lambda { |env| [200, {}, ['']]}
|
33
|
+
end
|
34
|
+
|
35
|
+
Rack::Profilers::Statsd.any_instance.stubs(:run_time => 200)
|
36
|
+
statsd.expects(:timing).with('namespace.me.GET.', 200)
|
37
|
+
Rack::MockRequest.new(app).get('/')
|
38
|
+
end
|
27
39
|
end
|
@@ -2,34 +2,39 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Rack::RequestProfiler do
|
4
4
|
include Rack::Test::Methods
|
5
|
+
class MockApp < Sinatra::Base
|
6
|
+
use Rack::RequestProfiler, :ignore_path => /ignore_me/
|
7
|
+
get '/' do
|
8
|
+
[200, "Hello, world"]
|
9
|
+
end
|
5
10
|
|
6
|
-
|
7
|
-
|
11
|
+
get '/ignore_me' do
|
12
|
+
[200, "Ignore me"]
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
16
|
+
def app
|
17
|
+
@app ||= Rack::Builder.app do
|
18
|
+
run MockApp
|
14
19
|
end
|
15
|
-
|
16
|
-
use Rack::CustomProfiler
|
20
|
+
end
|
17
21
|
|
18
|
-
|
19
|
-
|
22
|
+
it "implements the handle_results interface" do
|
23
|
+
Rack::RequestProfiler.new(lambda {}).should respond_to :handle_results
|
24
|
+
end
|
20
25
|
|
21
|
-
|
26
|
+
it "invokes the handle_results interface" do
|
27
|
+
Rack::RequestProfiler.any_instance.expects(:handle_results).once
|
22
28
|
Rack::MockRequest.new(app).get('/')
|
23
29
|
end
|
24
30
|
|
25
31
|
it "does not invoke handle_results if ignore_path matches" do
|
26
|
-
|
27
|
-
use Rack::RequestProfiler, :ignore_path => /ignore_me/
|
28
|
-
|
29
|
-
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['']]}
|
30
|
-
end
|
31
|
-
|
32
|
-
Rack::RequestProfiler.any_instance.should_not_receive(:handle_results)
|
32
|
+
Rack::RequestProfiler.any_instance.expects(:handle_results).never
|
33
33
|
Rack::MockRequest.new(app).get('/ignore_me')
|
34
34
|
end
|
35
|
+
|
36
|
+
it "does not invoke handlers if the status is 404" do
|
37
|
+
Rack::RequestProfiler.any_instance.expects(:handle_results).never
|
38
|
+
Rack::MockRequest.new(app).get('/does/not/exist')
|
39
|
+
end
|
35
40
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,7 @@ require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'rack-r
|
|
4
4
|
|
5
5
|
require 'rack/test'
|
6
6
|
require 'em-stathat'
|
7
|
+
require 'sinatra/base'
|
7
8
|
|
8
9
|
EventMachine::StatHat.config do |c|
|
9
10
|
c.ukey = 'key'
|
@@ -11,4 +12,5 @@ EventMachine::StatHat.config do |c|
|
|
11
12
|
end
|
12
13
|
|
13
14
|
RSpec.configure do |config|
|
15
|
+
config.mock_with :mocha
|
14
16
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-request-profiler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-10 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Provides a framework for sending wall time statistics to external services,
|
15
15
|
such as statsd, stathat, etc.
|
@@ -20,8 +20,10 @@ extensions: []
|
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
22
|
- .gitignore
|
23
|
+
- .travis.yml
|
23
24
|
- Gemfile
|
24
25
|
- README.md
|
26
|
+
- Rakefile
|
25
27
|
- lib/rack-request-profiler.rb
|
26
28
|
- lib/rack/profilers/stathat.rb
|
27
29
|
- lib/rack/profilers/statsd.rb
|
@@ -54,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
56
|
version: '0'
|
55
57
|
requirements: []
|
56
58
|
rubyforge_project:
|
57
|
-
rubygems_version: 1.8.
|
59
|
+
rubygems_version: 1.8.15
|
58
60
|
signing_key:
|
59
61
|
specification_version: 3
|
60
62
|
summary: Rack middleware for profiling request / response cycles.
|