influxdb 0.2.4 → 0.2.5

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: a1cd5af0d4500c96303b8c3c336926772eefedde
4
- data.tar.gz: f5b17bce835b6973d763a0b0faad0d1a4882beb1
3
+ metadata.gz: 09287aa2a00c9ec031281fbdbd081c4f599573d2
4
+ data.tar.gz: 9b454a640b3c2ff8c59b721a3bb5501910344ae5
5
5
  SHA512:
6
- metadata.gz: a9a1e9d0df4907d754ab2fe0b7898b5852a0f9541f2a36ac12d0c2d6e0701406b88ff7d58461ead70b4c6833dd3bffc0c6048c3003911b3788ab18e9878101a1
7
- data.tar.gz: 6d6703b9f341b8d1bb791a4548172d588165d537896b122c8d4fc6f902ad88b97d872fb15c1e078ddb36a3ec1341e7c9d3113b54d082659a295f5f803887d5c9
6
+ metadata.gz: 8df6f43cd2e34213ca3c7fb0e240cd6c7e331f738193ca975a398ca6c9980477a643245c6042741889eda133158b32bdcaf63886741c6218971e579fc2aa162b
7
+ data.tar.gz: 35f5c3d665848354082570e7dec081838084f5ce3db3b0fff2900ed38fb6bab392281dbde969632e8a70e4605ab32edf7e63395cceb65accdd73c103bdf36056
data/.gitignore CHANGED
@@ -14,6 +14,7 @@ tmp
14
14
  Gemfile.lock
15
15
  .rvmrc
16
16
  .ruby-version
17
+ .ruby-gemset
17
18
 
18
19
  # YARD artifacts
19
20
  .yardoc
@@ -6,15 +6,17 @@ AllCops:
6
6
  - 'spec/**/*.rb'
7
7
  Exclude:
8
8
  - 'bin/**/*'
9
- RunRailsCops: false
10
9
  DisplayCopNames: true
11
10
  StyleGuideCopsOnly: false
12
11
 
12
+ Rails:
13
+ Enabled: false
14
+
13
15
  Style/Documentation:
14
16
  Exclude:
15
17
  - 'spec/**/*.rb'
16
18
 
17
- Style/StringLiterals:
19
+ Style/StringLiterals:
18
20
  Enabled: false
19
21
 
20
22
  Style/BlockDelimiters:
@@ -38,4 +40,4 @@ Metrics/LineLength:
38
40
 
39
41
  Metrics/MethodLength:
40
42
  Exclude:
41
- - 'spec/**/*.rb'
43
+ - 'spec/**/*.rb'
@@ -9,3 +9,8 @@ rvm:
9
9
  - ruby-head
10
10
  - jruby-20mode
11
11
  - jruby-21mode
12
+ - jruby-head
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: jruby-head
16
+ - rvm: ruby-head
data/README.md CHANGED
@@ -3,7 +3,7 @@ influxdb-ruby
3
3
 
