metriks-middleware 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/example/Gemfile +6 -0
- data/{Gemfile.lock → example/Gemfile.lock} +15 -11
- data/example/Procfile +1 -0
- data/example/config.ru +40 -0
- data/lib/metriks/middleware.rb +6 -2
- data/metriks-middleware.gemspec +6 -3
- data/test/async_app_test.rb +25 -2
- data/test/sync_app_test.rb +21 -7
- metadata +6 -3
data/example/Gemfile
ADDED
@@ -1,26 +1,30 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
metriks-middleware (1.1.0)
|
5
|
-
metriks (~> 0.9.9)
|
6
|
-
|
7
1
|
GEM
|
8
2
|
remote: http://rubygems.org/
|
9
3
|
specs:
|
10
4
|
atomic (1.0.1)
|
11
5
|
avl_tree (1.1.3)
|
6
|
+
daemons (1.1.8)
|
7
|
+
eventmachine (0.12.10)
|
8
|
+
foreman (0.49.0)
|
9
|
+
thor (>= 0.13.6)
|
12
10
|
hitimes (1.1.1)
|
13
|
-
metaclass (0.0.1)
|
14
11
|
metriks (0.9.9.1)
|
15
12
|
atomic (~> 1.0)
|
16
13
|
avl_tree (~> 1.1.2)
|
17
14
|
hitimes (~> 1.1)
|
18
|
-
|
19
|
-
|
15
|
+
metriks-middleware (1.1.0)
|
16
|
+
metriks (~> 0.9.9)
|
17
|
+
rack (1.4.1)
|
18
|
+
thin (1.3.1)
|
19
|
+
daemons (>= 1.0.9)
|
20
|
+
eventmachine (>= 0.12.6)
|
21
|
+
rack (>= 1.0.0)
|
22
|
+
thor (0.15.4)
|
20
23
|
|
21
24
|
PLATFORMS
|
22
25
|
ruby
|
23
26
|
|
24
27
|
DEPENDENCIES
|
25
|
-
|
26
|
-
|
28
|
+
foreman
|
29
|
+
metriks-middleware
|
30
|
+
thin
|
data/example/Procfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
web: bundle exec thin start -p $PORT
|
data/example/config.ru
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
$: << 'lib'
|
2
|
+
require 'metriks/middleware'
|
3
|
+
require 'metriks/reporter/logger'
|
4
|
+
require 'pp'
|
5
|
+
|
6
|
+
$stdout.sync = true
|
7
|
+
Thread.abort_on_exception = true
|
8
|
+
|
9
|
+
Metriks::Reporter::Logger.new(logger: Logger.new($stdout), interval: 5).start
|
10
|
+
use Metriks::Middleware
|
11
|
+
|
12
|
+
run(->(env) do
|
13
|
+
case env['PATH_INFO']
|
14
|
+
when '/sync'
|
15
|
+
[200, {'Content-Type' => 'text/plain'}, ['sync!']]
|
16
|
+
|
17
|
+
when '/sync-error'
|
18
|
+
[500, {'Content-Type' => 'text/plain'}, ['sync error!']]
|
19
|
+
|
20
|
+
when '/async'
|
21
|
+
Thread.new do
|
22
|
+
sleep 1
|
23
|
+
env['async.callback'].call([200, {'Content-Type' => 'text/plain'}, ['async!']])
|
24
|
+
end
|
25
|
+
[-1, {}, []]
|
26
|
+
|
27
|
+
when '/async-error'
|
28
|
+
Thread.new do
|
29
|
+
sleep 1
|
30
|
+
env['async.callback'].call([500, {'Content-Type' => 'text/plain'}, ['async error!']])
|
31
|
+
end
|
32
|
+
[-1, {}, []]
|
33
|
+
|
34
|
+
else
|
35
|
+
world = env.keys.sort.each_with_object({}) {|key, world|
|
36
|
+
world[key] = env[key]
|
37
|
+
}
|
38
|
+
[200, {'Content-Type' => 'text/plain'}, [world.pretty_inspect]]
|
39
|
+
end
|
40
|
+
end)
|
data/lib/metriks/middleware.rb
CHANGED
@@ -2,7 +2,7 @@ require 'metriks'
|
|
2
2
|
|
3
3
|
module Metriks
|
4
4
|
class Middleware
|
5
|
-
VERSION = '1.
|
5
|
+
VERSION = '1.2.0'
|
6
6
|
|
7
7
|
def initialize(app, options = {})
|
8
8
|
@app = app
|
@@ -52,7 +52,11 @@ module Metriks
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def record_error(status)
|
55
|
-
|
55
|
+
if status >= 500
|
56
|
+
Metriks.meter("#{ @name }.responses.error").mark
|
57
|
+
elsif status == 404
|
58
|
+
Metriks.meter("#{ @name }.responses.not_found").mark
|
59
|
+
end
|
56
60
|
end
|
57
61
|
|
58
62
|
def response_timer
|
data/metriks-middleware.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'metriks-middleware'
|
16
|
-
s.version = '1.
|
17
|
-
s.date = '2012-07-
|
16
|
+
s.version = '1.2.0'
|
17
|
+
s.date = '2012-07-16'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
20
20
|
## as you like.
|
@@ -51,10 +51,13 @@ Gem::Specification.new do |s|
|
|
51
51
|
# = MANIFEST =
|
52
52
|
s.files = %w[
|
53
53
|
Gemfile
|
54
|
-
Gemfile.lock
|
55
54
|
LICENSE
|
56
55
|
README.md
|
57
56
|
Rakefile
|
57
|
+
example/Gemfile
|
58
|
+
example/Gemfile.lock
|
59
|
+
example/Procfile
|
60
|
+
example/config.ru
|
58
61
|
lib/metriks/middleware.rb
|
59
62
|
metriks-middleware.gemspec
|
60
63
|
test/async_app_test.rb
|
data/test/async_app_test.rb
CHANGED
@@ -61,7 +61,7 @@ class AsyncAppTest < Test::Unit::TestCase
|
|
61
61
|
assert_in_delta 0.1, time, 0.01
|
62
62
|
end
|
63
63
|
|
64
|
-
def
|
64
|
+
def test_records_error_responses
|
65
65
|
error_sync_app = lambda do |env| [500, {}, ['']] end
|
66
66
|
error_async_app = lambda do |env|
|
67
67
|
env['async.callback'].call [500, {}, ['']]
|
@@ -79,11 +79,34 @@ class AsyncAppTest < Test::Unit::TestCase
|
|
79
79
|
Metriks::Middleware.new(success_sync_app).call(@env.dup)
|
80
80
|
Metriks::Middleware.new(success_async_app).call(@env.dup)
|
81
81
|
|
82
|
-
errors = Metriks.meter('app.
|
82
|
+
errors = Metriks.meter('app.responses.error').count
|
83
83
|
|
84
84
|
assert_equal 2, errors
|
85
85
|
end
|
86
86
|
|
87
|
+
def test_records_not_found_responses
|
88
|
+
not_found_sync_app = lambda do |env| [404, {}, ['']] end
|
89
|
+
not_found_async_app = lambda do |env|
|
90
|
+
env['async.callback'].call [404, {}, ['']]
|
91
|
+
[-1, {}, ['']]
|
92
|
+
end
|
93
|
+
|
94
|
+
success_sync_app = lambda do |env| [200, {}, ['']] end
|
95
|
+
success_async_app = lambda do |env|
|
96
|
+
env['async.callback'].call [200, {}, ['']]
|
97
|
+
[-1, {}, ['']]
|
98
|
+
end
|
99
|
+
|
100
|
+
Metriks::Middleware.new(not_found_sync_app).call(@env.dup)
|
101
|
+
Metriks::Middleware.new(not_found_async_app).call(@env.dup)
|
102
|
+
Metriks::Middleware.new(success_sync_app).call(@env.dup)
|
103
|
+
Metriks::Middleware.new(success_async_app).call(@env.dup)
|
104
|
+
|
105
|
+
not_founds = Metriks.meter('app.responses.not_found').count
|
106
|
+
|
107
|
+
assert_equal 2, not_founds
|
108
|
+
end
|
109
|
+
|
87
110
|
def test_omits_queue_metrics
|
88
111
|
Metriks::Middleware.new(@downstream).call(@env)
|
89
112
|
@async_close.call
|
data/test/sync_app_test.rb
CHANGED
@@ -45,16 +45,26 @@ class SyncAppTest < Test::Unit::TestCase
|
|
45
45
|
assert_in_delta 0.1, time, 0.01
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
48
|
+
def test_records_error_responses
|
49
49
|
error_app = lambda do |env| [500, {}, ['']] end
|
50
50
|
2.times { Metriks::Middleware.new(error_app).call(@env) }
|
51
51
|
Metriks::Middleware.new(@downstream).call(@env)
|
52
52
|
|
53
|
-
errors = Metriks.meter('app.
|
53
|
+
errors = Metriks.meter('app.responses.error').count
|
54
54
|
|
55
55
|
assert_equal 2, errors
|
56
56
|
end
|
57
57
|
|
58
|
+
def test_records_not_found_responses
|
59
|
+
not_found_app = lambda do |env| [404, {}, ['']] end
|
60
|
+
2.times { Metriks::Middleware.new(not_found_app).call(@env) }
|
61
|
+
Metriks::Middleware.new(@downstream).call(@env)
|
62
|
+
|
63
|
+
not_founds = Metriks.meter('app.responses.not_found').count
|
64
|
+
|
65
|
+
assert_equal 2, not_founds
|
66
|
+
end
|
67
|
+
|
58
68
|
def test_omits_queue_metrics
|
59
69
|
Metriks::Middleware.new(@downstream).call(@env)
|
60
70
|
|
@@ -78,18 +88,22 @@ class SyncAppTest < Test::Unit::TestCase
|
|
78
88
|
end
|
79
89
|
|
80
90
|
def test_name_merics
|
81
|
-
error_app
|
91
|
+
error_app = lambda do |env| [500, {}, ['']] end
|
92
|
+
not_found_app = lambda do |env| [404, {}, ['']] end
|
82
93
|
@env.merge! 'HTTP_X_HEROKU_QUEUE_WAIT_TIME' => '42',
|
83
94
|
'HTTP_X_HEROKU_QUEUE_DEPTH' => '24'
|
84
95
|
Metriks::Middleware.new(error_app, name: 'metric-name').call(@env)
|
96
|
+
Metriks::Middleware.new(not_found_app, name: 'metric-name').call(@env)
|
85
97
|
|
86
|
-
count
|
87
|
-
errors
|
88
|
-
|
89
|
-
|
98
|
+
count = Metriks.timer('metric-name').count
|
99
|
+
errors = Metriks.meter('metric-name.responses.error').count
|
100
|
+
not_founds = Metriks.meter('metric-name.responses.not_found').count
|
101
|
+
wait = Metriks.histogram('metric-name.queue.wait').mean
|
102
|
+
depth = Metriks.histogram('metric-name.queue.depth').mean
|
90
103
|
|
91
104
|
assert_operator count, :>, 0
|
92
105
|
assert_operator errors, :>, 0
|
106
|
+
assert_operator not_founds, :>, 0
|
93
107
|
assert_operator wait, :>, 0
|
94
108
|
assert_operator depth, :>, 0
|
95
109
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metriks-middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
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-07-
|
12
|
+
date: 2012-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: metriks
|
@@ -52,10 +52,13 @@ extra_rdoc_files:
|
|
52
52
|
- LICENSE
|
53
53
|
files:
|
54
54
|
- Gemfile
|
55
|
-
- Gemfile.lock
|
56
55
|
- LICENSE
|
57
56
|
- README.md
|
58
57
|
- Rakefile
|
58
|
+
- example/Gemfile
|
59
|
+
- example/Gemfile.lock
|
60
|
+
- example/Procfile
|
61
|
+
- example/config.ru
|
59
62
|
- lib/metriks/middleware.rb
|
60
63
|
- metriks-middleware.gemspec
|
61
64
|
- test/async_app_test.rb
|