rack-request-profiler 0.1.1 → 0.1.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/CHANGES.md +4 -0
- data/README.md +6 -0
- data/lib/rack/request-profiler/version.rb +1 -1
- data/lib/rack/utils/url_stripper.rb +12 -3
- data/spec/rack/profilers/statsd_spec.rb +14 -0
- data/spec/rack/utils/url_stripper_spec.rb +4 -1
- metadata +3 -2
data/CHANGES.md
ADDED
data/README.md
CHANGED
@@ -18,6 +18,12 @@ Simply include one of the profiler middlewares into the middleware stack in any
|
|
18
18
|
use Rack::Profilers::Statsd, Statsd.new('localhost'), :ignore_path => /^\/assets/
|
19
19
|
```
|
20
20
|
|
21
|
+
Be default, we match URL's that look like BSON ids. You can over-ride this regular expression like this:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Rack::Utils::UrlStripper.id_pattern = /some_other_pattern/
|
25
|
+
```
|
26
|
+
|
21
27
|
## Profilers
|
22
28
|
|
23
29
|
* Statsd - Uses the [statsd ruby client](https://github.com/reinh/statsd-ruby) to send data to statsd / graphite.
|
@@ -1,10 +1,19 @@
|
|
1
1
|
module Rack
|
2
2
|
module Utils
|
3
3
|
class UrlStripper
|
4
|
-
|
4
|
+
class << self
|
5
|
+
def id_pattern
|
6
|
+
# A crude attempt at matching a BSON id format (http://bsonspec.org/)
|
7
|
+
@id_pattern ||= /[0-9]+[a-zA-Z]+[^\/]*/
|
8
|
+
end
|
5
9
|
|
6
|
-
|
7
|
-
|
10
|
+
def id_pattern=(pattern)
|
11
|
+
@id_pattern = pattern
|
12
|
+
end
|
13
|
+
|
14
|
+
def replace_id(url)
|
15
|
+
url.gsub(id_pattern, 'ID')
|
16
|
+
end
|
8
17
|
end
|
9
18
|
end
|
10
19
|
end
|
@@ -3,6 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe Rack::Profilers::Statsd do
|
4
4
|
include Rack::Test::Methods
|
5
5
|
|
6
|
+
class MockApp < Sinatra::Base
|
7
|
+
use Rack::Profilers::Statsd, Statsd.new('localhost')
|
8
|
+
post '/posts/:id/update' do
|
9
|
+
[200, "post content"]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def app; @app ||= Rack::Builder.app { run MockApp }; end
|
14
|
+
|
6
15
|
it "sends stuff to statsd" do
|
7
16
|
statsd = Statsd.new 'localhost'
|
8
17
|
app = Rack::Builder.app do
|
@@ -36,4 +45,9 @@ describe Rack::Profilers::Statsd do
|
|
36
45
|
statsd.expects(:timing).with('namespace.me.GET.', 200)
|
37
46
|
Rack::MockRequest.new(app).get('/')
|
38
47
|
end
|
48
|
+
|
49
|
+
it "subs out ids" do
|
50
|
+
Statsd.any_instance.expects(:timing).with("POST.posts.1.update", any_parameters)
|
51
|
+
Rack::MockRequest.new(app).post('/posts/1/update')
|
52
|
+
end
|
39
53
|
end
|
@@ -3,7 +3,10 @@ require 'spec_helper'
|
|
3
3
|
describe Rack::Utils::UrlStripper do
|
4
4
|
describe '.replace_id' do
|
5
5
|
it 'replaces BSON-like ids with ID' do
|
6
|
-
|
6
|
+
ids = %w(5005536b28330e5a8800005f 4f07931e3641417a88000002)
|
7
|
+
ids.each do |id|
|
8
|
+
Rack::Utils::UrlStripper.replace_id("/resource/#{id}").should == '/resource/ID'
|
9
|
+
end
|
7
10
|
end
|
8
11
|
|
9
12
|
it "replaces ids with sub-resources" do
|
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.2
|
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-07-17 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.
|
@@ -21,6 +21,7 @@ extra_rdoc_files: []
|
|
21
21
|
files:
|
22
22
|
- .gitignore
|
23
23
|
- .travis.yml
|
24
|
+
- CHANGES.md
|
24
25
|
- Gemfile
|
25
26
|
- README.md
|
26
27
|
- Rakefile
|