4
4
  [![Build Status](https://travis-ci.org/influxdata/influxdb-ruby.svg?branch=master)](https://travis-ci.org/influxdata/influxdb-ruby)
5
5
 
6
- The official ruby client library for [InfluxDB](https://influxdata.com/time-series-platform/influxdb/). Maintained by [@toddboom](https://github.com/toddboom).
6
+ The official ruby client library for [InfluxDB](https://influxdata.com/time-series-platform/influxdb/). Maintained by [@toddboom](https://github.com/toddboom) and [@dmke](https://github.com/dmke).
7
7
 
8
8
  > **Support for InfluxDB v0.8.x is now deprecated**. The final version of this library that will support the older InfluxDB interface is `v0.1.9`, which is available as a gem and tagged on this repository. If you're reading this message, then you should only expect support for InfluxDB v0.9.1 and higher.
9
9
 
data/Rakefile CHANGED
@@ -10,11 +10,6 @@ RSpec::Core::RakeTask.new(:spec) do |t|
10
10
  t.pattern = FileList[file_pattern]
11
11
  end
12
12
 
13
- RSpec.configure do |config|
14
- config.color = true
15
- config.formatter = :documentation
16
- end
17
-
18
13
  task default: :spec
19
14
 
20
15
  task :console do
@@ -24,8 +24,9 @@ Gem::Specification.new do |spec|
24
24
  spec.add_runtime_dependency "cause"
25
25
  end
26
26
 
27
- spec.add_development_dependency "bundler", "~> 1.3"
27
+ spec.add_development_dependency "bundler", "~> 1.3"
28
28
  spec.add_development_dependency "rake"
29
- spec.add_development_dependency "rspec", "~> 3.0.0"
30
- spec.add_development_dependency "webmock", "~> 1.21.0"
29
+ spec.add_development_dependency "rspec", "~> 3.4.0"
30
+ spec.add_development_dependency "webmock", "~> 1.24.2"
31
+ spec.add_development_dependency "rubocop", "~> 0.39.0"
31
32
  end
@@ -1,11 +1,8 @@
1
1
  require 'json'
2
- require 'cause' if RUBY_VERSION < '2.1'
2
+ require 'cause' unless Exception.instance_methods.include?(:cause)
3
3
  require 'thread'
4
4
 
5
5
  module InfluxDB
6
- # rubocop:disable Metrics/MethodLength
7
- # rubocop:disable Metrics/AbcSize
8
-
9
6
  # InfluxDB client class
10
7
  class Client
11
8
  attr_reader :config, :writer
@@ -56,24 +53,30 @@ module InfluxDB
56
53
  opts[:database] = args.first if args.first.is_a? String
57
54
  @config = InfluxDB::Config.new(opts)
58
55
  @stopped = false
59
-
60
- @writer = self
61
-
62
- if config.async?
63
- @writer = InfluxDB::Writer::Async.new(self, config.async)
64
- elsif config.udp?
65
- @writer = InfluxDB::Writer::UDP.new(self, config.udp)
66
- end
56
+ @writer = find_writer
67
57
 
68
58
  at_exit { stop! } if config.retry > 0
69
59
  end
70
60
 
71
61
  def stop!
62
+ writer.worker.stop! if config.async?
72
63
  @stopped = true
73
64
  end
74
65
 
75
66
  def stopped?
76
67
  @stopped
77
68
  end
69
+
70
+ private
71
+
72
+ def find_writer
73
+ if config.async?
74
+ InfluxDB::Writer::Async.new(self, config.async)
75
+ elsif config.udp?
76
+ InfluxDB::Writer::UDP.new(self, config.udp)
77
+ else
78
+ self
79
+ end
80
+ end
78
81
  end
79
82
  end
@@ -10,10 +10,11 @@ module InfluxDB
10
10
  def get(url, options = {})
11
11
  connect_with_retry do |http|
12
12
  response = do_request http, Net::HTTP::Get.new(url)
13
- if response.is_a? Net::HTTPSuccess
13
+ case response
14
+ when Net::HTTPSuccess
14
15
  handle_successful_response(response, options)
15
- elsif response.is_a? Net::HTTPUnauthorized
16
- fail InfluxDB::AuthenticationError, response.body
16
+ when Net::HTTPUnauthorized
17
+ raise InfluxDB::AuthenticationError, response.body
17
18
  else
18
19
  resolve_error(response.body)
19
20
  end
@@ -24,10 +25,12 @@ module InfluxDB
24
25
  headers = { "Content-Type" => "application/octet-stream" }
25
26
  connect_with_retry do |http|
26
27
  response = do_request http, Net::HTTP::Post.new(url, headers), data
27
- if response.is_a? Net::HTTPSuccess
28
+
29
+ case response
30
+ when Net::HTTPSuccess
28
31
  return response
29
- elsif response.is_a? Net::HTTPUnauthorized
30
- fail InfluxDB::AuthenticationError, response.body
32
+ when Net::HTTPUnauthorized
33
+ raise InfluxDB::AuthenticationError, response.body
31
34
  else
32
35
  resolve_error(response.body)
33
36
  end
@@ -36,7 +39,7 @@ module InfluxDB
36
39
 
37
40
  private
38
41
 
39
- def connect_with_retry(&block)
42
+ def connect_with_retry
40
43
  host = config.next_host
41
44
  delay = config.initial_delay
42
45
  retry_count = 0
@@ -47,8 +50,7 @@ module InfluxDB
47
50
  http.read_timeout = config.read_timeout
48
51
 
49
52
  http = setup_ssl(http)
50
-
51
- block.call(http)
53
+ yield http
52
54
 
53
55
  rescue Timeout::Error, *InfluxDB::NET_HTTP_EXCEPTIONS => e
54
56
  retry_count += 1
@@ -77,21 +79,23 @@ module InfluxDB
77
79
 
78
80
  def resolve_error(response)
79
81
  if response =~ /Couldn\'t find series/
80
- fail InfluxDB::SeriesNotFound, response
81
- else
82
- fail InfluxDB::Error, response
82
+ raise InfluxDB::SeriesNotFound, response
83
83
  end
84
+ raise InfluxDB::Error, response
84
85
  end
85
86
 
86
87
  def handle_successful_response(response, options)
87
- parsed_response = JSON.parse(response.body) if response.body
88
- errors = errors_from_response(parsed_response) if parsed_response
89
- fail InfluxDB::QueryError, errors if errors
88
+ parsed_response = JSON.parse(response.body) if response.body
89
+ errors = errors_from_response(parsed_response)
90
+
91
+ raise InfluxDB::QueryError, errors if errors
90
92
  options.fetch(:parse, false) ? parsed_response : response
91
93
  end
92
94
 
93
95
  def errors_from_response(parsed_resp)
94
- parsed_resp.is_a?(Hash) && parsed_resp.fetch('results', [])
96
+ return unless parsed_resp.is_a?(Hash)
97
+ parsed_resp
98
+ .fetch('results', [])
95
99
  .fetch(0, {})
96
100
  .fetch('error', nil)
97
101
  end
@@ -3,7 +3,7 @@ require 'thread'
3
3
  module InfluxDB
4
4
  # InfluxDB client configuration
5
5
  class Config
6
- AUTH_METHODS = %w(params basic_auth)
6
+ AUTH_METHODS = ["params".freeze, "basic_auth".freeze].freeze
7
7
 
8
8
  attr_accessor :port,
9
9
  :username,
@@ -27,41 +27,41 @@ module InfluxDB
27
27
 
28
28
  # rubocop:disable all
29
29
  def initialize(opts = {})
30
- @database = opts[:database]
31
- @hosts_queue = Queue.new
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)
32
49
 
33
50
  # load the hosts into a Queue for thread safety
51
+ @hosts_queue = Queue.new
34
52
  Array(opts[:hosts] || opts[:host] || ["localhost"]).each do |host|
35
53
  @hosts_queue.push(host)
36
54
  end
37
55
 
38
- @port = opts.fetch(:port, 8086)
39
- @prefix = opts.fetch(:prefix, '')
40
- @username = opts.fetch(:username, "root")
41
- @password = opts.fetch(:password, "root")
42
- @auth_method = AUTH_METHODS.include?(opts[:auth_method]) ? opts[:auth_method] : "params"
43
- @use_ssl = opts.fetch(:use_ssl, false)
44
- @verify_ssl = opts.fetch(:verify_ssl, true)
45
- @ssl_ca_cert = opts.fetch(:ssl_ca_cert, false)
46
- @time_precision = opts.fetch(:time_precision, "s")
47
- @initial_delay = opts.fetch(:initial_delay, 0.01)
48
- @max_delay = opts.fetch(:max_delay, 30)
49
- @open_timeout = opts.fetch(:write_timeout, 5)
50
- @read_timeout = opts.fetch(:read_timeout, 300)
51
- @async = opts.fetch(:async, false)
52
- @udp = opts.fetch(:udp, false)
53
- @retry = opts.fetch(:retry, nil)
54
- @denormalize = opts.fetch(:denormalize, true)
55
- @epoch = opts.fetch(:epoch, false)
56
- @retry =
57
- case @retry
58
- when Integer
59
- @retry
60
- when true, nil
61
- -1
62
- when false
63
- 0
64
- end
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
65
65
  end
66
66
 
67
67
  def udp?
@@ -33,8 +33,7 @@ module InfluxDB # :nodoc:
33
33
  Net::HTTPHeaderSyntaxError,
34
34
  Net::ProtocolError,
35
35
  SocketError,
36
- Zlib::GzipFile::Error
37
- ]
38
-
39
- NET_HTTP_EXCEPTIONS << OpenSSL::SSL::SSLError if defined?(OpenSSL)
36
+ Zlib::GzipFile::Error,
37
+ (OpenSSL::SSL::SSLError if defined?(OpenSSL))
38
+ ].compact.freeze
40
39
  end
@@ -2,7 +2,7 @@ require 'logger'
2
2
 
3
3
  module InfluxDB
4
4
  module Logging # :nodoc:
5
- PREFIX = "[InfluxDB] "
5
+ PREFIX = "InfluxDB".freeze
6
6
 
7
7
  class << self
8
8
  attr_writer :logger
@@ -16,7 +16,8 @@ module InfluxDB
16
16
  private
17
17
 
18
18
  def log(level, message)
19
- InfluxDB::Logging.logger.send(level.to_sym, PREFIX + message) if InfluxDB::Logging.logger
19
+ return unless InfluxDB::Logging.logger
20
+ InfluxDB::Logging.logger.send(level.to_sym, PREFIX) { message }
20
21
  end
21
22
  end
22
23
  end
@@ -6,7 +6,7 @@ module InfluxDB
6
6
  attr_reader :max
7
7
 
8
8
  def initialize(max = 10_000)
9
- fail ArgumentError, "queue size must be positive" unless max > 0
9
+ raise ArgumentError, "queue size must be positive" if max <= 0
10
10
  @max = max
11
11
  super()
12
12
  end
@@ -4,29 +4,15 @@ module InfluxDB
4
4
  attr_reader :series, :values, :tags, :timestamp
5
5
 
6
6
  def initialize(data)
7
- @series = escape(data[:series], :measurement)
8
-
9
- @values = data[:values].map{|k, v|
10
- key = escape(k.to_s, :field_key)
11
- val = if v.is_a?(String)
12
- '"' + escape(v, :field_value) + '"'
13
- else
14
- v.to_s
15
- end
16
- "#{key}=#{val}"
17
- }.join(',') if data[:values]
18
-
19
- @tags = data[:tags].map{|k, v|
20
- key = escape(k.to_s, :tag_key)
21
- val = escape(v.to_s, :tag_value)
22
- "#{key}=#{val}"
23
- }.join(',') if data[:tags]
7
+ @series = escape data[:series], :measurement
8
+ @values = escape_values data[:values]
9
+ @tags = escape_tags data[:tags]
24
10
 
25
11
  @timestamp = data[:timestamp]
26
12
  end
27
13
 
28
14
  def dump
29
- dump = "#{@series}"
15
+ dump = @series.dup
30
16
  dump << ",#{@tags}" if @tags
31
17
  dump << " #{@values}"
32
18
  dump << " #{@timestamp}" if @timestamp
@@ -36,16 +22,16 @@ module InfluxDB
36
22
  private
37
23
 
38
24
  ESCAPES = {
39
- measurement: [' ', ','],
40
- tag_key: ['=', ' ', ','],
41
- tag_value: ['=', ' ', ','],
42
- field_key: ['=', ' ', ',', '"'],
43
- field_value: ['"'],
44
- }
25
+ measurement: [' '.freeze, ','.freeze],
26
+ tag_key: ['='.freeze, ' '.freeze, ','.freeze],
27
+ tag_value: ['='.freeze, ' '.freeze, ','.freeze],
28
+ field_key: ['='.freeze, ' '.freeze, ','.freeze, '"'.freeze],
29
+ field_value: ['"'.freeze]
30
+ }.freeze
45
31
 
