influxdb 0.2.6 → 0.3.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: 122c637f20d98ea27ff046720c702d3bf18b8ff5
4
- data.tar.gz: bc260fe3b1a9bdaf45e517567f7d1a968a464e63
3
+ metadata.gz: a21a286129826d9f88c4ca4e8dc87676b6f017a2
4
+ data.tar.gz: e42cd53060f55865f25b480fd2894a5a375d9961
5
5
  SHA512:
6
- metadata.gz: ef62b971bf3165b918c96699cb3493193d9883b5378f773b8b1ae9204ac5cf6173ef23dcb27b554d10fc61b069a743205fc930684103a9d0daf19e773fa14bd5
7
- data.tar.gz: 70094c9a541fd931329bf6240cf809333a2ce4a7b58f6052bb36bf29bbf5a2b89f10e5d90086cb6b8d743517cc12ae23907e5eccdecfd0e91057294a70cce8df
6
+ metadata.gz: 405f425003836d44d9d7123d6bfd7b24be8f2955737e2922b40743e86cd5434bc7443f7b4f23c4ad6346ed17d27b41836b9eaba92ff0b70d301469617e033b28
7
+ data.tar.gz: 2fe79f2e54e16890cf5cfc6f50cbe45d282cf2f3a241305b6b925542b4f5e2603a60c8e0559d4402647ed586e972a46fd30ebae14368c7bd14f264bb83ea1a52
data/.rubocop.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  AllCops:
2
- # Include gemspec and Rakefile
3
2
  Include:
3
+ - 'Rakefile'
4
+ - '*.gemspec'
4
5
  - 'lib/**/*.rb'
5
- - 'lib/**/*.rake'
6
6
  - 'spec/**/*.rb'
7
7
  Exclude:
8
8
  - 'bin/**/*'
data/.travis.yml CHANGED
@@ -1,16 +1,31 @@
1
+ sudo: required
2
+ dist: trusty
1
3
  language: ruby
2
4
  before_install:
3
5
  - gem update bundler
4
6
  rvm:
5
7
  - 2.0.0
6
- - 2.1.0
7
- - 2.2.0
8
+ - 2.1.10
9
+ - 2.2.4
8
10
  - 2.3.0
9
11
  - ruby-head
10
- - jruby-20mode
11
- - jruby-21mode
12
- - jruby-head
12
+ env:
13
+ - TEST_TASK=spec
13
14
  matrix:
14
15
  allow_failures:
15
16
  - rvm: jruby-head
16
17
  - rvm: ruby-head
