influxdb 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e708cfd29b32a5d60b415ae05c17d60e1d003b8
4
- data.tar.gz: bd843bc59f21981ab448b682129a478276e01a83
3
+ metadata.gz: 3cfda4b23fa6e69256f6309aa37b2b84b4b00fe9
4
+ data.tar.gz: d9ca155910d5323850f3dc11f76a20f6d4520747
5
5
  SHA512:
6
- metadata.gz: 559ccfca33fc274337448ea27c9ac082d9f0f0d45b12b3c37cb934ebfa44539966d109d54bb28e20ce9fc28ccb71744fdc017a8061a36aa04308c454695c8594
7
- data.tar.gz: 69ad1c57c5d07a8ce36e8efee843d8c68230bf5a6f5c74c1136b343bcafd776cfad28815d2e4acb2034aa731a2ec0d1c652edc86db242a1f9d98a12080e6c16b
6
+ metadata.gz: 755051222fdd660fbc2b0b43bd6e3b07e153fe81193b9152f0b03e2eeedb6bccdcac0aeb67ec10b824efc0446597b9c2629fbb0117ca27739af12d35f1ff4466
7
+ data.tar.gz: 764110f71894216a9032505fc2bdd8f0ad5580fce387a8b420a3d0eff01b16ab86b8525543c5d42793ebc090e090ac1281d42d70b7d264693a8ac4ed64fd2560
data/Rakefile CHANGED
@@ -16,3 +16,11 @@ RSpec.configure do |config|
16
16
  end
17
17
 
18
18
  task :default => :spec
19
+
20
+ task :console do
21
+ require 'irb'
22
+ require 'irb/completion'
23
+ require 'influxdb'
24
+ ARGV.clear
25
+ IRB.start
26
+ end
@@ -53,6 +53,8 @@ module InfluxDB
53
53
  @read_timeout = opts[:read_timeout] || 300
54
54
  @async = opts[:async] || false
55
55
 
56
+ @worker = InfluxDB::Worker.new(self) if @async
57
+
56
58
  unless @hosts.is_a? Array
57
59
  @hosts = [@hosts]
58
60
  end
@@ -138,8 +140,7 @@ module InfluxDB
138
140
  end
139
141
 
140
142
  if async
141
- @worker = InfluxDB::Worker.new(self) if @worker.nil?
142
- @worker.queue.push(payload)
143
+ worker.push(payload)
143
144
  else
144
145
  _write([payload], time_precision)
145
146
  end
@@ -226,7 +227,8 @@ module InfluxDB
226
227
  http.read_timeout = @read_timeout
227
228
  http.use_ssl = @use_ssl
228
229
  block.call(http)
229
- rescue StandardError => e
230
+
231
+ rescue Timeout::Error, *InfluxDB::NET_HTTP_EXCEPTIONS => e
230
232
  log :error, "Failed to contact host #{host}: #{e.inspect} - retrying in #{delay}s."
231
233
  log :info, "Queue size is #{@queue.length}." unless @queue.nil?
232
234
 
@@ -249,5 +251,15 @@ module InfluxDB
249
251
  Hash[columns.zip(decoded_point)]
250
252
  end
251
253
  end
254
+
255
+ WORKER_MUTEX = Mutex.new
256
+ def worker
257
+ return @worker if @worker
258
+ WORKER_MUTEX.synchronize do
259
+ #this return is necessary because the previous mutex holder might have already assigned the @worker
260
+ return @worker if @worker
261
+ @worker = InfluxDB::Worker.new(self)
262
+ end
263
+ end
252
264
  end
253
265
  end
@@ -1,5 +1,8 @@
1
+ require "net/http"
2
+ require "zlib"
3
+
1
4
  module InfluxDB
2
- class Error < Exception
5
+ class Error < StandardError
3
6
  end
4
7
 
5
8
  class AuthenticationError < Error
@@ -10,4 +13,22 @@ module InfluxDB
10
13
 
11
14
  class JSONParserError < Error
12
15
  end