46
32
  def escape(s, type)
47
33
  ESCAPES[type].each do |ch|
48
- s = s.gsub(ch){ "\\#{ch}" }
34
+ s = s.gsub(ch) { "\\#{ch}" }
49
35
  end
50
36
  s
51
37
  end
@@ -58,5 +44,27 @@ module InfluxDB
58
44
  "#{key}=#{val}"
59
45
  end
60
46
  end
47
+
48
+ def escape_values(values)
49
+ return if values.nil?
50
+ values.map do |k, v|
51
+ key = escape(k.to_s, :field_key)
52
+ val = if v.is_a?(String)
53
+ '"' + escape(v, :field_value) + '"'
54
+ else
55
+ v.to_s
56
+ end
57
+ "#{key}=#{val}"
58
+ end.join(",")
59
+ end
60
+
61
+ def escape_tags(tags)
62
+ return if tags.nil?
63
+ tags.map do |k, v|
64
+ key = escape(k.to_s, :tag_key)
65
+ val = escape(v.to_s, :tag_value)
66
+ "#{key}=#{val}"
67
+ end.join(",")
68
+ end
61
69
  end
62
70
  end
@@ -3,7 +3,8 @@ module InfluxDB
3
3
  module ContinuousQuery # :nodoc:
4
4
  def list_continuous_queries(database)