18
+ - rvm: jruby-9.0.5.0
19
+ include:
20
+ - rvm: 2.3.0
21
+ env: TEST_TASK=rubocop
22
+ - rvm: jruby-9.0.5.0
23
+ env: JRUBY_OPTS='-J-Xmx256M'
24
+ - rvm: jruby-head
25
+ env: JRUBY_OPTS='-J-Xmx256M'
26
+ fail_fast: true
27
+ addons:
28
+ apt:
29
+ packages:
30
+ - libgmp-dev
31
+ script: bundle exec rake $TEST_TASK
data/CHANGELOG.md ADDED
@@ -0,0 +1,58 @@
1
+ # Changelog
2
+
3
+ For the full commit log, [see here](https://github.com/influxdata/influxdb-ruby/commits/master).
4
+
5
+ ## v0.3.0, released 2016-04-24
6
+
7
+ - Write queries are now checked against 204 No Content responses, in accordance with the official documentation (#128).
8
+ - Async options are now configurabe (#107).
9
+
10
+ ## v0.2.6, released 2016-04-14
11
+
12
+ - Empty tag keys/values are now omitted (#124).
13
+
14
+ ## v0.2.5, released 2016-04-14
15
+
16
+ - Async writer now behaves when stopping the client (#73).
17
+ - Update development dependencies and started enforcing Rubocop styles.
18
+
19
+ ## v0.2.4, released 2016-04-12
20
+
21
+ - Added `InfluxDB::Client#version`, returning the server version (#117).
22
+ - Fixed escaping issues (#119, #121, #135).
23
+ - Interger values are now written as Integer, not as Float value (#131).
24
+ - Return all result series when querying multiple selects (#134).
25
+ - Made host cycling thread safe (#136).
26
+
27
+ ## v0.2.3, released 2015-10-27
28
+
29
+ - Added `epoch` option to client constructor and write methods (#104).
30
+ - Added `#list_user_grants` (#111), `#grant_user_admin_privileges` (#112) and `#alter_retention_policy` (#114) methods.
31
+
32
+ ## v0.2.2, released 2015-07-29
33
+
34
+ - Fixed issues with Async client (#101)
35
+ - Avoid usage of `gsub!` (#102)
36
+
37
+ ## v0.2.1, released 2015-07-25
38
+
39
+ - Fix double quote tags escaping (#98)
40
+
41
+ ## v0.2.0, released 2015-07-20
42
+
43
+ - Large library refactoring (#88, #90)
44
+ - Extract config from client
45
+ - Extract HTTP functionality to separate module
46
+ - Extract InfluxDB management functions to separate modules
47
+ - Add writer concept
48
+ - Refactor specs (add cases)
49
+ - Add 'denormalize' option to config
50
+ - Recognize SeriesNotFound error
51
+ - Update README
52
+ - Add Rubocop config
53
+ - Break support for Ruby < 2
54
+ - Added support for InfluxDB 0.9+ (#92)
55
+
56
+ ## v0.1.9, released 2015-07-04
57
+
58
+ - last version to support InfluxDB 0.8.x
data/README.md CHANGED
@@ -345,7 +345,7 @@ name = 'foobar'
345
345
  influxdb = InfluxDB::Client.new database,
346
346
  username: username,
347
347
  password: password,
348
- async: true
348
+ async: true
349
349
 
350
350
  data = {
351
351
  values: { value: 0 },
@@ -356,6 +356,28 @@ data = {
356
356
  influxdb.write_point(name, data)
357
357
  ```
358
358
 
359
+ Using `async: true` is a shortcut for the following:
360
+
361
+ ``` ruby
362
+ async_options = {
363
+ # number of points to write to the server at once
364
+ max_post_points: 1000,
365
+ # queue capacity
366
+ max_queue_size: 10_000,
367
+ # number of threads
368
+ num_worker_threads: 3,
369
+ # max. time (in seconds) a thread sleeps before
370
+ # checking if there are new jobs in the queue
371
+ sleep_interval: 5
372
+ }
373
+
374
+ influxdb = InfluxDB::Client.new database,
375
+ username: username,
376
+ password: password,
377
+ async: async_options
378
+ ```
379
+
380
+
359
381
  Write data via UDP (note that a retention policy cannot be specified for UDP writes):
360
382
 
361
383
  ``` ruby
data/Rakefile CHANGED
@@ -1,4 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rubocop/rake_task'
3
+
4
+ RuboCop::RakeTask.new
2
5
 
3
6
  targeted_files = ARGV.drop(1)
4
7
  file_pattern = targeted_files.empty? ? 'spec/**/*_spec.rb' : targeted_files
data/influxdb.gemspec CHANGED
@@ -3,13 +3,14 @@ lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'influxdb/version'
5
5
 
6
+ # rubocop:disable Style/SpecialGlobalVars
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = "influxdb"
8
9
  spec.version = InfluxDB::VERSION
9
10
  spec.authors = ["Todd Persen"]
10
11
  spec.email = ["influxdb@googlegroups.com"]
11
- spec.description = %q{This is the official Ruby library for InfluxDB.}
12
- spec.summary = %q{Ruby library for InfluxDB.}
12
+ spec.description = "This is the official Ruby library for InfluxDB."
13
+ spec.summary = "Ruby library for InfluxDB."
13
14
  spec.homepage = "http://influxdb.org"
14
15
  spec.license = "MIT"
15
16
 
@@ -19,13 +20,10 @@ Gem::Specification.new do |spec|
19
20
  spec.require_paths = ["lib"]
20
21
 
21
22
  spec.add_runtime_dependency "json"
23
+ spec.add_runtime_dependency "cause" if RUBY_VERSION < '2.1'
22
24
 
23
- if RUBY_VERSION < '2.1'
24
- spec.add_runtime_dependency "cause"
25
- end
26
-
27
- spec.add_development_dependency "bundler", "~> 1.3"
28
25
  spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "bundler", "~> 1.3"
29
27
  spec.add_development_dependency "rspec", "~> 3.4.0"
30
28
  spec.add_development_dependency "webmock", "~> 1.24.2"
31
29
  spec.add_development_dependency "rubocop", "~> 0.39.0"
@@ -27,7 +27,7 @@ module InfluxDB
27
27
  response = do_request http, Net::HTTP::Post.new(url, headers), data
28
28
 
29
29
  case response
30
- when Net::HTTPSuccess
30
+ when Net::HTTPNoContent
31
31
  return response
32
32
  when Net::HTTPUnauthorized
33
33
  raise InfluxDB::AuthenticationError, response.body
@@ -25,51 +25,22 @@ module InfluxDB
25
25
 
26
26
  attr_reader :async, :udp
27
27
 
28
- # rubocop:disable all
29
28
  def initialize(opts = {})
30
- @database = opts[:database]
31
- @port = opts.fetch(:port, 8086)
32
- @prefix = opts.fetch(:prefix, "".freeze)
33
- @username = opts.fetch(:username, "root".freeze)
34
- @password = opts.fetch(:password, "root".freeze)
35
- @auth_method = AUTH_METHODS.include?(opts[:auth_method]) ? opts[:auth_method] : "params".freeze
36
- @use_ssl = opts.fetch(:use_ssl, false)
37
- @verify_ssl = opts.fetch(:verify_ssl, true)
38
- @ssl_ca_cert = opts.fetch(:ssl_ca_cert, false)
39
- @time_precision = opts.fetch(:time_precision, "s".freeze)
40
- @initial_delay = opts.fetch(:initial_delay, 0.01)
41
- @max_delay = opts.fetch(:max_delay, 30)
42
- @open_timeout = opts.fetch(:write_timeout, 5)
43
- @read_timeout = opts.fetch(:read_timeout, 300)
44
- @async = opts.fetch(:async, false)
45
- @udp = opts.fetch(:udp, false)
46
- @retry = opts.fetch(:retry, nil)
47
- @denormalize = opts.fetch(:denormalize, true)
48
- @epoch = opts.fetch(:epoch, false)
49
-
50
- # load the hosts into a Queue for thread safety
51
- @hosts_queue = Queue.new
52
- Array(opts[:hosts] || opts[:host] || ["localhost"]).each do |host|
53
- @hosts_queue.push(host)
54
- end
29
+ extract_http_options!(opts)
30
+ extract_ssl_options!(opts)
31
+ extract_database_options!(opts)
32
+ extract_writer_options!(opts)
55
33
 
56
- # normalize retry option
57
- case @retry
58
- when Integer
59
- # ok
60
- when true, nil
61
- @retry = -1
62
- when false
63
- @retry = 0
64
- end
34
+ configure_retry! opts.fetch(:retry, nil)
35
+ configure_hosts! opts[:hosts] || opts[:host] || "localhost".freeze
65
36
  end
66
37
 
67
38
  def udp?
68
- !!udp
39
+ udp != false
69
40
  end
70
41
 
71
42
  def async?
72
- !!async
43
+ async != false
73
44
  end
74
45
 
75
46
  def next_host
@@ -85,5 +56,59 @@ module InfluxDB
85
56
  host
86
57
  end
87
58
  end
59
+
60
+ private
61
+
62
+ # rubocop:disable Metrics/AbcSize
63
+ def extract_http_options!(opts)
64
+ @port = opts.fetch :port, 8086
65
+ @prefix = opts.fetch :prefix, "".freeze
66
+ @username = opts.fetch :username, "root".freeze
67
+ @password = opts.fetch :password, "root".freeze
68
+ @open_timeout = opts.fetch :write_timeout, 5
69
+ @read_timeout = opts.fetch :read_timeout, 300
70
+ @max_delay = opts.fetch :max_delay, 30
71
+ @initial_delay = opts.fetch :initial_delay, 0.01
72
+ auth = opts[:auth_method]
73
+ @auth_method = AUTH_METHODS.include?(auth) ? auth : "params".freeze
74
+ end
75
+
76
+ def extract_ssl_options!(opts)
77
+ @use_ssl = opts.fetch :use_ssl, false
78
+ @verify_ssl = opts.fetch :verify_ssl, true
79
+ @ssl_ca_cert = opts.fetch :ssl_ca_cert, false
80
+ end
81
+
82
+ # normalize retry option
83
+ def configure_retry!(value)
84
+ case value
85
+ when Integer
86
+ @retry = value
87
+ when true, nil
88
+ @retry = -1
89
+ when false
90
+ @retry = 0
91
+ end
92
+ end
93
+
94
+ # load the hosts into a Queue for thread safety
95
+ def configure_hosts!(hosts)
96
+ @hosts_queue = Queue.new
97
+ Array(hosts).each do |host|
98
+ @hosts_queue.push(host)
99
+ end
100
+ end
101
+
102
+ def extract_database_options!(opts)
103
+ @database = opts[:database]
104
+ @time_precision = opts.fetch :time_precision, "s".freeze
105
+ @denormalize = opts.fetch :denormalize, true
106
+ @epoch = opts.fetch :epoch, false
107
+ end
108
+
109
+ def extract_writer_options!(opts)
110
+ @async = opts.fetch :async, false
111
+ @udp = opts.fetch :udp, false
112
+ end
88
113
  end
89
114
  end
@@ -1,3 +1,3 @@
1
1
  module InfluxDB # :nodoc:
2
- VERSION = "0.2.6".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
@@ -29,19 +29,31 @@ module InfluxDB
29
29
  end
30
30
 
31
31
  class Worker
32
- attr_reader :client, :queue, :threads
32
+ attr_reader :client,
33
+ :queue,
34
+ :threads,
35
+ :max_post_points,
36
+ :max_queue_size,
37
+ :num_worker_threads,
38
+ :sleep_interval
33
39
 
34
40
  include InfluxDB::Logging
35
41
 
36
- MAX_POST_POINTS = 1000
37
- MAX_QUEUE_SIZE = 10_000
38
- NUM_WORKER_THREADS = 3
39
- SLEEP_INTERVAL = 5
42
+ MAX_POST_POINTS = 1000
43
+ MAX_QUEUE_SIZE = 10_000
44
+ NUM_WORKER_THREADS = 3
45
+ SLEEP_INTERVAL = 5
40
46
 
41
47
  def initialize(client, config)
42
48
  @client = client
43
49
  config = config.is_a?(Hash) ? config : {}
44
- @queue = InfluxDB::MaxQueue.new config.fetch(:max_queue, MAX_QUEUE_SIZE)
50
+
51
+ @max_post_points = config.fetch(:max_post_points, MAX_POST_POINTS)
52
+ @max_queue_size = config.fetch(:max_queue_size, MAX_QUEUE_SIZE)
53
+ @num_worker_threads = config.fetch(:num_worker_threads, NUM_WORKER_THREADS)
54
+ @sleep_interval = config.fetch(:sleep_interval, SLEEP_INTERVAL)
55
+
56
+ @queue = InfluxDB::MaxQueue.new max_queue_size
45
57
 
46
58
  spawn_threads!
47
59
  end
@@ -64,7 +76,7 @@ module InfluxDB
64
76
 
65
77
  def spawn_threads!
66
78
  @threads = []
67
- NUM_WORKER_THREADS.times do |thread_num|
79
+ num_worker_threads.times do |thread_num|
68
80
  log :debug, "Spawning background worker thread #{thread_num}."
69
81
 
70
82
  @threads << Thread.new do
@@ -72,7 +84,7 @@ module InfluxDB
72
84
 
73
85
  until client.stopped?
74
86
  check_background_queue(thread_num)
75
- sleep rand(SLEEP_INTERVAL)
87
+ sleep rand(sleep_interval)
76
88
  end
77
89
 
78
90
  log :debug, "Exit background worker thread #{thread_num}."
@@ -87,7 +99,7 @@ module InfluxDB
87
99
  loop do
88
100
  data = []
89
101
 
90
- while data.size < MAX_POST_POINTS && !queue.empty?
102
+ while data.size < max_post_points && !queue.empty?
91
103
  p = queue.pop(true) rescue next
92
104
  data.push p
93
105
  end
@@ -101,7 +113,7 @@ module InfluxDB
101
113
  puts "Cannot write data: #{e.inspect}"
102
114
  end
103
115
 
104
- break if queue.length > MAX_POST_POINTS
116
+ break if queue.length > max_post_points
105
117
  end
106
118
  end
107
119
 
@@ -2,17 +2,19 @@ require "spec_helper"
2
2
  require "timeout"
3
3
 
4
4
  describe InfluxDB::Client do
5
- let(:subject) { described_class.new(async: true) }
5
+ let(:async_options) { true }
6
+ let(:client) { described_class.new(async: async_options) }
7
+ let(:subject) { client }
6
8
  let(:stub_url) { "http://localhost:8086/write?db=&p=root&precision=s&u=root" }
7
- let(:worker_klass) { InfluxDB::Writer::Async::Worker }
9
+ let(:worker) { client.writer.worker }
8
10
 
9
11
  specify { expect(subject.writer).to be_a(InfluxDB::Writer::Async) }
10
12
 
11
13
  describe "#write_point" do
12
14
  it "sends writes to client" do
13
- post_request = stub_request(:post, stub_url)
15
+ post_request = stub_request(:post, stub_url).to_return(status: 204)
14
16
 
15
- (worker_klass::MAX_POST_POINTS + 100).times do
17
+ (worker.max_post_points + 100).times do
16
18
  subject.write_point('a', {})
17
19
  end
18
20
 
@@ -21,11 +23,11 @@ describe InfluxDB::Client do
21
23
  # responsive and needs a bit more time.
22
24
  timeout_stretch = ENV["TRAVIS"] == "true" ? 10 : 3
23
25
 
24
- Timeout.timeout(timeout_stretch * worker_klass::SLEEP_INTERVAL) do
26
+ Timeout.timeout(timeout_stretch * worker.sleep_interval) do
25
27
  subject.stop!
26
28
  end
27
29
 
28
- subject.writer.worker.threads.each do |t|
30
+ worker.threads.each do |t|
29
31
  expect(t.stop?).to be true
30
32
  end
31
33
 
@@ -34,4 +36,23 @@ describe InfluxDB::Client do
34
36
  expect(post_request).to have_been_requested.at_least_times(2)
35
37
  end
36
38
  end
39
+
40
+ describe "async options" do
41
+ let(:async_options) do
42
+ {
43
+ max_post_points: 10,
44
+ max_queue_size: 100,
45
+ num_worker_threads: 1,
46
+ sleep_interval: 0.5
47
+ }
48
+ end
49
+
50
+ subject { worker }
51
+ before { worker.stop! }
52
+
53
+ specify { expect(subject.max_post_points).to be 10 }
54
+ specify { expect(subject.max_queue_size).to be 100 }
55
+ specify { expect(subject.num_worker_threads).to be 1 }
56
+ specify { expect(subject.sleep_interval).to be_within(0.0001).of(0.5) }
57
+ end
37
58
  end
@@ -1,33 +1,35 @@
1
- require 'spec_helper'
2
- require 'json'
1
+ require "spec_helper"
3
2
 
4
3
  describe InfluxDB::Client do
5
4
  let(:subject) do
6
- described_class.new(
7
- 'database',
8
- {
9
- host: 'influxdb.test',
10
- port: 9999,
11
- username: 'username',
12
- password: 'password',
13
- time_precision: 's'
14
- }.merge(args)
15
- )
5
+ described_class.new "database", {
6
+ host: "influxdb.test",
7
+ port: 9999,
8
+ username: "username",
9
+ password: "password",
10
+ time_precision: "s"
11
+ }.merge(args)
16
12
  end
17
13
 
18
14
  let(:args) { {} }
19
15
 
20
- describe '#query' do
16
+ describe "#query" do
17
+ let(:query) { "SELECT value FROM requests_per_minute WHERE time > 1437019900" }
18
+ let(:response) do
19
+ { "results" => [{ "series" => [{ "name" => "requests_per_minute",
20
+ "columns" => %w( time value ) }] }] }
21
+ end
22
+
23
+ before do
24
+ stub_request(:get, "http://influxdb.test:9999/query")
25
+ .with(query: { db: "database", precision: "s", u: "username", p: "password", q: query })
26
+ .to_return(body: JSON.generate(response), status: 200)
27
+ end
21
28
 
22
- it 'should handle responses with no values' do
29
+ it "should handle responses with no values" do
23
30
  # Some requests (such as trying to retrieve values from the future)
24
- # return a result with no 'values' key set.
25
- query = 'SELECT value FROM requests_per_minute WHERE time > 1437019900'
26
- response = {'results'=>[{'series'=>[{'name'=>'requests_per_minute' ,'columns' => ['time','value']}]}]}
27
- stub_request(:get, 'http://influxdb.test:9999/query').with(
28
- query: { db: 'database', precision: 's', u: 'username', p: 'password', q: query }
29
- ).to_return(body: JSON.generate(response), status: 200)
30
- expected_result = [{'name'=>'requests_per_minute', 'tags'=>nil, 'values'=>[]}]
31
+ # return a result with no "values" key set.
32
+ expected_result = [{ "name" => "requests_per_minute", "tags" => nil, "values" => [] }]
31
33
  expect(subject.query(query)).to eq(expected_result)
32
34
  end
33
35
  end
@@ -145,9 +145,9 @@ describe InfluxDB::Client do
145
145
  let(:list_query) { "SHOW GRANTS FOR #{user}" }
146
146
 
147
147
  before do
148
- stub_request(:get, "http://influxdb.test:9999/query").with(
149
- query: { u: "username", p: "password", q: list_query},
150
- ).to_return(:status => 200, :body => "", :headers => {})
148
+ stub_request(:get, "http://influxdb.test:9999/query")
149
+ .with(query: { u: "username", p: "password", q: list_query })
150
+ .to_return(status: 200, body: "", headers: {})
151
151
  end
152
152
 
153
153
  it "should GET for a user" do
@@ -3,20 +3,25 @@ require "json"
3
3
 
4
4
  describe InfluxDB::Client do
5
5
  let(:subject) do
6
- described_class.new(
7
- "database",
8
- {
9
- host: "influxdb.test",
10
- port: 9999,
11
- username: "username",
12
- password: "password",
13
- time_precision: "s"
14
- }.merge(args)
15
- )
6
+ described_class.new "database", {
7
+ host: "influxdb.test",
8
+ port: 9999,
9
+ username: "username",
10
+ password: "password",
11
+ time_precision: "s"
12
+ }.merge(args)
16
13
  end
17
14
 
18
- let(:args) { {} }
19
- let(:database) { subject.config.database }
15
+ let(:args) { {} }
16
+ let(:database) { subject.config.database }
17
+ let(:extra_params) { {} }
18
+ let(:response) {}
19
+
20
+ before do
21
+ stub_request(:get, "http://influxdb.test:9999/query")
22
+ .with(query: { q: query, u: "username", p: "password", precision: 's', db: database }.merge(extra_params))
23
+ .to_return(body: JSON.generate(response))
24
+ end
20
25
 
21
26
  describe "#query" do
22
27
  context "with single series with multiple points" do
@@ -32,12 +37,6 @@ describe InfluxDB::Client do
32
37
  end
33
38
  let(:query) { 'SELECT * FROM cpu' }
34
39
 
35
- before do
36
- stub_request(:get, "http://influxdb.test:9999/query").with(
37
- query: { q: query, u: "username", p: "password", precision: 's', db: database }
38
- ).to_return(body: JSON.generate(response))
39
- end
40
-
41
40
  it "should return array with single hash containing multiple values" do
42
41
  expect(subject.query(query)).to eq(expected_result)
43
42
  end
@@ -45,8 +44,8 @@ describe InfluxDB::Client do
45
44
 
46
45
  context "with series with different tags" do
47
46
  let(:response) do
48
- { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
49
- { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] }
47
+ { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
48
+ { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] }
50
49
  end
51
50
  let(:expected_result) do
52
51
  [{ "name" => "cpu", "tags" => { "region" => "pl" },
@@ -57,12 +56,6 @@ describe InfluxDB::Client do
57
56
  end
58
57
  let(:query) { 'SELECT * FROM cpu' }
59
58
 
60
- before do
61
- stub_request(:get, "http://influxdb.test:9999/query").with(
62
- query: { q: query, u: "username", p: "password", precision: 's', db: database }
63
- ).to_return(body: JSON.generate(response))
64
- end
65
-
66
59
  it "should return array with 2 elements grouped by tags" do
67
60
  expect(subject.query(query)).to eq(expected_result)
68
61
  end
@@ -70,10 +63,10 @@ describe InfluxDB::Client do
70
63
 
71
64
  context "with multiple series with different tags" do
72
65
  let(:response) do
73
- { "results" => [{ "series" => [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 327]] },
74
- { "name" => "access_times.service_1", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 873]] },
75
- { "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 943]] },
76
- { "name" => "access_times.service_2", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 606]] }] }] }
66
+ { "results" => [{ "series" => [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 327]] },
67
+ { "name" => "access_times.service_1", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 873]] },
68
+ { "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 943]] },
69
+ { "name" => "access_times.service_2", "tags" => { "code" => "500", "result" => "failure", "status" => "Internal Server Error" }, "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 606]] }] }] }
77
70
  end
78
71
  let(:expected_result) do
79
72
  [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "values" => [{ "time" => "2015-07-08T07:15:22Z", "value" => 327 }] },
@@ -83,12 +76,6 @@ describe InfluxDB::Client do
83
76
  end
84
77
  let(:query) { "SELECT * FROM /access_times.*/" }
85
78
 
86
- before do
87
- stub_request(:get, "http://influxdb.test:9999/query").with(
88
- query: { q: query, u: "username", p: "password", precision: 's', db: database }
89
- ).to_return(body: JSON.generate(response))
90
- end
91
-
92
79
  it "should return array with 4 elements grouped by name and tags" do
93
80
  expect(subject.query(query)).to eq(expected_result)
94
81
  end
@@ -96,8 +83,8 @@ describe InfluxDB::Client do
96
83
 
97
84
  context "with multiple series for explicit value only" do
98
85
  let(:response) do
99
- { "results" => [{ "series" => [{ "name" => "access_times.service_1", "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 873], ["2015-07-08T07:15:22Z", 327]] },
100
- { "name" => "access_times.service_2", "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 606], ["2015-07-08T07:15:22Z", 943]] }] }] }
86
+ { "results" => [{ "series" => [{ "name" => "access_times.service_1", "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 873], ["2015-07-08T07:15:22Z", 327]] },
87
+ { "name" => "access_times.service_2", "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 606], ["2015-07-08T07:15:22Z", 943]] }] }] }
101
88
  end
102
89
  let(:expected_result) do
103
90
  [{ "name" => "access_times.service_1", "tags" => nil, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 873 }, { "time" => "2015-07-08T07:15:22Z", "value" => 327 }] },
@@ -105,12 +92,6 @@ describe InfluxDB::Client do
105
92
  end
106
93
  let(:query) { "SELECT value FROM /access_times.*/" }
107
94
 
108
- before do
109
- stub_request(:get, "http://influxdb.test:9999/query").with(
110
- query: { q: query, u: "username", p: "password", precision: 's', db: database }
111
- ).to_return(body: JSON.generate(response))
112
- end
113
-
114
95
  it "should return array with 2 elements grouped by name only and no tags" do
115
96
  expect(subject.query(query)).to eq(expected_result)
116
97
  end
@@ -118,8 +99,8 @@ describe InfluxDB::Client do
118
99
 
119
100
  context "with a block" do
120
101
  let(:response) do
121
- { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
122
- { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] }
102
+ { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
103
+ { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] }
123
104
  end
124
105
 
125
106
  let(:expected_result) do
@@ -131,12 +112,6 @@ describe InfluxDB::Client do
131
112
  end
132
113
  let(:query) { 'SELECT * FROM cpu' }
133
114
 
134
- before do
135
- stub_request(:get, "http://influxdb.test:9999/query").with(
136
- query: { q: query, u: "username", p: "password", precision: 's', db: database }
137
- ).to_return(body: JSON.generate(response))
138
- end
139
-
140
115
  it "should accept a block and yield name, tags and points" do
141
116
  results = []
142
117
  subject.query(query) do |name, tags, points|
@@ -147,33 +122,23 @@ describe InfluxDB::Client do
147
122
  end
148
123
 
149
124
  context "with epoch set to seconds" do
150
- let(:args) { {epoch: 's'} }
125
+ let(:args) { { epoch: 's' } }
126
+ let(:extra_params) { { epoch: 's' } }
151
127
 
152
128
  let(:response) do
153
- { "results" =>
154
- [{ "series" =>
155
- [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [[1438580576, 34, 0.343443]] },
156
- { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [[1438612976, 92, 0.3445], [1438612989, 68, 0.8787]] }
157
- ]
158
- }]
159
- }
129
+ { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [[1_438_580_576, 34, 0.343443]] },
130
+ { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [[1_438_612_976, 92, 0.3445], [1_438_612_989, 68, 0.8787]] }] }] }
160
131
  end
161
132
  let(:expected_result) do
162
133
  [{ "name" => "cpu", "tags" => { "region" => "pl" },
163
- "values" => [{ "time" => 1438580576, "temp" => 34, "value" => 0.343443 }] },
134
+ "values" => [{ "time" => 1_438_580_576, "temp" => 34, "value" => 0.343443 }] },
164
135
  { "name" => "cpu", "tags" => { "region" => "us" },
165
- "values" => [{ "time" => 1438612976, "temp" => 92, "value" => 0.3445 },
166
- { "time" => 1438612989, "temp" => 68, "value" => 0.8787 }]
136
+ "values" => [{ "time" => 1_438_612_976, "temp" => 92, "value" => 0.3445 },
137
+ { "time" => 1_438_612_989, "temp" => 68, "value" => 0.8787 }]
167
138
  }]
168
139
  end
169
140
  let(:query) { 'SELECT * FROM cpu' }
170
141
 
171
- before do
172
- stub_request(:get, "http://influxdb.test:9999/query").with(
173
- query: { q: query, u: "username", p: "password", precision: 's', db: database, epoch: 's' }
174
- ).to_return(body: JSON.generate(response))
175
- end
176
-
177
142
  it "should return results with integer timestamp" do
178
143
  expect(subject.query(query)).to eq(expected_result)
179
144
  end
@@ -188,24 +153,18 @@ describe InfluxDB::Client do
188
153
  "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] },
189
154
  { "series" => [{ "name" => "memory", "tags" => { "region" => "us" },
190
155
  "columns" => %w(time free total),
191
- "values" => [["2015-07-07T14:58:37Z", 96468992, 134217728], ["2015-07-07T14:59:09Z", 71303168, 134217728]] }] }] }
156
+ "values" => [["2015-07-07T14:58:37Z", 96_468_992, 134_217_728], ["2015-07-07T14:59:09Z", 71_303_168, 134_217_728]] }] }] }
192
157
  end
193
158
  let(:expected_result) do
194
159
  [{ "name" => "cpu", "tags" => { "region" => "us" },
195
160
  "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 },
196
161
  { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] },
197
162
  { "name" => "memory", "tags" => { "region" => "us" },
198
- "values" => [{ "time" => "2015-07-07T14:58:37Z", "free" => 92*2**20, "total" => 128*2**20 },
199
- { "time" => "2015-07-07T14:59:09Z", "free" => 68*2**20, "total" => 128*2**20 }] }]
163
+ "values" => [{ "time" => "2015-07-07T14:58:37Z", "free" => 92 * 2**20, "total" => 128 * 2**20 },
164
+ { "time" => "2015-07-07T14:59:09Z", "free" => 68 * 2**20, "total" => 128 * 2**20 }] }]
200
165
  end
201
166
  let(:query) { 'SELECT * FROM cpu; SELECT * FROM memory' }
202
167
 
203
- before do
204
- stub_request(:get, "http://influxdb.test:9999/query").with(
205
- query: { q: query, u: "username", p: "password", precision: 's', db: database }
206
- ).to_return(body: JSON.generate(response))
207
- end
208
-
209
168
  it "should return array with single hash containing multiple values" do
210
169
  expect(subject.query(query)).to eq(expected_result)
211
170
  end
@@ -213,10 +172,10 @@ describe InfluxDB::Client do
213
172
 
214
173
  context "with series with different tags" do
215
174
  let(:response) do
216
- { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
217
- { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] },
218
- { "series" => [{ "name" => "memory", "tags" => { "region" => "pl" }, "columns" => %w(time free total), "values" => [["2015-07-07T15:13:04Z", 35651584, 134217728]] },
219
- { "name" => "memory", "tags" => { "region" => "us" }, "columns" => %w(time free total), "values" => [["2015-07-07T14:58:37Z", 96468992, 134217728], ["2015-07-07T14:59:09Z", 71303168, 134217728]] }] }] }
175
+ { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
176
+ { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] },
177
+ { "series" => [{ "name" => "memory", "tags" => { "region" => "pl" }, "columns" => %w(time free total), "values" => [["2015-07-07T15:13:04Z", 35_651_584, 134_217_728]] },
178
+ { "name" => "memory", "tags" => { "region" => "us" }, "columns" => %w(time free total), "values" => [["2015-07-07T14:58:37Z", 96_468_992, 134_217_728], ["2015-07-07T14:59:09Z", 71_303_168, 134_217_728]] }] }] }
220
179
  end
221
180
  let(:expected_result) do
222
181
  [{ "name" => "cpu", "tags" => { "region" => "pl" },
@@ -225,19 +184,13 @@ describe InfluxDB::Client do
225
184
  "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 },
226
185
  { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] },
227
186
  { "name" => "memory", "tags" => { "region" => "pl" },
228
- "values" => [{ "time" => "2015-07-07T15:13:04Z", "free" => 34*2**20, "total" => 128*2**20 }] },
187
+ "values" => [{ "time" => "2015-07-07T15:13:04Z", "free" => 34 * 2**20, "total" => 128 * 2**20 }] },
229
188
  { "name" => "memory", "tags" => { "region" => "us" },
230
- "values" => [{ "time" => "2015-07-07T14:58:37Z", "free" => 92*2**20, "total" => 128*2**20 },
231
- { "time" => "2015-07-07T14:59:09Z", "free" => 68*2**20, "total" => 128*2**20 }] }]
189
+ "values" => [{ "time" => "2015-07-07T14:58:37Z", "free" => 92 * 2**20, "total" => 128 * 2**20 },
190
+ { "time" => "2015-07-07T14:59:09Z", "free" => 68 * 2**20, "total" => 128 * 2**20 }] }]
232
191
  end
233
192
  let(:query) { 'SELECT * FROM cpu; SELECT * FROM memory' }
234
193
 
235
- before do
236
- stub_request(:get, "http://influxdb.test:9999/query").with(
237
- query: { q: query, u: "username", p: "password", precision: 's', db: database }
238
- ).to_return(body: JSON.generate(response))
239
- end
240
-
241
194
  it "should return array with 2 elements grouped by tags" do
242
195
  expect(subject.query(query)).to eq(expected_result)
243
196
  end
@@ -245,10 +198,10 @@ describe InfluxDB::Client do
245
198
 
246
199
  context "with a block" do
247
200
  let(:response) do
248
- { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
249
- { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] },
250
- { "series" => [{ "name" => "memory", "tags" => { "region" => "pl" }, "columns" => %w(time free total), "values" => [["2015-07-07T15:13:04Z", 35651584, 134217728]] },
251
- { "name" => "memory", "tags" => { "region" => "us" }, "columns" => %w(time free total), "values" => [["2015-07-07T14:58:37Z", 96468992, 134217728], ["2015-07-07T14:59:09Z", 71303168, 134217728]] }] }] }
201
+ { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
202
+ { "name" => "cpu", "tags" => { "region" => "us" }, "columns" => %w(time temp value), "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] },
203
+ { "series" => [{ "name" => "memory", "tags" => { "region" => "pl" }, "columns" => %w(time free total), "values" => [["2015-07-07T15:13:04Z", 35_651_584, 134_217_728]] },
204
+ { "name" => "memory", "tags" => { "region" => "us" }, "columns" => %w(time free total), "values" => [["2015-07-07T14:58:37Z", 96_468_992, 134_217_728], ["2015-07-07T14:59:09Z", 71_303_168, 134_217_728]] }] }] }
252
205
  end
253
206
 
254
207
  let(:expected_result) do
@@ -258,19 +211,13 @@ describe InfluxDB::Client do
258
211
  "values" => [{ "time" => "2015-07-07T14:58:37Z", "temp" => 92, "value" => 0.3445 },
259
212
  { "time" => "2015-07-07T14:59:09Z", "temp" => 68, "value" => 0.8787 }] },
260
213
  { "name" => "memory", "tags" => { "region" => "pl" },
261
- "values" => [{ "time" => "2015-07-07T15:13:04Z", "free" => 34*2**20, "total" => 128*2**20 }] },
214
+ "values" => [{ "time" => "2015-07-07T15:13:04Z", "free" => 34 * 2**20, "total" => 128 * 2**20 }] },
262
215
  { "name" => "memory", "tags" => { "region" => "us" },
263
- "values" => [{ "time" => "2015-07-07T14:58:37Z", "free" => 92*2**20, "total" => 128*2**20 },
264
- { "time" => "2015-07-07T14:59:09Z", "free" => 68*2**20, "total" => 128*2**20 }] }]
216
+ "values" => [{ "time" => "2015-07-07T14:58:37Z", "free" => 92 * 2**20, "total" => 128 * 2**20 },
217
+ { "time" => "2015-07-07T14:59:09Z", "free" => 68 * 2**20, "total" => 128 * 2**20 }] }]
265
218
  end
