dogapi 1.10.0 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/CHANGELOG.md +3 -0
- data/examples/custom_metric.rb +6 -0
- data/lib/dogapi/common.rb +13 -4
- data/lib/dogapi/facade.rb +10 -0
- data/lib/dogapi/v1/metric.rb +52 -14
- data/lib/dogapi/version.rb +1 -1
- data/spec/common_spec.rb +21 -0
- data/spec/facade_spec.rb +55 -13
- metadata +29 -19
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2Y1MzNkOWZlNzJmODkxZmY0OTczYmQxOTI1NGZlZGViODc2OTkyMg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
M2JkNGNhMTI2N2Y4NDczNzU0NDYyZmI3NGQyNjU1MzBkMWQxNjhmMw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjYzZTAyY2U2ZDU4ZjcxODZiNTRkY2Y2OGZkZTZlNTI2ZWQxNzZhY2I4ZTZi
|
10
|
+
M2JmN2M2YmJhZDA0ODFkZDE2ZmE1YmMxM2YwZjQzNDUwOGRmNjk3OTRmZWM5
|
11
|
+
MGI5MjU1N2UxZjllMzUyNGM3M2QwZjczNzNhZWUwMjAzN2FlYTU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OTBkNTA4YTY5OWRjY2M0YmQ3MjMyZjUxYWM5MDcyODk3ZDcxNDhhZTY5ZGQ4
|
14
|
+
Mjg2MzI4MjhiNmU3YTQwNTAxMDY2YzA2NjE2ZDQxMmI1ZGQyZDZhM2FkNGZk
|
15
|
+
NDAzYjEyYWExZjQ3M2M5OWI0YzQ5NDQ1MjRkODFiOTk1YWM4ZDc=
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
Changes
|
2
2
|
=======
|
3
|
+
# 1.11.0 / 2014-07-03
|
4
|
+
* Allow to send several metrics in the same http request
|
5
|
+
* Add support for http proxy defined by the environment variables
|
3
6
|
|
4
7
|
# 1.10.0 / 2014-05-13
|
5
8
|
* Re-enable SSL verification ([#37](https://github.com/DataDog/dogapi-rb/issues/37))
|
data/examples/custom_metric.rb
CHANGED
@@ -27,3 +27,9 @@ end
|
|
27
27
|
|
28
28
|
# And emit the data in one call
|
29
29
|
dog.emit_points('test.api.test_metric', points)
|
30
|
+
|
31
|
+
# Emit differents metrics in a single request to be more efficient
|
32
|
+
dog.batch_metrics do
|
33
|
+
dog.emit_point('test.api.test_metric',10)
|
34
|
+
dog.emit_point('test.api.this_other_metric', 1, :type => 'counter')
|
35
|
+
end
|
data/lib/dogapi/common.rb
CHANGED
@@ -79,11 +79,20 @@ module Dogapi
|
|
79
79
|
|
80
80
|
# Manages the HTTP connection
|
81
81
|
def connect
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
connection = Net::HTTP
|
83
|
+
|
84
|
+
# After ruby 2.0 Net::HTTP looks for the env variable but not ruby 1.9
|
85
|
+
if RUBY_VERSION < "2.0.0"
|
86
|
+
proxy = ENV["HTTPS_PROXY"] || ENV["https_proxy"] || ENV["HTTP_PROXY"] || ENV["http_proxy"]
|
87
|
+
if proxy
|
88
|
+
proxy_uri = URI.parse(proxy)
|
89
|
+
connection = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
|
90
|
+
end
|
86
91
|
end
|
92
|
+
|
93
|
+
uri = URI.parse(@api_host)
|
94
|
+
session = connection.new(uri.host, uri.port)
|
95
|
+
session.use_ssl = uri.scheme == 'https'
|
87
96
|
session.start do |conn|
|
88
97
|
conn.read_timeout = @timeout
|
89
98
|
yield(conn)
|
data/lib/dogapi/facade.rb
CHANGED
@@ -89,6 +89,16 @@ module Dogapi
|
|
89
89
|
@metric_svc.submit(metric, points, scope, options)
|
90
90
|
end
|
91
91
|
|
92
|
+
def batch_metrics()
|
93
|
+
@metric_svc.switch_to_batched
|
94
|
+
begin
|
95
|
+
yield
|
96
|
+
@metric_svc.flush_buffer
|
97
|
+
ensure
|
98
|
+
@metric_svc.switch_to_single
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
92
102
|
#
|
93
103
|
# EVENTS
|
94
104
|
|
data/lib/dogapi/v1/metric.rb
CHANGED
@@ -8,36 +8,74 @@ module Dogapi
|
|
8
8
|
|
9
9
|
API_VERSION = "v1"
|
10
10
|
|
11
|
-
|
12
|
-
def submit(metric, points, scope, options = {})
|
11
|
+
def upload(metrics)
|
13
12
|
begin
|
14
13
|
params = {
|
15
14
|
:api_key => @api_key
|
16
15
|
}
|
16
|
+
body = {
|
17
|
+
:series => metrics
|
18
|
+
}
|
19
|
+
request(Net::HTTP::Post, '/api/' + API_VERSION + '/series', params, body, true)
|
20
|
+
rescue Exception => e
|
21
|
+
if @silent
|
22
|
+
warn e
|
23
|
+
return -1, {}
|
24
|
+
else
|
25
|
+
raise e
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def submit_to_api(metric, points, scope, options = {})
|
31
|
+
payload = self.make_metric_payload(metric, points, scope, options)
|
32
|
+
self.upload([payload])
|
33
|
+
end
|
34
|
+
|
35
|
+
def submit_to_buffer(metric, points, scope, options = {})
|
36
|
+
payload = self.make_metric_payload(metric, points, scope, options)
|
37
|
+
@buffer << payload
|
38
|
+
end
|
39
|
+
|
40
|
+
def flush_buffer()
|
41
|
+
self.upload(@buffer)
|
42
|
+
@buffer = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
alias :submit :submit_to_api
|
46
|
+
|
47
|
+
def switch_to_batched()
|
48
|
+
alias :submit :submit_to_buffer
|
49
|
+
@buffer = Array.new
|
50
|
+
end
|
51
|
+
|
52
|
+
def switch_to_single()
|
53
|
+
@buffer = nil
|
54
|
+
alias :submit :submit_to_api
|
55
|
+
end
|
56
|
+
|
57
|
+
def make_metric_payload(metric, points, scope, options)
|
58
|
+
begin
|
17
59
|
typ = options[:type] || "gauge"
|
18
60
|
|
19
61
|
if typ != "gauge" && typ != "counter"
|
20
62
|
raise ArgumentError, "metric type must be gauge or counter"
|
21
63
|
end
|
22
64
|
|
23
|
-
|
24
|
-
:
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
:host => scope.host,
|
30
|
-
:device => scope.device
|
31
|
-
}
|
32
|
-
]
|
65
|
+
metric_payload = {
|
66
|
+
:metric => metric,
|
67
|
+
:points => points,
|
68
|
+
:type => typ,
|
69
|
+
:host => scope.host,
|
70
|
+
:device => scope.device
|
33
71
|
}
|
34
72
|
|
35
73
|
# Add tags if there are any
|
36
74
|
if not options[:tags].nil?
|
37
|
-
|
75
|
+
metric_payload[:tags] = options[:tags]
|
38
76
|
end
|
39
77
|
|
40
|
-
|
78
|
+
return metric_payload
|
41
79
|
rescue Exception => e
|
42
80
|
if @silent
|
43
81
|
warn e
|
data/lib/dogapi/version.rb
CHANGED
data/spec/common_spec.rb
CHANGED
@@ -13,4 +13,25 @@ describe "Common" do
|
|
13
13
|
|
14
14
|
end # end Scope
|
15
15
|
|
16
|
+
context "HttpConnection" do
|
17
|
+
|
18
|
+
it "respects the proxy configuration" do
|
19
|
+
service = Dogapi::APIService.new("api_key", "app_key")
|
20
|
+
|
21
|
+
service.connect do |conn|
|
22
|
+
expect(conn.proxy_address).to be(nil)
|
23
|
+
expect(conn.proxy_port).to be(nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
ENV["http_proxy"] = "https://www.proxy.com:443"
|
27
|
+
|
28
|
+
service.connect do |conn|
|
29
|
+
expect(conn.proxy_address).to eq "www.proxy.com"
|
30
|
+
expect(conn.proxy_port).to eq 443
|
31
|
+
end
|
32
|
+
|
33
|
+
ENV["http_proxy"] = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
16
37
|
end # end Common
|
data/spec/facade_spec.rb
CHANGED
@@ -13,31 +13,73 @@ describe "Facade", :vcr => true do
|
|
13
13
|
|
14
14
|
before(:each) do
|
15
15
|
@dogmock = Dogapi::Client.new(@api_key, @app_key)
|
16
|
-
@
|
17
|
-
@
|
16
|
+
@service = @dogmock.instance_variable_get(:@metric_svc)
|
17
|
+
@service.instance_variable_set(:@uploaded, Array.new)
|
18
|
+
def @service.upload payload
|
19
|
+
@uploaded << payload
|
20
|
+
end
|
18
21
|
end
|
19
22
|
|
20
23
|
it "emit_point passes data" do
|
21
|
-
expect(@metric_svc).to receive(:submit) do |metric, points, scope, options|
|
22
|
-
expect(metric).to eq "metric.name"
|
23
|
-
expect(points[0][1]).to eq 0
|
24
|
-
expect(scope.host).to eq "myhost"
|
25
|
-
end
|
26
24
|
@dogmock.emit_point("metric.name", 0, :host => "myhost")
|
25
|
+
|
26
|
+
uploaded = @service.instance_variable_get(:@uploaded)
|
27
|
+
expect(uploaded.length).to eq 1
|
28
|
+
series = uploaded.first
|
29
|
+
expect(series.class).to eq Array
|
30
|
+
expect(series[0][:metric]).to eq "metric.name"
|
31
|
+
expect(series[0][:points][0][1]).to eq 0
|
32
|
+
expect(series[0][:host]).to eq "myhost"
|
27
33
|
end
|
28
34
|
|
29
35
|
it "emit_point uses localhost default" do
|
30
|
-
expect(@metric_svc).to receive(:submit) do |metric, points, scope, options|
|
31
|
-
expect(scope.host).to eq Dogapi.find_localhost
|
32
|
-
end
|
33
36
|
@dogmock.emit_point("metric.name", 0)
|
37
|
+
|
38
|
+
uploaded = @service.instance_variable_get(:@uploaded)
|
39
|
+
series = uploaded.first
|
40
|
+
expect(series[0][:host]).to eq Dogapi.find_localhost
|
34
41
|
end
|
35
42
|
|
36
43
|
it "emit_point can pass nil host" do
|
37
|
-
expect(@metric_svc).to receive(:submit) do |metric, points, scope, options|
|
38
|
-
expect(scope.host).to be_nil
|
39
|
-
end
|
40
44
|
@dogmock.emit_point("metric.name", 0, :host => nil)
|
45
|
+
|
46
|
+
uploaded = @service.instance_variable_get(:@uploaded)
|
47
|
+
series = uploaded.first
|
48
|
+
expect(series[0][:host]).to be_nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it "emit_points can be batched" do
|
52
|
+
@dogmock.batch_metrics do
|
53
|
+
@dogmock.emit_point("metric.name", 1, :type => 'counter')
|
54
|
+
@dogmock.emit_point("othermetric.name", 2, :type => 'counter')
|
55
|
+
end
|
56
|
+
# Verify that we uploaded what we expected
|
57
|
+
uploaded = @service.instance_variable_get(:@uploaded)
|
58
|
+
expect(uploaded.length).to eq 1
|
59
|
+
series = uploaded.first
|
60
|
+
expect(series.class).to eq Array
|
61
|
+
expect(series[0][:metric]).to eq 'metric.name'
|
62
|
+
expect(series[0][:points][0][1]).to eq 1
|
63
|
+
expect(series[0][:type]).to eq 'counter'
|
64
|
+
expect(series[1][:metric]).to eq 'othermetric.name'
|
65
|
+
expect(series[1][:points][0][1]).to eq 2
|
66
|
+
expect(series[1][:type]).to eq 'counter'
|
67
|
+
|
68
|
+
# Verify that the buffer was correclty emptied
|
69
|
+
buffer = @service.instance_variable_get(:@buffer)
|
70
|
+
expect(buffer).to be nil
|
71
|
+
end
|
72
|
+
|
73
|
+
it "flushes the buffer even if an exception is raised" do
|
74
|
+
begin
|
75
|
+
@dogmock.batch_metrics do
|
76
|
+
@dogmock.emit_point("metric.name", 1, :type => 'counter')
|
77
|
+
raise "Oh no, something went wrong"
|
78
|
+
end
|
79
|
+
rescue
|
80
|
+
end
|
81
|
+
buffer = @service.instance_variable_get(:@buffer)
|
82
|
+
expect(buffer).to be nil
|
41
83
|
end
|
42
84
|
|
43
85
|
end
|
metadata
CHANGED
@@ -1,60 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dogapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.11.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Datadog, Inc.
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: json
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 1.5.1
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.5.1
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: bundler
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
31
|
- - ~>
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '1.3'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: rake
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
45
|
- - ~>
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '10'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: rdoc
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
59
|
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
type: :development
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
58
69
|
description: Ruby bindings for Datadog's API
|
59
70
|
email:
|
60
71
|
- packages@datadoghq.com
|
@@ -124,6 +135,7 @@ files:
|
|
124
135
|
homepage: http://datadoghq.com/
|
125
136
|
licenses:
|
126
137
|
- BSD
|
138
|
+
metadata: {}
|
127
139
|
post_install_message:
|
128
140
|
rdoc_options:
|
129
141
|
- --title
|
@@ -135,22 +147,20 @@ rdoc_options:
|
|
135
147
|
require_paths:
|
136
148
|
- lib
|
137
149
|
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
-
none: false
|
139
150
|
requirements:
|
140
151
|
- - ! '>='
|
141
152
|
- !ruby/object:Gem::Version
|
142
153
|
version: '0'
|
143
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
-
none: false
|
145
155
|
requirements:
|
146
156
|
- - ! '>='
|
147
157
|
- !ruby/object:Gem::Version
|
148
158
|
version: '0'
|
149
159
|
requirements: []
|
150
160
|
rubyforge_project:
|
151
|
-
rubygems_version:
|
161
|
+
rubygems_version: 2.2.2
|
152
162
|
signing_key:
|
153
|
-
specification_version:
|
163
|
+
specification_version: 4
|
154
164
|
summary: Ruby bindings for Datadog's API
|
155
165
|
test_files:
|
156
166
|
- spec/alerts_spec.rb
|