16
+
17
+ # Taken from: https://github.com/lostisland/faraday/blob/master/lib/faraday/adapter/net_http.rb
18
+ NET_HTTP_EXCEPTIONS = [
19
+ EOFError,
20
+ Errno::ECONNABORTED,
21
+ Errno::ECONNREFUSED,
22
+ Errno::ECONNRESET,
23
+ Errno::EHOSTUNREACH,
24
+ Errno::EINVAL,
25
+ Errno::ENETUNREACH,
26
+ Net::HTTPBadResponse,
27
+ Net::HTTPHeaderSyntaxError,
28
+ Net::ProtocolError,
29
+ SocketError,
30
+ Zlib::GzipFile::Error,
31
+ ]
32
+
33
+ NET_HTTP_EXCEPTIONS << OpenSSL::SSL::SSLError if defined?(OpenSSL)
13
34
  end
@@ -1,3 +1,3 @@
1
1
  module InfluxDB
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -27,6 +27,10 @@ module InfluxDB
27
27
  Thread.list.count {|t| t[:influxdb] == self.object_id}
28
28
  end
29
29
 
30
+ def push(payload)
31
+ queue.push(payload)
32
+ end
33
+
30
34
  def spawn_threads!
31
35
  NUM_WORKER_THREADS.times do |thread_num|
32
36
  log :debug, "Spawning background worker thread #{thread_num}."
@@ -41,7 +45,7 @@ module InfluxDB
41
45
 
42
46
  while true
43
47
  self.check_background_queue(thread_num)
44
- sleep SLEEP_INTERVAL
48
+ sleep rand(SLEEP_INTERVAL)
45
49
  end
46
50
  end
47
51
  end
@@ -381,6 +381,27 @@ describe InfluxDB::Client do
381
381
 
382
382
  @influxdb.write_point("seriez", data, false, "m").should be_a(Net::HTTPOK)
383
383
  end
384
+
385
+ describe "async" do
386
+
387
+ it "should push to the worker with payload if client is async" do
388
+ @influxdb = InfluxDB::Client.new "database", :host => "influxdb.test", :async => true
389
+
390
+ data = {:name => "juan", :age => 87, :time => Time.now.to_i}
391
+ @influxdb.stub_chain(:worker, :push).with(hash_including({:name => 'seriez'})).and_return(:ok)
392
+ @influxdb.write_point("seriez", data).should eq(:ok)
393
+ end
394
+
395
+ it "should push to the worker with payload if write_point call is async" do
396
+ @influxdb = InfluxDB::Client.new "database", :host => "influxdb.test", :async => false
397
+
398
+ data = {:name => "juan", :age => 87, :time => Time.now.to_i}
399
+ @influxdb.stub_chain(:worker, :push).with(hash_including({:name => 'seriez'})).and_return(:ok)
400
+ @influxdb.write_point("seriez", data, true).should eq(:ok)
401
+ end
402
+
403
+ end
404
+
384
405
  end
385
406
 
386
407
  describe "#execute_queries" do
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+ require 'timeout'
3
+
4
+ describe InfluxDB::Worker do
5
+ let(:fake_client) { double() }
6
+ let(:worker) { InfluxDB::Worker.new(fake_client) }
7
+
8
+ describe "#push" do
9
+ let(:payload) { {:name => "juan", :age => 87, :time => Time.now.to_i} }
10
+
11
+ it "should _write to the client" do
12
+ queue = Queue.new
13
+ expect(fake_client).to receive(:_write).once.with([payload]).and_return do |data|
14
+ queue.push(:received)
15
+ end
16
+ worker.push(payload)
17
+
18
+ Timeout.timeout(InfluxDB::Worker::SLEEP_INTERVAL) do
19
+ queue.pop()
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+
26
+ end
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.1
4
+ version: 0.1.2
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-03-25 00:00:00.000000000 Z
11
+ date: 2014-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -105,6 +105,7 @@ files:
105
105
  - spec/influxdb/client_spec.rb
106
106
  - spec/influxdb/logger_spec.rb
107
107
  - spec/influxdb/point_value_spec.rb
108
+ - spec/influxdb/worker_spec.rb
108
109
  - spec/influxdb_spec.rb
109
110
  - spec/max_queue_spec.rb
110
111
  - spec/spec_helper.rb
@@ -136,6 +137,7 @@ test_files:
136
137
  - spec/influxdb/client_spec.rb
137
138
  - spec/influxdb/logger_spec.rb
138
139
  - spec/influxdb/point_value_spec.rb
140
+ - spec/influxdb/worker_spec.rb
139
141
  - spec/influxdb_spec.rb
140
142
  - spec/max_queue_spec.rb
141
143
  - spec/spec_helper.rb