266
219
  let(:query) { 'SELECT * FROM cpu; SELECT * FROM memory' }
267
220
 
268
- before do
269
- stub_request(:get, "http://influxdb.test:9999/query").with(
270
- query: { q: query, u: "username", p: "password", precision: 's', db: database }
271
- ).to_return(body: JSON.generate(response))
272
- end
273
-
274
221
  it "should accept a block and yield name, tags and points" do
275
222
  results = []
276
223
  subject.query(query) do |name, tags, points|
@@ -23,7 +23,7 @@ describe InfluxDB::Client do
23
23
  let(:series) { "cpu" }
24
24
  let(:data) do
25
25
  { tags: { region: 'us', host: 'server_1' },
26
- values: { temp: 88, value: 54 } }
26
+ values: { temp: 88, value: 54 } }
27
27
  end
28
28
  let(:body) do
29
29
  InfluxDB::PointValue.new(data.merge(series: series)).dump
@@ -72,15 +72,17 @@ describe InfluxDB::Client do
72
72
  context "when retry is -1" do
73
73
  let(:args) { { retry: -1 } }
74
74
  before do
75
- stub_request(:post, "http://influxdb.test:9999/write").with(
76
- query: { u: "username", p: "password", precision: 's', db: database },
77
- headers: { "Content-Type" => "application/octet-stream" },
78
- body: body
79
- ).to_raise(Timeout::Error).then
75
+ stub_request(:post, "http://influxdb.test:9999/write")
76
+ .with(
77
+ query: { u: "username", p: "password", precision: 's', db: database },
78
+ headers: { "Content-Type" => "application/octet-stream" },
79
+ body: body
80
+ )
80
81
  .to_raise(Timeout::Error).then
