influxdb 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -1
- data/Rakefile +1 -1
- data/lib/influxdb/client.rb +32 -13
- data/lib/influxdb/version.rb +1 -1
- data/spec/influxdb/client_spec.rb +63 -10
- data/spec/influxdb/worker_spec.rb +1 -1
- 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: 760707db17ad8199b2159d6e1e0f28e420f60f2f
|
4
|
+
data.tar.gz: 1fb214ed28fe1978c7fc7a0b4a1aa9b2d6572988
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7348efe2e8cf889cfcb6f4fa5557eb217438abb7c87a43813b3da1290412107f7b73f0959cd7a590172ed0158ef9663716c3ac1de733dcb6e26038e90ddbacfd
|
7
|
+
data.tar.gz: 4fbceddc8faa2e02bc7ef272c17c63d4fc81f73c9f964f51003cbd96769786d84d07369d52617737c5618f15a66fa67eaf55aaf9cbf76beb54ec8921a4373935
|
data/README.md
CHANGED
@@ -106,7 +106,7 @@ name = 'foobar'
|
|
106
106
|
time_precision = 's'
|
107
107
|
|
108
108
|
influxdb = InfluxDB::Client.new database, :username => username,
|
109
|
-
:password => password,
|
109
|
+
:password => password,
|
110
110
|
:time_precision => time_precision
|
111
111
|
|
112
112
|
data = {
|
@@ -215,6 +215,41 @@ influxdb.query 'select * from time_series_1' do |name, points|
|
|
215
215
|
end
|
216
216
|
```
|
217
217
|
|
218
|
+
By default, an InfluxDB::Client will keep trying to connect to the database when
|
219
|
+
it gets connection denied, if you want to retry a finite number of times
|
220
|
+
(or disable retries altogether), you should pass the `:retry`
|
221
|
+
value. `:retry` can be either `true`, `false` or an `Integer` to retry
|
222
|
+
infinite times, disable retries or retry a finite number of times,
|
223
|
+
respectively. `0` is equivalent to `false`
|
224
|
+
|
225
|
+
```
|
226
|
+
> require 'influxdb'
|
227
|
+
=> true
|
228
|
+
|
229
|
+
> influxdb = InfluxDB::Client.new 'database', :retry => 4
|
230
|
+
=> #<InfluxDB::Client:0x00000002bb5ce0 @database="database", @hosts=["localhost"],
|
231
|
+
@port=8086, @username="root", @password="root", @use_ssl=false,
|
232
|
+
@time_precision="s", @initial_delay=0.01, @max_delay=30,
|
233
|
+
@open_timeout=5, @read_timeout=300, @async=false, @retry=4>
|
234
|
+
|
235
|
+
> influxdb.query 'select * from serie limit 1'
|
236
|
+
E, [2014-06-02T11:04:13.416209 #22825] ERROR -- : [InfluxDB] Failed to
|
237
|
+
contact host localhost: #<SocketError: getaddrinfo: Name or service not known> -
|
238
|
+
retrying in 0.01s.
|
239
|
+
E, [2014-06-02T11:04:13.433646 #22825] ERROR -- : [InfluxDB] Failed to
|
240
|
+
contact host localhost: #<SocketError: getaddrinfo: Name or service not known> -
|
241
|
+
retrying in 0.02s.
|
242
|
+
E, [2014-06-02T11:04:13.462566 #22825] ERROR -- : [InfluxDB] Failed to
|
243
|
+
contact host localhost: #<SocketError: getaddrinfo: Name or service not known> -
|
244
|
+
retrying in 0.04s.
|
245
|
+
E, [2014-06-02T11:04:13.510853 #22825] ERROR -- : [InfluxDB] Failed to
|
246
|
+
contact host localhost: #<SocketError: getaddrinfo: Name or service not known> -
|
247
|
+
retrying in 0.08s.
|
248
|
+
SocketError: Tried 4 times to reconnect but failed.
|
249
|
+
|
250
|
+
```
|
251
|
+
If you pass `:retry => -1` it will keep trying forever
|
252
|
+
until it gets the connection.
|
218
253
|
|
219
254
|
Testing
|
220
255
|
-------
|
data/Rakefile
CHANGED
data/lib/influxdb/client.rb
CHANGED
@@ -54,7 +54,15 @@ module InfluxDB
|
|
54
54
|
@open_timeout = opts[:write_timeout] || 5
|
55
55
|
@read_timeout = opts[:read_timeout] || 300
|
56
56
|
@async = opts[:async] || false
|
57
|
-
@retry = opts.fetch(:retry)
|
57
|
+
@retry = opts.fetch(:retry, nil)
|
58
|
+
@retry = case @retry
|
59
|
+
when Integer
|
60
|
+
@retry
|
61
|
+
when true, nil
|
62
|
+
-1
|
63
|
+
when false
|
64
|
+
0
|
65
|
+
end
|
58
66
|
|
59
67
|
@worker = InfluxDB::Worker.new(self) if @async
|
60
68
|
|
@@ -129,6 +137,15 @@ module InfluxDB
|
|
129
137
|
get full_url("/db/#{database}/continuous_queries")
|
130
138
|
end
|
131
139
|
|
140
|
+
def get_shard_list()
|
141
|
+
get full_url("/cluster/shards")
|
142
|
+
end
|
143
|
+
|
144
|
+
def delete_shard(shard_id, server_ids, username, password)
|
145
|
+
data = JSON.generate({"serverIds" => server_ids})
|
146
|
+
delete full_url("/cluster/shards/#{shard_id}", :u => username, :p => password), data
|
147
|
+
end
|
148
|
+
|
132
149
|
def write_point(name, data, async=@async, time_precision=@time_precision)
|
133
150
|
data = data.is_a?(Array) ? data : [data]
|
134
151
|
columns = data.reduce(:merge).keys.sort {|a,b| a.to_s <=> b.to_s}
|
@@ -169,6 +186,10 @@ module InfluxDB
|
|
169
186
|
end
|
170
187
|
end
|
171
188
|
|
189
|
+
def delete_series(series)
|
190
|
+
delete full_url("/db/#{@database}/series/#{series}")
|
191
|
+
end
|
192
|
+
|
172
193
|
def stop!
|
173
194
|
@stopped = true
|
174
195
|
end
|
@@ -215,9 +236,10 @@ module InfluxDB
|
|
215
236
|
end
|
216
237
|
end
|
217
238
|
|
218
|
-
def delete(url)
|
239
|
+
def delete(url, data = nil)
|
240
|
+
headers = {"Content-Type" => "application/json"}
|
219
241
|
connect_with_retry do |http|
|
220
|
-
response = http.request(Net::HTTP::Delete.new(url))
|
242
|
+
response = http.request(Net::HTTP::Delete.new(url, headers), data)
|
221
243
|
if response.kind_of? Net::HTTPSuccess
|
222
244
|
return response
|
223
245
|
elsif response.kind_of? Net::HTTPUnauthorized
|
@@ -231,6 +253,7 @@ module InfluxDB
|
|
231
253
|
def connect_with_retry(&block)
|
232
254
|
hosts = @hosts.dup
|
233
255
|
delay = @initial_delay
|
256
|
+
retry_count = 0
|
234
257
|
|
235
258
|
begin
|
236
259
|
hosts.push(host = hosts.shift)
|
@@ -241,25 +264,21 @@ module InfluxDB
|
|
241
264
|
block.call(http)
|
242
265
|
|
243
266
|
rescue Timeout::Error, *InfluxDB::NET_HTTP_EXCEPTIONS => e
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
raise e
|
249
|
-
else
|
267
|
+
retry_count += 1
|
268
|
+
if (@retry == -1 or retry_count <= @retry) and !stopped?
|
269
|
+
log :error, "Failed to contact host #{host}: #{e.inspect} - retrying in #{delay}s."
|
270
|
+
log :info, "Queue size is #{@queue.length}." unless @queue.nil?
|
250
271
|
sleep delay
|
251
272
|
delay = [@max_delay, delay * 2].min
|
252
273
|
retry
|
274
|
+
else
|
275
|
+
raise e, "Tried #{retry_count-1} times to reconnect but failed."
|
253
276
|
end
|
254
277
|
ensure
|
255
278
|
http.finish if http.started?
|
256
279
|
end
|
257
280
|
end
|
258
281
|
|
259
|
-
def retry?
|
260
|
-
!stopped? && @retry
|
261
|
-
end
|
262
|
-
|
263
282
|
def denormalize_series series
|
264
283
|
columns = series['columns']
|
265
284
|
|
data/lib/influxdb/version.rb
CHANGED
@@ -20,7 +20,7 @@ describe InfluxDB::Client do
|
|
20
20
|
@influxdb.port.should == 8086
|
21
21
|
@influxdb.username.should == "root"
|
22
22
|
@influxdb.password.should == "root"
|
23
|
-
@influxdb.use_ssl.should
|
23
|
+
@influxdb.use_ssl.should be_falsey
|
24
24
|
@influxdb.time_precision.should == "s"
|
25
25
|
end
|
26
26
|
end
|
@@ -85,7 +85,7 @@ describe InfluxDB::Client do
|
|
85
85
|
@influxdb.port.should == 8086
|
86
86
|
@influxdb.username.should == "root"
|
87
87
|
@influxdb.password.should == "root"
|
88
|
-
@influxdb.use_ssl.should
|
88
|
+
@influxdb.use_ssl.should be_truthy
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -243,6 +243,28 @@ describe InfluxDB::Client do
|
|
243
243
|
end
|
244
244
|
end
|
245
245
|
|
246
|
+
describe "#get_shard_list" do
|
247
|
+
it "should GET a list of shards" do
|
248
|
+
shard_list = {"longTerm" => [], "shortTerm" => []}
|
249
|
+
stub_request(:get, "http://influxdb.test:9999/cluster/shards").with(
|
250
|
+
:query => {:u => "username", :p => "password"}
|
251
|
+
).to_return(:body => JSON.generate(shard_list, :status => 200))
|
252
|
+
|
253
|
+
@influxdb.get_shard_list.should == shard_list
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe "#delete_shard" do
|
258
|
+
it "should DELETE a shard by id" do
|
259
|
+
shard_id = 1
|
260
|
+
stub_request(:delete, "http://influxdb.test:9999/cluster/shards/#{shard_id}").with(
|
261
|
+
:query => {:u => "username", :p => "password"}
|
262
|
+
)
|
263
|
+
|
264
|
+
@influxdb.delete_shard(shard_id, [1, 2], "username", "password").should be_a(Net::HTTPOK)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
246
268
|
describe "#write_point" do
|
247
269
|
it "should POST to add points" do
|
248
270
|
body = [{
|
@@ -279,25 +301,46 @@ describe InfluxDB::Client do
|
|
279
301
|
stub_request(:post, "http://influxdb.test:9999/db/database/series").with(
|
280
302
|
:query => {:u => "username", :p => "password", :time_precision => "s"},
|
281
303
|
:body => body
|
282
|
-
).to_raise(Timeout::Error)
|
283
|
-
end
|
284
|
-
|
285
|
-
it "retries on http errors when not stopped" do
|
286
|
-
expect(subject).to be_a(Net::HTTPOK)
|
304
|
+
).to_raise(Timeout::Error)
|
287
305
|
end
|
288
306
|
|
289
307
|
it "raises when stopped" do
|
290
308
|
@influxdb.stop!
|
309
|
+
@influxdb.should_not_receive :sleep
|
291
310
|
expect { subject }.to raise_error(Timeout::Error)
|
292
311
|
end
|
293
312
|
|
294
|
-
context "when retry
|
295
|
-
let(:args) { { :retry =>
|
313
|
+
context "when retry is 0" do
|
314
|
+
let(:args) { { :retry => 0 } }
|
315
|
+
it "raise error directly" do
|
316
|
+
@influxdb.should_not_receive :sleep
|
317
|
+
expect { subject }.to raise_error(Timeout::Error)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
context "when retry is 'n'" do
|
322
|
+
let(:args) { { :retry => 3 } }
|
296
323
|
|
297
|
-
it "
|
324
|
+
it "raise error after 'n' attemps" do
|
325
|
+
@influxdb.should_receive(:sleep).exactly(3).times
|
298
326
|
expect { subject }.to raise_error(Timeout::Error)
|
299
327
|
end
|
300
328
|
end
|
329
|
+
|
330
|
+
context "when retry is -1" do
|
331
|
+
let(:args) { { :retry => -1 } }
|
332
|
+
before do
|
333
|
+
stub_request(:post, "http://influxdb.test:9999/db/database/series").with(
|
334
|
+
:query => {:u => "username", :p => "password", :time_precision => "s"},
|
335
|
+
:body => body
|
336
|
+
).to_raise(Timeout::Error).then.to_raise(Timeout::Error).then.to_raise(Timeout::Error).then.to_raise(Timeout::Error).then.to_return(:status => 200)
|
337
|
+
end
|
338
|
+
|
339
|
+
it "keep trying until get the connection" do
|
340
|
+
@influxdb.should_receive(:sleep).at_least(4).times
|
341
|
+
expect { subject }.to_not raise_error
|
342
|
+
end
|
343
|
+
end
|
301
344
|
end
|
302
345
|
|
303
346
|
it "raise an exception if the server didn't return 200" do
|
@@ -491,6 +534,16 @@ describe InfluxDB::Client do
|
|
491
534
|
end
|
492
535
|
end
|
493
536
|
|
537
|
+
describe "#delete_series" do
|
538
|
+
it "should DELETE to remove a series" do
|
539
|
+
stub_request(:delete, "http://influxdb.test:9999/db/database/series/foo").with(
|
540
|
+
:query => {:u => "username", :p => "password"}
|
541
|
+
)
|
542
|
+
|
543
|
+
@influxdb.delete_series("foo").should be_a(Net::HTTPOK)
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
494
547
|
describe "#full_url" do
|
495
548
|
it "should return String" do
|
496
549
|
@influxdb.send(:full_url, "/unknown").should be_a String
|
@@ -10,7 +10,7 @@ describe InfluxDB::Worker do
|
|
10
10
|
|
11
11
|
it "should _write to the client" do
|
12
12
|
queue = Queue.new
|
13
|
-
expect(fake_client).to receive(:_write).once.with([payload])
|
13
|
+
expect(fake_client).to receive(:_write).once.with([payload]) do |data|
|
14
14
|
queue.push(:received)
|
15
15
|
end
|
16
16
|
worker.push(payload)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: influxdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Todd Persen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|