5
5
  resp = execute("SHOW CONTINUOUS QUERIES", parse: true)
6
- fetch_series(resp).select { |v| v['name'] == database }
6
+ fetch_series(resp)
7
+ .select { |v| v['name'] == database }
7
8
  .fetch(0, {})
8
9
  .fetch('values', [])
9
10
  .map { |v| { 'name' => v.first, 'query' => v.last } }
@@ -3,11 +3,11 @@ module InfluxDB
3
3
  # rubocop:disable Metrics/AbcSize
4
4
  module Core
5
5
  def ping
6
- get "/ping"
6
+ get "/ping".freeze
7
7
  end
8
8
 
9
9
  def version
10
- resp = get "/ping"
10
+ resp = get "/ping".freeze
11
11
  resp.header['x-influxdb-version']
12
12
  end
13
13
 
@@ -15,12 +15,13 @@ module InfluxDB
15
15
  def query(query, opts = {})
16
16
  denormalize = opts.fetch(:denormalize, config.denormalize)
17
17
  params = query_params(query, opts)
18
- url = full_url("/query", params)
18
+ url = full_url("/query".freeze, params)
19
19
  series = fetch_series(get(url, parse: true))
20
20
 
21
21
  if block_given?
22
22
  series.each do |s|
23
- yield s['name'], s['tags'], denormalize ? denormalize_series(s) : raw_values(s)
23
+ values = denormalize ? denormalize_series(s) : raw_values(s)
24
+ yield s['name'.freeze], s['tags'.freeze], values
24
25
  end