81
82
  .to_raise(Timeout::Error).then
82
83
  .to_raise(Timeout::Error).then
83
- .to_return(status: 200)
84
+ .to_raise(Timeout::Error).then
85
+ .to_return(status: 204)
84
86
  end
85
87
 
86
88
  it "keep trying until get the connection" do
@@ -3,16 +3,13 @@ require "json"
3
3
 
4
4
  describe InfluxDB::Client do
5
5
  let(:subject) do
6
- described_class.new(
7
- "database",
8
- {
9
- host: "influxdb.test",
10
- port: 9999,
11
- username: "username",
12
- password: "password",
13
- time_precision: "s"
14
- }.merge(args)
15
- )
6
+ described_class.new "database", {
7
+ host: "influxdb.test",
8
+ port: 9999,
9
+ username: "username",
10
+ password: "password",
11
+ time_precision: "s"
12
+ }.merge(args)
16
13
  end
17
14
 
18
15
  let(:args) { {} }
@@ -23,7 +20,7 @@ describe InfluxDB::Client do
23
20
  let(:series) { "cpu" }
24
21
  let(:data) do
25
22
  { tags: { region: 'us', host: 'server_1' },
26
- values: { temp: 88, value: 54 } }
23
+ values: { temp: 88, value: 54 } }
27
24
  end
