grape-datadog 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ba4b9a27af459dcef450e036d45bcfb8f41b08f
4
- data.tar.gz: 599981b5f22f182a9834055ed00338f37b103461
3
+ metadata.gz: b14dbd829e8c193af488bfcde4a5bbd625a5ecbf
4
+ data.tar.gz: c3055618f84b9970c4fc308bb363db61225691da
5
5
  SHA512:
6
- metadata.gz: c0a3c9077a3fb3bcd784a6969980a559e68bfbe5ebe96e747a9c41e87059149cf2d0e590671a328bf103658f4a0f5e635cb6c50b06f4d674029ac5c62aa479bb
7
- data.tar.gz: 77e186ee2d920fc3505e8b4c7b74a5d2481df12eabf0741685c255881eca5b27bac010989c1c8cf722b339424fde634f1b159008cefe67006e39af3d830e3ed4
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.push "host:#{hostname}"
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
- path = env['api.endpoint'].routes.first.route_path[1..-1].gsub("/", ".").sub(/\(\.:format\)\z/, "").gsub(/\.:(\w+)/, '.{\1}')
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
- when String
48
- tag
49
- when Proc
50
- tag.call(env)
51
- end
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
@@ -1,5 +1,5 @@
1
1
  module Grape
2
2
  module Datadog
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  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:echo.{key1}.{key2},status:200",
35
- "grape.request.time:333|ms|#custom:tag,scheme:http,host:test.host,method:GET,path:echo.{key1}.{key2},status:200"
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.1.0
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-09-28 00:00:00.000000000 Z
12
+ date: 2015-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grape