ecin-rack-probe 0.0.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/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/rack-probe.rb +3 -0
- data/lib/rack/probe.rb +47 -0
- data/rack-probe.gemspec +60 -0
- data/spec/rack/probe_spec.rb +114 -0
- data/spec/spec_helper.rb +14 -0
- metadata +95 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 ecin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= rack-probe
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 ecin. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rack-probe"
|
8
|
+
gem.summary = %Q{Rack::Probe adds Dtrace probes to your Rack apps.}
|
9
|
+
gem.description = %Q{Rack::Probe provides a set of probes for Rack that fire with each request.}
|
10
|
+
gem.email = "ecin@copypastel.com"
|
11
|
+
gem.homepage = "http://github.com/ecin/rack-probe"
|
12
|
+
gem.authors = ["ecin"]
|
13
|
+
gem.add_dependency "ruby-dtrace", ">= 0.2.8"
|
14
|
+
gem.add_dependency "rack", ">= 1.0.0"
|
15
|
+
gem.add_development_dependency "rspec"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
if File.exist?('VERSION')
|
41
|
+
version = File.read('VERSION')
|
42
|
+
else
|
43
|
+
version = ""
|
44
|
+
end
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "rack-probe #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/lib/rack-probe.rb
ADDED
data/lib/rack/probe.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
class Symbol
|
2
|
+
unless instance_methods.include? :to_proc
|
3
|
+
def to_proc
|
4
|
+
Proc.new { |obj, *args| obj.send(self, *args) }
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Rack
|
10
|
+
class Probe
|
11
|
+
|
12
|
+
gem 'ruby-dtrace', '>= 0.2.7'
|
13
|
+
require 'dtrace/provider'
|
14
|
+
|
15
|
+
Dtrace::Provider.create :rack do |p|
|
16
|
+
p.probe :get # GET request
|
17
|
+
p.probe :post # POST request
|
18
|
+
p.probe :put # PUT request
|
19
|
+
p.probe :delete # DELETE request
|
20
|
+
p.probe :ip, :string # IP of the requester
|
21
|
+
p.probe :path, :string # Path visited
|
22
|
+
p.probe :referer, :string # Referer
|
23
|
+
p.probe :xhr # AJAX request
|
24
|
+
end
|
25
|
+
|
26
|
+
# Provider shortcut
|
27
|
+
R = Dtrace::Probe::Rack
|
28
|
+
|
29
|
+
def initialize( app, opts = {} )
|
30
|
+
@app = app
|
31
|
+
end
|
32
|
+
|
33
|
+
def call( env )
|
34
|
+
request = Rack::Request.new env
|
35
|
+
R.get(&:fire) if request.get?
|
36
|
+
R.post(&:fire) if request.post?
|
37
|
+
R.put(&:fire) if request.put?
|
38
|
+
R.delete(&:fire) if request.delete?
|
39
|
+
R.xhr(&:fire) if request.xhr?
|
40
|
+
R.path { |p| p.fire(request.path) }
|
41
|
+
R.ip { |p| p.fire(request.ip) }
|
42
|
+
R.referer { |p| p.fire(request.referer) }
|
43
|
+
@app.call env
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/rack-probe.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rack-probe}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["ecin"]
|
12
|
+
s.date = %q{2009-08-15}
|
13
|
+
s.description = %q{Rack::Probe provides a set of probes for Rack that fire with each request.}
|
14
|
+
s.email = %q{ecin@copypastel.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/rack-probe.rb",
|
27
|
+
"lib/rack/probe.rb",
|
28
|
+
"rack-probe.gemspec",
|
29
|
+
"spec/rack/probe_spec.rb",
|
30
|
+
"spec/spec_helper.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/ecin/rack-probe}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.5}
|
36
|
+
s.summary = %q{Rack::Probe adds Dtrace probes to your Rack apps.}
|
37
|
+
s.test_files = [
|
38
|
+
"spec/rack/probe_spec.rb",
|
39
|
+
"spec/spec_helper.rb"
|
40
|
+
]
|
41
|
+
|
42
|
+
if s.respond_to? :specification_version then
|
43
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<ruby-dtrace>, [">= 0.2.8"])
|
48
|
+
s.add_runtime_dependency(%q<rack>, [">= 1.0.0"])
|
49
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
50
|
+
else
|
51
|
+
s.add_dependency(%q<ruby-dtrace>, [">= 0.2.8"])
|
52
|
+
s.add_dependency(%q<rack>, [">= 1.0.0"])
|
53
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
54
|
+
end
|
55
|
+
else
|
56
|
+
s.add_dependency(%q<ruby-dtrace>, [">= 0.2.8"])
|
57
|
+
s.add_dependency(%q<rack>, [">= 1.0.0"])
|
58
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)+'/../spec_helper.rb')
|
2
|
+
|
3
|
+
require 'spec/interop/test'
|
4
|
+
require 'dtrace'
|
5
|
+
|
6
|
+
describe Rack::Probe do
|
7
|
+
include Rack::Test::Methods
|
8
|
+
|
9
|
+
def app
|
10
|
+
a = lambda { [200, {'Content-Type' => 'text/html'},''] }
|
11
|
+
Rack::Probe.new(a)
|
12
|
+
end
|
13
|
+
|
14
|
+
def compile_script(script)
|
15
|
+
@compiler.compile(script).execute
|
16
|
+
@compiler.go
|
17
|
+
DtraceConsumer.new(@compiler)
|
18
|
+
end
|
19
|
+
|
20
|
+
class DtraceConsumer
|
21
|
+
def finished?
|
22
|
+
@done
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
before :each do
|
27
|
+
@compiler = Dtrace.new
|
28
|
+
@compiler.setopt('bufsize', '8m')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should fire a probe with a request\'s ip' do
|
32
|
+
consumer = compile_script ":::ip {trace(copyinstr((int) arg0));}"
|
33
|
+
get '/'
|
34
|
+
consumer.consume_once do |d|
|
35
|
+
record = d.data.first
|
36
|
+
record.value.should match(/.*\..*\..*\..*/)
|
37
|
+
consumer.finish
|
38
|
+
end
|
39
|
+
consumer.finished?.should be_true
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should fire a probe with a request\'s path' do
|
43
|
+
consumer = compile_script ":::path {trace(copyinstr((int) arg0));}"
|
44
|
+
get '/'
|
45
|
+
consumer.consume_once do |d|
|
46
|
+
record = d.data.first
|
47
|
+
record.value.should eql('/')
|
48
|
+
consumer.finish
|
49
|
+
end
|
50
|
+
consumer.finished?.should be_true
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should fire a probe with a request\'s referer' do
|
54
|
+
consumer = compile_script ":::referer {trace(copyinstr((int) arg0));}"
|
55
|
+
get '/'
|
56
|
+
consumer.consume_once do |d|
|
57
|
+
record = d.data.first
|
58
|
+
record.value.should eql('/')
|
59
|
+
consumer.finish
|
60
|
+
end
|
61
|
+
consumer.finished?.should be_true
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should fire a probe when a request is a GET' do
|
65
|
+
consumer = compile_script ":::get {}"
|
66
|
+
get '/'
|
67
|
+
consumer.consume_once do |d|
|
68
|
+
d.probe.name.should eql('get')
|
69
|
+
consumer.finish
|
70
|
+
end
|
71
|
+
consumer.finished?.should be_true
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should fire a probe when a request is a POST' do
|
75
|
+
consumer = compile_script ":::post {}"
|
76
|
+
post '/'
|
77
|
+
consumer.consume_once do |d|
|
78
|
+
d.probe.name.should eql('post')
|
79
|
+
consumer.finish
|
80
|
+
end
|
81
|
+
consumer.finished?.should be_true
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should fire a probe when a request is a PUTS' do
|
85
|
+
consumer = compile_script ":::put {}"
|
86
|
+
put '/'
|
87
|
+
consumer.consume_once do |d|
|
88
|
+
d.probe.name.should eql('put')
|
89
|
+
consumer.finish
|
90
|
+
end
|
91
|
+
consumer.finished?.should be_true
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should fire a probe when a request is a DELETE' do
|
95
|
+
consumer = compile_script ":::delete {}"
|
96
|
+
delete '/'
|
97
|
+
consumer.consume_once do |d|
|
98
|
+
d.probe.name.should eql('delete')
|
99
|
+
consumer.finish
|
100
|
+
end
|
101
|
+
consumer.finished?.should be_true
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should fire a probe when a request is a XHR' do
|
105
|
+
consumer = compile_script ":::xhr {}"
|
106
|
+
get '/', {}, { "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest" }
|
107
|
+
consumer.consume_once do |d|
|
108
|
+
d.probe.name.should eql('xhr')
|
109
|
+
consumer.finish
|
110
|
+
end
|
111
|
+
consumer.finished?.should be_true
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rack/probe'
|
5
|
+
require 'rack/test'
|
6
|
+
require 'spec'
|
7
|
+
require 'spec/autorun'
|
8
|
+
|
9
|
+
# Be sure to run tests with sudo/as root, as it makes use of Dtrace
|
10
|
+
# consumers.
|
11
|
+
|
12
|
+
Spec::Runner.configure do |config|
|
13
|
+
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ecin-rack-probe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ecin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-15 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ruby-dtrace
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.2.8
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rack
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
description: Rack::Probe provides a set of probes for Rack that fire with each request.
|
46
|
+
email: ecin@copypastel.com
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files:
|
52
|
+
- LICENSE
|
53
|
+
- README.rdoc
|
54
|
+
files:
|
55
|
+
- .document
|
56
|
+
- .gitignore
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
- Rakefile
|
60
|
+
- VERSION
|
61
|
+
- lib/rack-probe.rb
|
62
|
+
- lib/rack/probe.rb
|
63
|
+
- rack-probe.gemspec
|
64
|
+
- spec/rack/probe_spec.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
has_rdoc: false
|
67
|
+
homepage: http://github.com/ecin/rack-probe
|
68
|
+
licenses:
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options:
|
71
|
+
- --charset=UTF-8
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
version:
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: "0"
|
85
|
+
version:
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.3.5
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: Rack::Probe adds Dtrace probes to your Rack apps.
|
93
|
+
test_files:
|
94
|
+
- spec/rack/probe_spec.rb
|
95
|
+
- spec/spec_helper.rb
|