28
25
  let(:body) do
29
26
  InfluxDB::PointValue.new(data.merge(series: series)).dump
@@ -34,11 +31,11 @@ describe InfluxDB::Client do
34
31
  query: { u: "username", p: "password", precision: 's', db: database },
35
32
  headers: { "Content-Type" => "application/octet-stream" },
36
33
  body: body
37
- )
34
+ ).to_return(status: 204)
38
35
  end
39
36
 
40
37
  it "should POST to add single point" do
41
- expect(subject.write_point(series, data)).to be_a(Net::HTTPOK)
38
+ expect(subject.write_point(series, data)).to be_a(Net::HTTPNoContent)
42
39
  end
43
40
 
44
41
  it "should not mutate data object" do
@@ -52,16 +49,12 @@ describe InfluxDB::Client do
52
49
  describe "#write_points" do
53
50
  context "with multiple series" do
54
51
  let(:data) do
55
- [{
56
- series: 'cpu',
57
- tags: { region: 'us', host: 'server_1' },
58
- values: { temp: 88, value: 54 }
59
- },
60
- {
61
- series: 'gpu',
62
- tags: { region: 'uk', host: 'server_5' },
63
- values: { value: 0.5435345 }
64
- }]
52
+ [{ series: 'cpu',
53
+ tags: { region: 'us', host: 'server_1' },
54
+ values: { temp: 88, value: 54 } },
55
+ { series: 'gpu',
56
+ tags: { region: 'uk', host: 'server_5' },
57
+ values: { value: 0.5435345 } }]
65
58
  end
