rack-request-profiler 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ ## 0.1.2
2
+
3
+ * [Bugfix] Fixed #2. Handle BSON id's that begin with more than one number.
4
+ * Allow the id matching pattern to be over-ridden via `Rack::Util::UrlStripper.id_pattern=`
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,5 +1,5 @@
1
1
  module Rack
2
2
  class RequestProfiler
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
@@ -1,10 +1,19 @@
1
1
  module Rack
2
2
  module Utils
3
3
  class UrlStripper
4
- ID_PATTERN = /([0-9][a-z][^\/]+)/
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
- def self.replace_id(url)
7
- url.gsub(ID_PATTERN, 'ID')
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
- Rack::Utils::UrlStripper.replace_id("/resource/4f07931e3641417a88000002").should == '/resource/ID'
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.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-02-10 00:00:00.000000000 Z
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