metriks-middleware 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/metriks/middleware.rb +8 -9
- data/metriks-middleware.gemspec +2 -2
- data/test/async_app_test.rb +6 -21
- data/test/sync_app_test.rb +6 -27
- metadata +2 -2
data/lib/metriks/middleware.rb
CHANGED
@@ -2,11 +2,10 @@ require 'metriks'
|
|
2
2
|
|
3
3
|
module Metriks
|
4
4
|
class Middleware
|
5
|
-
VERSION = '1.2.
|
5
|
+
VERSION = '1.2.1'
|
6
6
|
|
7
|
-
def initialize(app
|
8
|
-
@app
|
9
|
-
@name = options.fetch :name, 'app'
|
7
|
+
def initialize(app)
|
8
|
+
@app = app
|
10
9
|
end
|
11
10
|
|
12
11
|
def call(env)
|
@@ -33,8 +32,8 @@ module Metriks
|
|
33
32
|
queue_wait = env['HTTP_X_HEROKU_QUEUE_WAIT_TIME']
|
34
33
|
queue_depth = env['HTTP_X_HEROKU_QUEUE_DEPTH']
|
35
34
|
|
36
|
-
Metriks.histogram("
|
37
|
-
Metriks.histogram("
|
35
|
+
Metriks.histogram("queue.wait") .update(queue_wait.to_i) if queue_wait
|
36
|
+
Metriks.histogram("queue.depth").update(queue_depth.to_i) if queue_depth
|
38
37
|
end
|
39
38
|
|
40
39
|
def record_error_rate(env)
|
@@ -53,14 +52,14 @@ module Metriks
|
|
53
52
|
|
54
53
|
def record_error(status)
|
55
54
|
if status >= 500
|
56
|
-
Metriks.meter("
|
55
|
+
Metriks.meter("responses.error").mark
|
57
56
|
elsif status == 404
|
58
|
-
Metriks.meter("
|
57
|
+
Metriks.meter("responses.not_found").mark
|
59
58
|
end
|
60
59
|
end
|
61
60
|
|
62
61
|
def response_timer
|
63
|
-
Metriks.timer(
|
62
|
+
Metriks.timer('app')
|
64
63
|
end
|
65
64
|
end
|
66
65
|
end
|
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.2.
|
17
|
-
s.date = '2012-
|
16
|
+
s.version = '1.2.1'
|
17
|
+
s.date = '2012-09-25'
|
18
18
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
20
20
|
## as you like.
|
data/test/async_app_test.rb
CHANGED
@@ -79,7 +79,7 @@ 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('
|
82
|
+
errors = Metriks.meter('responses.error').count
|
83
83
|
|
84
84
|
assert_equal 2, errors
|
85
85
|
end
|
@@ -102,7 +102,7 @@ class AsyncAppTest < Test::Unit::TestCase
|
|
102
102
|
Metriks::Middleware.new(success_sync_app).call(@env.dup)
|
103
103
|
Metriks::Middleware.new(success_async_app).call(@env.dup)
|
104
104
|
|
105
|
-
not_founds = Metriks.meter('
|
105
|
+
not_founds = Metriks.meter('responses.not_found').count
|
106
106
|
|
107
107
|
assert_equal 2, not_founds
|
108
108
|
end
|
@@ -111,8 +111,8 @@ class AsyncAppTest < Test::Unit::TestCase
|
|
111
111
|
Metriks::Middleware.new(@downstream).call(@env)
|
112
112
|
@async_close.call
|
113
113
|
|
114
|
-
wait = Metriks.histogram('
|
115
|
-
depth = Metriks.histogram('
|
114
|
+
wait = Metriks.histogram('queue.wait').mean
|
115
|
+
depth = Metriks.histogram('queue.depth').mean
|
116
116
|
|
117
117
|
assert_equal 0, wait
|
118
118
|
assert_equal 0, depth
|
@@ -124,25 +124,10 @@ class AsyncAppTest < Test::Unit::TestCase
|
|
124
124
|
Metriks::Middleware.new(@downstream).call(@env)
|
125
125
|
@async_close.call
|
126
126
|
|
127
|
-
wait = Metriks.histogram('
|
128
|
-
depth = Metriks.histogram('
|
127
|
+
wait = Metriks.histogram('queue.wait').mean
|
128
|
+
depth = Metriks.histogram('queue.depth').mean
|
129
129
|
|
130
130
|
assert_equal 42, wait
|
131
131
|
assert_equal 24, depth
|
132
132
|
end
|
133
|
-
|
134
|
-
def test_name_merics
|
135
|
-
@env.merge! 'HTTP_X_HEROKU_QUEUE_WAIT_TIME' => '42',
|
136
|
-
'HTTP_X_HEROKU_QUEUE_DEPTH' => '24'
|
137
|
-
Metriks::Middleware.new(@downstream, name: 'metric-name').call(@env)
|
138
|
-
@async_close.call
|
139
|
-
|
140
|
-
count = Metriks.timer('metric-name').count
|
141
|
-
wait = Metriks.histogram('metric-name.queue.wait').mean
|
142
|
-
depth = Metriks.histogram('metric-name.queue.depth').mean
|
143
|
-
|
144
|
-
assert_operator count, :>, 0
|
145
|
-
assert_operator wait, :>, 0
|
146
|
-
assert_operator depth, :>, 0
|
147
|
-
end
|
148
133
|
end
|
data/test/sync_app_test.rb
CHANGED
@@ -50,7 +50,7 @@ class SyncAppTest < Test::Unit::TestCase
|
|
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('
|
53
|
+
errors = Metriks.meter('responses.error').count
|
54
54
|
|
55
55
|
assert_equal 2, errors
|
56
56
|
end
|
@@ -60,7 +60,7 @@ class SyncAppTest < Test::Unit::TestCase
|
|
60
60
|
2.times { Metriks::Middleware.new(not_found_app).call(@env) }
|
61
61
|
Metriks::Middleware.new(@downstream).call(@env)
|
62
62
|
|
63
|
-
not_founds = Metriks.meter('
|
63
|
+
not_founds = Metriks.meter('responses.not_found').count
|
64
64
|
|
65
65
|
assert_equal 2, not_founds
|
66
66
|
end
|
@@ -68,8 +68,8 @@ class SyncAppTest < Test::Unit::TestCase
|
|
68
68
|
def test_omits_queue_metrics
|
69
69
|
Metriks::Middleware.new(@downstream).call(@env)
|
70
70
|
|
71
|
-
wait = Metriks.histogram('
|
72
|
-
depth = Metriks.histogram('
|
71
|
+
wait = Metriks.histogram('queue.wait').mean
|
72
|
+
depth = Metriks.histogram('queue.depth').mean
|
73
73
|
|
74
74
|
assert_equal 0, wait
|
75
75
|
assert_equal 0, depth
|
@@ -80,31 +80,10 @@ class SyncAppTest < Test::Unit::TestCase
|
|
80
80
|
'HTTP_X_HEROKU_QUEUE_DEPTH' => '24'
|
81
81
|
Metriks::Middleware.new(@downstream).call(@env)
|
82
82
|
|
83
|
-
wait = Metriks.histogram('
|
84
|
-
depth = Metriks.histogram('
|
83
|
+
wait = Metriks.histogram('queue.wait').mean
|
84
|
+
depth = Metriks.histogram('queue.depth').mean
|
85
85
|
|
86
86
|
assert_equal 42, wait
|
87
87
|
assert_equal 24, depth
|
88
88
|
end
|
89
|
-
|
90
|
-
def test_name_merics
|
91
|
-
error_app = lambda do |env| [500, {}, ['']] end
|
92
|
-
not_found_app = lambda do |env| [404, {}, ['']] end
|
93
|
-
@env.merge! 'HTTP_X_HEROKU_QUEUE_WAIT_TIME' => '42',
|
94
|
-
'HTTP_X_HEROKU_QUEUE_DEPTH' => '24'
|
95
|
-
Metriks::Middleware.new(error_app, name: 'metric-name').call(@env)
|
96
|
-
Metriks::Middleware.new(not_found_app, name: 'metric-name').call(@env)
|
97
|
-
|
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
|
103
|
-
|
104
|
-
assert_operator count, :>, 0
|
105
|
-
assert_operator errors, :>, 0
|
106
|
-
assert_operator not_founds, :>, 0
|
107
|
-
assert_operator wait, :>, 0
|
108
|
-
assert_operator depth, :>, 0
|
109
|
-
end
|
110
89
|
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.2.
|
4
|
+
version: 1.2.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-09-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: metriks
|