66
59
  let(:body) do
67
60
  data.map do |point|
@@ -74,24 +67,20 @@ describe InfluxDB::Client do
74
67
  query: { u: "username", p: "password", precision: 's', db: database },
75
68
  headers: { "Content-Type" => "application/octet-stream" },
76
69
  body: body
77
- )
70
+ ).to_return(status: 204)
78
71
  end
79
72
 
80
73
  it "should POST multiple points" do
81
- expect(subject.write_points(data)).to be_a(Net::HTTPOK)
74
+ expect(subject.write_points(data)).to be_a(Net::HTTPNoContent)
82
75
  end
83
76
  end
84
77
 
85
78
  context "with no tags" do
86
79
  let(:data) do
87
- [{
88
- series: 'cpu',
89
- values: { temp: 88, value: 54 }
90
- },
91
- {
92
- series: 'gpu',
93
- values: { value: 0.5435345 }
94
- }]
80
+ [{ series: 'cpu',
81
+ values: { temp: 88, value: 54 } },
82
+ { series: 'gpu',
83
+ values: { value: 0.5435345 } }]
95
84
  end
96
85
  let(:body) do
97
86
  data.map do |point|
@@ -104,26 +93,22 @@ describe InfluxDB::Client do
104
93
  query: { u: "username", p: "password", precision: 's', db: database },