25
26
  else
26
27
  denormalize ? denormalized_series_list(series) : series
@@ -68,30 +69,30 @@ module InfluxDB
68
69
  epoch = opts.fetch(:epoch, config.epoch)
69
70
 
70
71
  params = { q: query, db: config.database, precision: precision }
71
- params.merge!(epoch: epoch) if epoch
72
+ params[:epoch] = epoch if epoch
72
73
  params
73
74
  end
74
75
 
75
76
  def denormalized_series_list(series)
76
77
  series.map do |s|
77
78
  {
78
- 'name' => s['name'],
79
- 'tags' => s['tags'],
80
- 'values' => denormalize_series(s)
79
+ "name" => s["name".freeze],
80
+ "tags" => s["tags".freeze],
81
+ "values" => denormalize_series(s)
81
82
  }
82
83
  end
83
84
  end
84
85
 
85
86
  def fetch_series(response)
86
- response.fetch('results', []).flat_map{|result|
87
- result.fetch('series', [])
88
- }
87
+ response.fetch('results'.freeze, []).flat_map do |result|
88
+ result.fetch('series'.freeze, [])
89
+ end
89
90
  end
90
91
 
91
92
  def generate_payload(data)
92
93
  data.map do |point|
93
94
  InfluxDB::PointValue.new(point).dump
