grape-datadog 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/grape/datadog/middleware.rb +12 -9
- data/lib/grape/datadog/version.rb +1 -1
- data/spec/grape/datadog/middleware_spec.rb +25 -2
- 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: b14dbd829e8c193af488bfcde4a5bbd625a5ecbf
|
4
|
+
data.tar.gz: c3055618f84b9970c4fc308bb363db61225691da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd8d20ca60f27da9cc0ee74d60410dbc4e79033ce7471a8be31e6ff71f79d9f0ddacfdb4d74a946bd02c109b2a4f555c7cc6c25cdb40b9fefe28acd4a2ab7fb0
|
7
|
+
data.tar.gz: 3be84c6ea24b6c259cd872a9b2fa3b1c3ee2996acd789f89971deff5b2fba0a55f8968b5dc776eee67935fde047edd296acd741b4214540e4e36a7a25a526804
|
@@ -25,7 +25,7 @@ module Grape
|
|
25
25
|
@metric = opts[:metric_name] || "grape.request"
|
26
26
|
@statsd = opts[:prefer_global] == false || !defined?($statsd) ? ::Statsd.new(statsd_host, statsd_port) : $statsd
|
27
27
|
@tags = opts[:tags] || []
|
28
|
-
@tags
|
28
|
+
@tags += ["host:#{hostname}"]
|
29
29
|
end
|
30
30
|
|
31
31
|
def call(env)
|
@@ -41,15 +41,18 @@ module Grape
|
|
41
41
|
private
|
42
42
|
|
43
43
|
def prepare_tags(env)
|
44
|
-
|
44
|
+
endpoint = env['api.endpoint']
|
45
|
+
path = File.join endpoint.namespace, endpoint.options[:path].join('/').gsub(/:(\w+)/) {|m| "_#{m[1..-1]}_" }
|
46
|
+
versions = endpoint.namespace_inheritable(:version)
|
47
|
+
version = versions.first if versions
|
48
|
+
|
45
49
|
@tags.map do |tag|
|
46
|
-
case tag
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end.compact + ["method:#{env[Rack::REQUEST_METHOD]}", "path:#{path}"]
|
50
|
+
case tag when String then tag when Proc then tag.call(env) end
|
51
|
+
end.compact + [
|
52
|
+
"method:#{env[Rack::REQUEST_METHOD]}",
|
53
|
+
"path:#{path}",
|
54
|
+
(version ? "version:#{version}" : nil),
|
55
|
+
].compact
|
53
56
|
end
|
54
57
|
|
55
58
|
end
|
@@ -2,6 +2,13 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Grape::Datadog::Middleware do
|
4
4
|
|
5
|
+
class VersionedTestAPI < Grape::API
|
6
|
+
version 'v1'
|
7
|
+
prefix 'api'
|
8
|
+
|
9
|
+
get('versioned') { "OK" }
|
10
|
+
end
|
11
|
+
|
5
12
|
class TestAPI < Grape::API
|
6
13
|
use Grape::Datadog::Middleware,
|
7
14
|
hostname: "test.host",
|
@@ -10,6 +17,10 @@ describe Grape::Datadog::Middleware do
|
|
10
17
|
get 'echo/:key1/:key2' do
|
11
18
|
"#{params['key1']} #{params['key2']}"
|
12
19
|
end
|
20
|
+
|
21
|
+
namespace :sub do
|
22
|
+
mount VersionedTestAPI
|
23
|
+
end
|
13
24
|
end
|
14
25
|
|
15
26
|
def app; TestAPI; end
|
@@ -31,8 +42,20 @@ describe Grape::Datadog::Middleware do
|
|
31
42
|
expect(last_response.body).to eq('1 1234')
|
32
43
|
|
33
44
|
expect($statsd.buffer).to eq([
|
34
|
-
"grape.request:1|c|#custom:tag,scheme:http,host:test.host,method:GET,path
|
35
|
-
"grape.request.time:333|ms|#custom:tag,scheme:http,host:test.host,method:GET,path
|
45
|
+
"grape.request:1|c|#custom:tag,scheme:http,host:test.host,method:GET,path:/echo/_key1_/_key2_,status:200",
|
46
|
+
"grape.request.time:333|ms|#custom:tag,scheme:http,host:test.host,method:GET,path:/echo/_key1_/_key2_,status:200",
|
47
|
+
])
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should support namespaces and versioning' do
|
51
|
+
get '/api/v1/sub/versioned'
|
52
|
+
expect(last_response.status).to eq(200)
|
53
|
+
expect(last_response.body).to eq('OK')
|
54
|
+
|
55
|
+
expect($statsd.buffer).to eq([
|
56
|
+
"grape.request:1|c|#custom:tag,scheme:http,host:test.host,method:GET,path:/sub/versioned,version:v1,status:200",
|
57
|
+
"grape.request.time:333|ms|#custom:tag,scheme:http,host:test.host,method:GET,path:/sub/versioned,version:v1,status:200",
|
36
58
|
])
|
37
59
|
end
|
60
|
+
|
38
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-datadog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Chernyshev
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-10-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grape
|