105
94
  headers: { "Content-Type" => "application/octet-stream" },
106
95
  body: body
107
- )
96
+ ).to_return(status: 204)
108
97
  end
109
98
 
110
99
  it "should POST multiple points" do
111
- expect(subject.write_points(data)).to be_a(Net::HTTPOK)
100
+ expect(subject.write_points(data)).to be_a(Net::HTTPNoContent)
112
101
  end
113
102
  end
114
103
 
115
104
  context "with time precision set to milisceconds" do
116
105
  let(:data) do
117
- [{
118
- series: 'cpu',
119
- values: { temp: 88, value: 54 },
120
- timestamp: (Time.now.to_f * 1000).to_i
121
- },
122
- {
123
- series: 'gpu',
106
+ [{ series: 'cpu',
107
+ values: { temp: 88, value: 54 },
108
+ timestamp: (Time.now.to_f * 1000).to_i },
109
+ { series: 'gpu',
124
110
  values: { value: 0.5435345 },
125
- timestamp: (Time.now.to_f * 1000).to_i
126
- }]
111
+ timestamp: (Time.now.to_f * 1000).to_i }]
127
112
  end
128
113
 
129
114
  let(:body) do
@@ -137,23 +122,19 @@ describe InfluxDB::Client do
137
122
  query: { u: "username", p: "password", precision: 'm', db: database },