94
- end.join("\n")
95
+ end.join("\n".freeze)
95
96
  end
96
97
 
97
98
  def execute(query, options = {})
@@ -100,8 +101,8 @@ module InfluxDB
100
101
  end
101
102
 
102
103
  def denormalize_series(series)
103
- Array(series["values"]).map do |values|
104
- Hash[series["columns"].zip(values)]
104
+ Array(series["values".freeze]).map do |values|
105
+ Hash[series["columns".freeze].zip(values)]
105
106
  end
106
107
  end
107
108
 
@@ -115,7 +116,9 @@ module InfluxDB
115
116
  params[:p] = config.password
116
117
  end
117
118
 
118
- query = params.map { |k, v| [CGI.escape(k.to_s), "=", CGI.escape(v.to_s)].join }.join("&")
119
+ query = params.map do |k, v|
120
+ [CGI.escape(k.to_s), "=".freeze, CGI.escape(v.to_s)].join
121
+ end.join("&".freeze)
119
122
 
120
123
  URI::Generic.build(path: File.join(config.prefix, path), query: query).to_s
121
124
  end
@@ -10,8 +10,9 @@ module InfluxDB
10
10
  end
11
11
 
12
12
  def list_databases
13
- resp = execute("SHOW DATABASES", parse: true)
14
- fetch_series(resp).fetch(0, {})
13
+ resp = execute("SHOW DATABASES".freeze, parse: true)
14
+ fetch_series(resp)
15
+ .fetch(0, {})
15
16
  .fetch('values', [])
16
17
  .flatten
17
18
  .map { |v| { 'name' => v } }
@@ -11,9 +11,9 @@ module InfluxDB
11
11
  resp = execute("SHOW RETENTION POLICIES ON \"#{database}\"", parse: true)
12
12
  data = fetch_series(resp).fetch(0)
13
13
 
14
- data['values'].map do |policy|
14
+ data['values'.freeze].map do |policy|
15
15
  policy.each.with_index.inject({}) do |hash, (value, index)|
16
- hash.tap { |h| h[data['columns'][index]] = value }
16
+ hash.tap { |h| h[data['columns'.freeze][index]] = value }
17
17
  end
18
18
  end
19
19
  end
@@ -40,9 +40,10 @@ module InfluxDB
40
40
 
41
41
  # => [{"username"=>"usr", "admin"=>true}, {"username"=>"justauser", "admin"=>false}]
42
42
  def list_users
43
- resp = execute("SHOW USERS", parse: true)
44
- fetch_series(resp).fetch(0, {})
45
- .fetch('values', [])
43
+ resp = execute("SHOW USERS".freeze, parse: true)
44
+ fetch_series(resp)
45
+ .fetch(0, {})
46
+ .fetch('values'.freeze, [])
46
47
  .map { |v| { 'username' => v.first, 'admin' => v.last } }
47
48
  end
48
49
  end
@@ -1,3 +1,3 @@
1
1
  module InfluxDB # :nodoc:
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5".freeze
3
3
  end
@@ -44,11 +44,6 @@ module InfluxDB
44
44
  @queue = InfluxDB::MaxQueue.new config.fetch(:max_queue, MAX_QUEUE_SIZE)
45
45
 
46
46
  spawn_threads!
47
-
48
- at_exit do
49
- log :debug, "Thread exiting, flushing queue."
50
- check_background_queue until queue.empty?
51
- end
52
47
  end
53
48
 
54
49
  def push(payload)
@@ -109,6 +104,11 @@ module InfluxDB
109
104
  break if queue.length > MAX_POST_POINTS
110
105
  end
111
106
  end
107
+
108
+ def stop!
109
+ log :debug, "Thread exiting, flushing queue."
110
+ check_background_queue until queue.empty?
111
+ end
112
112
  end
113
113
  end
114
114
  end
@@ -7,7 +7,7 @@ module InfluxDB
7
7
  def initialize(client, config)
