napa 0.1.28 → 0.1.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/napa/generators/migration_generator.rb +1 -1
- data/lib/napa/generators/templates/migration/%migration_filename%.rb.tt +0 -3
- data/lib/napa/grape_extenders.rb +1 -1
- data/lib/napa/middleware/request_stats.rb +16 -4
- data/lib/napa/version.rb +1 -1
- data/spec/middleware/request_stats_spec.rb +7 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b908b554665776da48de53dd708fa5aab073f75
|
4
|
+
data.tar.gz: 22d74ccfd70d4864121f527266e7de4b062a7068
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09c3b747af4ec25f35adbc5f65296139d365907901276c0dfcde2f9ebd8f86243ab55edad8ce83849869dde2f20d3487394ea745a222a79340b698ffc6ba4e4c
|
7
|
+
data.tar.gz: 4634f451434e794ad7ec3aa3767272e803348e799de9a8412e7cec54320069074ad95c0b03885022e7d36475491228b79fd8e196491458b66bc31b66aeda9e56
|
data/lib/napa/grape_extenders.rb
CHANGED
@@ -9,7 +9,7 @@ module Napa
|
|
9
9
|
rack_response(Napa::JsonError.new(:record_not_found, 'record not found').to_json, 404)
|
10
10
|
end
|
11
11
|
modified_class.rescue_from ::ActiveRecord::RecordInvalid do |e|
|
12
|
-
rack_response(Napa::JsonError.new(:
|
12
|
+
rack_response(Napa::JsonError.new(:unprocessable_entity, e.message).to_json, 422)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -5,6 +5,15 @@ module Napa
|
|
5
5
|
@app = app
|
6
6
|
end
|
7
7
|
|
8
|
+
def normalize_path(path)
|
9
|
+
case
|
10
|
+
when path == '/'
|
11
|
+
'root'
|
12
|
+
else
|
13
|
+
path.start_with?('/') ? path[1..-1] : path
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
8
17
|
def call(env)
|
9
18
|
# Mark the request time
|
10
19
|
start = Time.now
|
@@ -16,12 +25,15 @@ module Napa
|
|
16
25
|
stop = Time.now
|
17
26
|
|
18
27
|
# Calculate total response time
|
19
|
-
response_time = stop - start
|
28
|
+
response_time = (stop - start) * 1000
|
29
|
+
|
30
|
+
request = Rack::Request.new(env)
|
31
|
+
path = normalize_path(request.path_info)
|
32
|
+
stat = "#{Napa::Identity.name}.http.#{request.request_method.downcase}.#{path}".gsub('/', '.')
|
20
33
|
|
21
34
|
# Emit stats to StatsD
|
22
|
-
Napa::Stats.emitter.increment('
|
23
|
-
Napa::Stats.emitter.timing('
|
24
|
-
|
35
|
+
Napa::Stats.emitter.increment(stat + '.requests')
|
36
|
+
Napa::Stats.emitter.timing(stat + '.response_time', response_time)
|
25
37
|
# Return the results
|
26
38
|
[status, headers, body]
|
27
39
|
end
|
data/lib/napa/version.rb
CHANGED
@@ -10,18 +10,21 @@ describe Napa::Middleware::RequestStats do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should increment api_requests counter' do
|
13
|
-
Napa::Stats.emitter.should_receive(:increment).with(
|
13
|
+
Napa::Stats.emitter.should_receive(:increment).with(Napa::Identity.name + ".http.get." + "test.path.requests")
|
14
14
|
app = lambda { |env| [200, { 'Content-Type' => 'application/json' }, Array.new] }
|
15
15
|
middleware = Napa::Middleware::RequestStats.new(app)
|
16
|
-
env = Rack::MockRequest.env_for('/test')
|
16
|
+
env = Rack::MockRequest.env_for('/test/path')
|
17
17
|
middleware.call(env)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should send the api_response_time' do
|
21
|
-
Napa::Stats.emitter.should_receive(:timing).with(
|
21
|
+
Napa::Stats.emitter.should_receive(:timing).with(
|
22
|
+
Napa::Identity.name + ".http.get." + "test.path.response_time",
|
23
|
+
an_instance_of(Float)
|
24
|
+
)
|
22
25
|
app = lambda { |env| [200, { 'Content-Type' => 'application/json'}, Array.new] }
|
23
26
|
middleware = Napa::Middleware::RequestStats.new(app)
|
24
|
-
env = Rack::MockRequest.env_for('/test')
|
27
|
+
env = Rack::MockRequest.env_for('/test/path')
|
25
28
|
middleware.call(env)
|
26
29
|
end
|
27
30
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: napa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darby Frey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|