138
123
  headers: { "Content-Type" => "application/octet-stream" },
139
124
  body: body
140
- )
125
+ ).to_return(status: 204)
141
126
  end
142
127
  it "should POST multiple points" do
143
- expect(subject.write_points(data, 'm')).to be_a(Net::HTTPOK)
128
+ expect(subject.write_points(data, 'm')).to be_a(Net::HTTPNoContent)
144
129
  end
145
130
  end
146
131
 
147
132
  context "with retention policy" do
148
133
  let(:data) do
149
- [{
150
- series: 'cpu',
151
- values: { temp: 88, value: 54 }
152
- },
153
- {
154
- series: 'gpu',
155
- values: { value: 0.5435345 }
156
- }]
134
+ [{ series: 'cpu',
135
+ values: { temp: 88, value: 54 } },
136
+ { series: 'gpu',
137
+ values: { value: 0.5435345 } }]
157
138
  end
158
139
 
159
140
  let(:body) do
@@ -167,10 +148,10 @@ describe InfluxDB::Client do
167
148
  query: { u: "username", p: "password", precision: 's', db: database, rp: 'rp_1_hour' },
168
149
  headers: { "Content-Type" => "application/octet-stream" },
169
150
  body: body
170
- )
151
+ ).to_return(status: 204)
171
152
  end
172
153
  it "should POST multiple points" do
173
- expect(subject.write_points(data, nil, 'rp_1_hour')).to be_a(Net::HTTPOK)
154
+ expect(subject.write_points(data, nil, 'rp_1_hour')).to be_a(Net::HTTPNoContent)
174
155
  end
175
156
  end
176
157
  end
@@ -31,8 +31,8 @@ describe InfluxDB::Client do
31
31
  end
32
32
 
33
33
  it "POST" do
34
- stub_request(:post, stub_url)
35
- expect(subject.post(url, {})).to be_a(Net::HTTPOK)
34
+ stub_request(:post, stub_url).to_return(status: 204)
35
+ expect(subject.post(url, {})).to be_a(Net::HTTPNoContent)
36
36
  end
37
37
  end
38
38
 
@@ -66,8 +66,8 @@ describe InfluxDB::Client do
66
66
 
67
67
  describe "GET #version" do
68
68
  it "returns 1.1.1" do
69
- stub_request(:get, "http://influxdb.test:9999/ping").to_return(
70
- { :status => 204, :headers => {'x-influxdb-version' => '1.1.1'} })
69
+ stub_request(:get, "http://influxdb.test:9999/ping")
70
+ .to_return(status: 204, headers: { 'x-influxdb-version' => '1.1.1' })
71
71
 
72
72
  expect(subject.version).to eq('1.1.1')
73
73
  end
@@ -10,8 +10,11 @@ describe InfluxDB::Logging do
10
10
  end
11
11
  end
12
12
 
13
- before { @old_logger = InfluxDB::Logging.logger }
14
- after { InfluxDB::Logging.logger = @old_logger }
13
+ around do |example|
14
+ old_logger = InfluxDB::Logging.logger
15
+ example.call
16
+ InfluxDB::Logging.logger = old_logger
17
+ end
15
18
 
16
19
  it "has a default logger" do
17
20
  expect(InfluxDB::Logging.logger).to be_a(Logger)
@@ -5,14 +5,14 @@ describe InfluxDB::PointValue do
5
5
  let(:data) do
6
6
  {
7
7
  series: '1= ,"\\1',
8
- tags: {'2= ,"\\2' => '3= ,"\\3'},
9
- values: {'4= ,"\\4' => '5= ,"\\5'},
8
+ tags: { '2= ,"\\2' => '3= ,"\\3' },
9
+ values: { '4= ,"\\4' => '5= ,"\\5' }
10
10
  }
11
11
  end
12
12
 
13
13
  it 'should escape correctly' do
14
14
  point = InfluxDB::PointValue.new(data)
15
- expected = %(1=\\ \\,"\\1,2\\=\\ \\,"\\2=3\\=\\ \\,"\\3 )+
15
+ expected = %(1=\\ \\,"\\1,2\\=\\ \\,"\\2=3\\=\\ \\,"\\3 ) +
16
16
  %(4\\=\\ \\,\\"\\4="5= ,\\"\\5")
17
17
  expect(point.dump).to eq(expected)
18
18
  end
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,7 @@ end
8
8
  RSpec.configure do |config|
9
9
  config.color = ENV["TRAVIS"] != "true"
10
10
 
11
+ # rubocop:disable Style/ConditionalAssignment
11
12
  if config.files_to_run.one? || ENV["TRAVIS"] == "true"
12
13
  config.formatter = :documentation
13
14
  else
@@ -19,8 +20,8 @@ RSpec.configure do |config|
19
20
  logfile = File.open("tmp/spec.log", File::WRONLY | File::TRUNC | File::CREAT)
20
21
 
21
22
  InfluxDB::Logging.logger = Logger.new(logfile).tap do |logger|
22
- logger.formatter = ->(severity, _datetime, progname, message) {
23
- "%-5s - %s: %s\n" % [ severity, progname, message ]
23
+ logger.formatter = proc {|severity, _datetime, progname, message|
24
+ "%-5s - %s: %s\n".format severity, progname, message
24
25
  }
25
26
  end
26
27
 
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.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Persen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-14 00:00:00.000000000 Z
11
+ date: 2016-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -25,33 +25,33 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: bundler
28
+ name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.3'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.3'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '1.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '1.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -104,6 +104,7 @@ files:
104
104
  - ".gitignore"
105
105
  - ".rubocop.yml"
106
106
  - ".travis.yml"
107
+ - CHANGELOG.md
107
108
  - Gemfile
108
109
  - LICENSE.txt
109
110
  - README.md