8
8
  @client = client
9
9
  config = config.is_a?(Hash) ? config : {}
10
- @host = config.fetch(:host, 'localhost')
10
+ @host = config.fetch(:host, "localhost".freeze)
11
11
  @port = config.fetch(:port, 4444)
12
12
  self.socket = UDPSocket.new
13
13
  socket.connect(host, port)
@@ -9,8 +9,6 @@ describe InfluxDB::Client do
9
9
  specify { expect(subject.writer).to be_a(InfluxDB::Writer::Async) }
10
10
 
11
11
  describe "#write_point" do
12
- let(:payload) { "responses,region=eu value=5" }
13
-
14
12
  it "sends writes to client" do
15
13
  post_request = stub_request(:post, stub_url)
16
14
 
@@ -18,13 +16,17 @@ describe InfluxDB::Client do
18
16
  subject.write_point('a', {})
19
17
  end
20
18
 
21
- Timeout.timeout(2 * worker_klass::SLEEP_INTERVAL) do
19
+ # The timout code is fragile, and heavily dependent on system load
20
+ # (and scheduler decisions). On the CI, the system is less
21
+ # responsive and needs a bit more time.
22
+ timeout_stretch = ENV["TRAVIS"] == "true" ? 10 : 3
23
+
24
+ Timeout.timeout(timeout_stretch * worker_klass::SLEEP_INTERVAL) do
22
25
  subject.stop!
23
- # ensure threads exit
24
- subject.writer.worker.threads.each(&:join)
26
+ end
25
27
 
26
- # flush queue (we cannot test `at_exit`)
27
- subject.writer.worker.check_background_queue
28
+ subject.writer.worker.threads.each do |t|
29
+ expect(t.stop?).to be true
28
30
  end
29
31
 
30
32
  # exact times can be 2 or 3 (because we have 3 worker threads),
@@ -5,4 +5,32 @@ begin
5
5
  rescue LoadError
6
6
  end
7
7
 
8
- InfluxDB::Logging.logger = Logger.new(STDOUT) if ENV['LOG']
8
+ RSpec.configure do |config|
9
+ config.color = ENV["TRAVIS"] != "true"
10
+
11
+ if config.files_to_run.one? || ENV["TRAVIS"] == "true"
12
+ config.formatter = :documentation
13
+ else
14
+ config.formatter = :progress
15
+ end
16
+
17
+ if ENV["LOG"]
18
+ Dir.mkdir("tmp") unless Dir.exist?("tmp")
19
+ logfile = File.open("tmp/spec.log", File::WRONLY | File::TRUNC | File::CREAT)
20
+
21
+ InfluxDB::Logging.logger = Logger.new(logfile).tap do |logger|
22
+ logger.formatter = ->(severity, _datetime, progname, message) {
23
+ "%-5s - %s: %s\n" % [ severity, progname, message ]
24
+ }
25
+ end
26
+
27
+ config.before(:each) do
28
+ InfluxDB::Logging.logger.info("RSpec") { self.class }
29
+ InfluxDB::Logging.logger.info("RSpec") { @__inspect_output }
30
+ end
31
+
32
+ config.after(:each) do
33
+ logfile.write "\n"
34
+ end
35
+ end
36
+ 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.2.4
4
+ version: 0.2.5
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-12 00:00:00.000000000 Z
11
+ date: 2016-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -58,28 +58,42 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 3.0.0
61
+ version: 3.4.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 3.0.0
68
+ version: 3.4.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: webmock
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.21.0
75
+ version: 1.24.2
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.21.0
82
+ version: 1.24.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.39.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.39.0
83
97
  description: This is the official Ruby library for InfluxDB.
84
98
  email:
85
99
  - influxdb@googlegroups.com
@@ -153,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
167
  version: '0'
154
168
  requirements: []
155
169
  rubyforge_project:
156
- rubygems_version: 2.4.5
170
+ rubygems_version: 2.5.1
157
171
  signing_key:
158
172
  specification_version: 4
159
173
  summary: Ruby library for InfluxDB.