influxdb 0.3.17 → 0.4.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.
@@ -2,23 +2,12 @@ require "net/http"
2
2
  require "zlib"
3
3
 
4
4
  module InfluxDB # :nodoc:
5
- class Error < StandardError
6
- end
7
-
8
- class AuthenticationError < Error
9
- end
10
-
11
- class ConnectionError < Error
12
- end
13
-
14
- class SeriesNotFound < Error
15
- end
16
-
17
- class JSONParserError < Error
18
- end
19
-
20
- class QueryError < Error
21
- end
5
+ Error = Class.new StandardError
6
+ AuthenticationError = Class.new Error
7
+ ConnectionError = Class.new Error
8
+ SeriesNotFound = Class.new Error
9
+ JSONParserError = Class.new Error
10
+ QueryError = Class.new Error
22
11
 
23
12
  # When executing queries via HTTP, some errors can more or less safely
24
13
  # be ignored and we can retry the query again. This following
@@ -6,18 +6,40 @@ module InfluxDB
6
6
 
7
7
  class << self
8
8
  attr_writer :logger
9
- end
9
+ attr_writer :log_level
10
+
11
+ def logger
12
+ return false if @logger == false
13
+ @logger ||= ::Logger.new(STDERR).tap { |logger| logger.level = Logger::INFO }
14
+ end
10
15
 
11
- def self.logger
12
- return false if @logger == false
13
- @logger ||= ::Logger.new(STDERR).tap { |logger| logger.level = Logger::INFO }
16
+ def log_level
17
+ @log_level || Logger::INFO
18
+ end
19
+
20
+ def log?(level)
21
+ case level
22
+ when :debug then log_level <= Logger::DEBUG
23
+ when :info then log_level <= Logger::INFO
24
+ when :warn then log_level <= Logger::WARN
25
+ when :error then log_level <= Logger::ERROR
26
+ when :fatal then log_level <= Logger::FATAL
27
+ else true
28
+ end
29
+ end
14
30
  end
15
31
 
16
32
  private
17
33
 
18
- def log(level, message)
34
+ def log(level, message = nil, &block)
19
35
  return unless InfluxDB::Logging.logger
20
- InfluxDB::Logging.logger.send(level.to_sym, PREFIX) { message }
36
+ return unless InfluxDB::Logging.log?(level)
37
+
38
+ if block_given?
39
+ InfluxDB::Logging.logger.send(level.to_sym, PREFIX, &block)
40
+ else
41
+ InfluxDB::Logging.logger.send(level.to_sym, PREFIX) { message }
42
+ end
21
43
  end
22
44
  end
23
45
  end
@@ -25,11 +25,13 @@ module InfluxDB
25
25
  tag_key: ['='.freeze, ' '.freeze, ','.freeze],
26
26
  tag_value: ['='.freeze, ' '.freeze, ','.freeze],
27
27
  field_key: ['='.freeze, ' '.freeze, ','.freeze, '"'.freeze],
28
- field_value: ["\\".freeze, '"'.freeze],
28
+ field_value: ['"'.freeze],
29
29
  }.freeze
30
30
 
31
+ private_constant :ESCAPES
32
+
31
33
  def escape(s, type)
32
- # rubocop:disable Style/AlignParameters
34
+ # rubocop:disable Layout/AlignParameters
33
35
  s = s.encode "UTF-8".freeze, "UTF-8".freeze,
34
36
  invalid: :replace,
35
37
  undef: :replace,
@@ -47,12 +49,12 @@ module InfluxDB
47
49
  key = escape(k.to_s, :field_key)
48
50
  val = escape_value(v)
49
51
  "#{key}=#{val}"
50
- end.join(",")
52
+ end.join(",".freeze)
51
53
  end
52
54
 
53
55
  def escape_value(value)
54
56
  if value.is_a?(String)
55
- '"' + escape(value, :field_value) + '"'
57
+ '"'.freeze + escape(value, :field_value) + '"'.freeze
56
58
  elsif value.is_a?(Integer)
57
59
  "#{value}i"
58
60
  else
@@ -67,7 +69,7 @@ module InfluxDB
67
69
  key = escape(k.to_s, :tag_key)
68
70
  val = escape(v.to_s, :tag_value)
69
71
 
70
- "#{key}=#{val}" unless key == "" || val == ""
72
+ "#{key}=#{val}" unless key == "".freeze || val == "".freeze
71
73
  end.compact
72
74
 
73
75
  tags.join(",") unless tags.empty?
@@ -10,7 +10,6 @@ module InfluxDB
10
10
  end
11
11
 
12
12
  query % params
13
-
14
13
  rescue KeyError => e
15
14
  raise ArgumentError, e.message
16
15
  end
@@ -18,7 +17,7 @@ module InfluxDB
18
17
  def quote(param)
19
18
  case param
20
19
  when String, Symbol
21
- "'" + param.to_s.gsub(/['"\\\x0]/, '\\\\\0') + "'"
20
+ "'".freeze + param.to_s.gsub(/['"\\\x0]/, '\\\\\0') + "'".freeze
22
21
  when Integer, Float, TrueClass, FalseClass
23
22
  param.to_s
24
23
  else
@@ -6,7 +6,7 @@ module InfluxDB
6
6
  end
7
7
 
8
8
  def list_cluster_admins
9
- list_users.select { |u| u['admin'] }.map { |u| u['username'] }
9
+ list_users.select { |u| u["admin".freeze] }.map { |u| u["username".freeze] }
10
10
  end
11
11
 
12
12
  def revoke_cluster_admin_privileges(username)
@@ -10,16 +10,16 @@ module InfluxDB
10
10
  .map { |v| { 'name' => v.first, 'query' => v.last } }
11
11
  end
12
12
 
13
- def create_continuous_query(name, database, query, options = {})
13
+ def create_continuous_query(name, database, query, resample_every: nil, resample_for: nil)
14
14
  clause = ["CREATE CONTINUOUS QUERY", name, "ON", database]
15
15
 
16
- if options[:resample_every] || options[:resample_for]
17
- clause << "RESAMPLE"
18
- clause << "EVERY #{options[:resample_every]}" if options[:resample_every]
19
- clause << "FOR #{options[:resample_for]}" if options[:resample_for]
16
+ if resample_every || resample_for
17
+ clause << "RESAMPLE".freeze
18
+ clause << "EVERY #{resample_every}" if resample_every
19
+ clause << "FOR #{resample_for}" if resample_for
20
20
  end
21
21
 
22
- clause = clause.join(" ") << " BEGIN\n" << query << "\nEND"
22
+ clause = clause.join(" ".freeze) << " BEGIN\n".freeze << query << "\nEND".freeze
23
23
  execute(clause)
24
24
  end
25
25
 
@@ -18,14 +18,17 @@ module InfluxDB
18
18
  end
19
19
 
20
20
  # rubocop:disable Metrics/MethodLength
21
- def query(query, opts = {})
22
- query = builder.build(query, opts[:params])
23
- denormalize = opts.fetch(:denormalize, config.denormalize)
24
- json_streaming = !opts.fetch(:chunk_size, config.chunk_size).nil?
25
-
26
- params = query_params(query, opts)
27
- url = full_url("/query".freeze, params)
28
- series = fetch_series(get(url, parse: true, json_streaming: json_streaming))
21
+ def query(
22
+ query,
23
+ params: nil,
24
+ denormalize: config.denormalize,
25
+ chunk_size: config.chunk_size,
26
+ **opts
27
+ )
28
+ query = builder.build(query, params)
29
+
30
+ url = full_url("/query".freeze, query_params(query, opts))
31
+ series = fetch_series(get(url, parse: true, json_streaming: !chunk_size.nil?))
29
32
 
30
33
  if block_given?
31
34
  series.each do |s|
@@ -80,13 +83,13 @@ module InfluxDB
80
83
 
81
84
  private
82
85
 
83
- # rubocop:disable Metrics/MethodLength
84
- def query_params(query, opts)
85
- precision = opts.fetch(:precision, config.time_precision)
86
- epoch = opts.fetch(:epoch, config.epoch)
87
- chunk_size = opts.fetch(:chunk_size, config.chunk_size)
88
- database = opts.fetch(:database, config.database)
89
-
86
+ def query_params(
87
+ query,
88
+ precision: config.time_precision,
89
+ epoch: config.epoch,
90
+ chunk_size: config.chunk_size,
91
+ database: config.database
92
+ )
90
93
  params = { q: query, db: database }
91
94
  params[:precision] = precision if precision
92
95
  params[:epoch] = epoch if epoch
@@ -98,7 +101,6 @@ module InfluxDB
98
101
 
99
102
  params
100
103
  end
101
- # rubocop:enable Metrics/MethodLength
102
104
 
103
105
  def denormalized_series_list(series)
104
106
  series.map do |s|
@@ -122,9 +124,9 @@ module InfluxDB
122
124
  end.join("\n".freeze)
123
125
  end
124
126
 
125
- def execute(query, options = {})
127
+ def execute(query, db: nil, **options)
126
128
  params = { q: query }
127
- params[:db] = options.delete(:db) if options.key?(:db)
129
+ params[:db] = db if db
128
130
  url = full_url("/query".freeze, params)
129
131
  get(url, options)
130
132
  end
@@ -136,7 +138,7 @@ module InfluxDB
136
138
  end
137
139
 
138
140
  def raw_values(series)
139
- series.select { |k, _| %w(columns values).include?(k) }
141
+ series.select { |k, _| %w[columns values].include?(k) }
140
142
  end
141
143
 
142
144
  def full_url(path, params = {})
@@ -1,3 +1,3 @@
1
1
  module InfluxDB # :nodoc:
2
- VERSION = "0.3.17".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
@@ -77,7 +77,7 @@ module InfluxDB
77
77
  def spawn_threads!
78
78
  @threads = []
79
79
  num_worker_threads.times do |thread_num|
80
- log :debug, "Spawning background worker thread #{thread_num}."
80
+ log(:debug) { "Spawning background worker thread #{thread_num}." }
81
81
 
82
82
  @threads << Thread.new do
83
83
  Thread.current[:influxdb] = object_id
@@ -87,14 +87,15 @@ module InfluxDB
87
87
  sleep rand(sleep_interval)
88
88
  end
89
89
 
90
- log :debug, "Exit background worker thread #{thread_num}."
90
+ log(:debug) { "Exit background worker thread #{thread_num}." }
91
91
  end
92
92
  end
93
93
  end
94
94
 
95
95
  def check_background_queue(thread_num = 0)
96
- log :debug,
97
- "Checking background queue on thread #{thread_num} (#{current_thread_count} active)"
96
+ log(:debug) do
97
+ "Checking background queue on thread #{thread_num} (#{current_thread_count} active)"
98
+ end
98
99
 
99
100
  loop do
100
101
  data = []
@@ -107,7 +108,7 @@ module InfluxDB
107
108
  return if data.empty?
108
109
 
109
110
  begin
110
- log :debug, "Found data in the queue! (#{data.length} points)"
111
+ log(:debug) { "Found data in the queue! (#{data.length} points)" }
111
112
  client.write(data.join("\n"), nil)
112
113
  rescue => e
113
114
  log :error, "Cannot write data: #{e.inspect}"
@@ -118,7 +119,7 @@ module InfluxDB
118
119
  end
119
120
 
120
121
  def stop!
121
- log :debug, "Thread exiting, flushing queue."
122
+ log(:debug) { "Thread exiting, flushing queue." }
122
123
  check_background_queue until queue.empty?
123
124
  end
124
125
  end
@@ -4,17 +4,26 @@ module InfluxDB
4
4
  class UDP
5
5
  attr_accessor :socket
6
6
  attr_reader :host, :port
7
- def initialize(client, config)
7
+
8
+ def initialize(client, host: "localhost".freeze, port: 4444)
8
9
  @client = client
9
- config = config.is_a?(Hash) ? config : {}
10
- @host = config.fetch(:host, "localhost".freeze)
11
- @port = config.fetch(:port, 4444)
12
- self.socket = UDPSocket.new
13
- socket.connect(host, port)
10
+ @host = host
11
+ @port = port
14
12
  end
15
13
 
16
14
  def write(payload, _precision = nil, _retention_policy = nil, _database = nil)
17
- socket.send(payload, 0)
15
+ with_socket { |sock| sock.send(payload, 0) }
16
+ end
17
+
18
+ private
19
+
20
+ def with_socket
21
+ unless socket
22
+ self.socket = UDPSocket.new
23
+ socket.connect(host, port)
24
+ end
25
+
26
+ yield socket
18
27
  end
19
28
  end
20
29
  end
@@ -52,7 +52,7 @@ describe InfluxDB::Client do
52
52
  describe "#list_cluster_admins" do
53
53
  let(:response) do
54
54
  { "results" => [{ "statement_id" => 0,
55
- "series" => [{ "columns" => %w(user admin), "values" => [["dbadmin", true], ["foobar", false]] }] }] }
55
+ "series" => [{ "columns" => %w[user admin], "values" => [["dbadmin", true], ["foobar", false]] }] }] }
56
56
  end
57
57
  let(:expected_result) { ["dbadmin"] }
58
58
 
@@ -22,9 +22,9 @@ describe InfluxDB::Client do
22
22
  let(:database) { "testdb" }
23
23
  let(:response) do
24
24
  { "results" => [{ "statement_id" => 0,
25
- "series" => [{ "name" => "otherdb", "columns" => %w(name query),
25
+ "series" => [{ "name" => "otherdb", "columns" => %w[name query],
26
26
  "values" => [["clicks_per_hour", "CREATE CONTINUOUS QUERY clicks_per_hour ON otherdb BEGIN SELECT count(name) INTO \"otherdb\".\"default\".clicksCount_1h FROM \"otherdb\".\"default\".clicks GROUP BY time(1h) END"]] },
27
- { "name" => "testdb", "columns" => %w(name query),
27
+ { "name" => "testdb", "columns" => %w[name query],
28
28
  "values" => [["event_counts", "CREATE CONTINUOUS QUERY event_counts ON testdb BEGIN SELECT count(type) INTO \"testdb\".\"default\".typeCount_10m_byType FROM \"testdb\".\"default\".events GROUP BY time(10m), type END"]] }] }] }
29
29
  end
30
30
 
@@ -18,7 +18,7 @@ describe InfluxDB::Client do
18
18
  let(:response) do
19
19
  { "results" => [{ "statement_id" => 0,
20
20
  "series" => [{ "name" => "requests_per_minute",
21
- "columns" => %w(time value) }] }] }
21
+ "columns" => %w[time value] }] }] }
22
22
  end
23
23
 
24
24
  before do
@@ -27,7 +27,7 @@ describe InfluxDB::Client do
27
27
 
28
28
  describe "#list_retention_policies" do
29
29
  let(:query) { "SHOW RETENTION POLICIES ON \"database\"" }
30
- let(:response) { { "results" => [{ "statement_id" => 0, "series" => [{ "columns" => %w(name duration replicaN default), "values" => [["default", "0", 1, true], ["another", "1", 2, false]] }] }] } }
30
+ let(:response) { { "results" => [{ "statement_id" => 0, "series" => [{ "columns" => %w[name duration replicaN default], "values" => [["default", "0", 1, true], ["another", "1", 2, false]] }] }] } }
31
31
  let(:expected_result) { [{ "name" => "default", "duration" => "0", "replicaN" => 1, "default" => true }, { "name" => "another", "duration" => "1", "replicaN" => 2, "default" => false }] }
32
32
 
33
33
  it "should GET a list of retention policies" do
@@ -19,7 +19,7 @@ describe InfluxDB::Client do
19
19
 
20
20
  describe "GET #list_series" do
21
21
  let(:response) { { "results" => [{ "series" => [{ "columns" => "key", "values" => [["series1,name=default,duration=0"], ["series2,name=another,duration=1"]] }] }] } }
22
- let(:data) { %w(series1 series2) }
22
+ let(:data) { %w[series1 series2] }
23
23
  let(:query) { "SHOW SERIES" }
24
24
 
25
25
  before do
@@ -99,7 +99,7 @@ describe InfluxDB::Client do
99
99
 
100
100
  describe "#list_users" do
101
101
  let(:query) { "SHOW USERS" }
102
- let(:response) { { "results" => [{ "statement_id" => 0, "series" => [{ "columns" => %w(user admin), "values" => [["dbadmin", true], ["foobar", false]] }] }] } }
102
+ let(:response) { { "results" => [{ "statement_id" => 0, "series" => [{ "columns" => %w[user admin], "values" => [["dbadmin", true], ["foobar", false]] }] }] } }
103
103
  let(:expected_result) { [{ "username" => "dbadmin", "admin" => true }, { "username" => "foobar", "admin" => false }] }
104
104
 
105
105
  it "should GET a list of database users" do
@@ -21,7 +21,7 @@ describe InfluxDB::Client do
21
21
  let(:response) do
22
22
  { "results" => [{ "statement_id" => 0,
23
23
  "series" => [{ "name" => "requests_per_minute",
24
- "columns" => %w(time value) }] }] }
24
+ "columns" => %w[time value] }] }] }
25
25
  end
26
26
 
27
27
  before do
@@ -33,11 +33,11 @@ describe InfluxDB::Client do
33
33
 
34
34
  let(:response_line_1) do
35
35
  { "results" => [{ "statement_id" => 0,
36
- "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] }] }] }
36
+ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w[time temp value], "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] }] }] }
37
37
  end
38
38
  let(:response_line_2) do
39
39
  { "results" => [{ "statement_id" => 0,
40
- "series" => [{ "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]] }] }] }
40
+ "series" => [{ "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]] }] }] }
41
41
  end
42
42
  let(:response) do
43
43
  JSON.generate(response_line_1) + "\n" + JSON.generate(response_line_2)
@@ -62,19 +62,19 @@ describe InfluxDB::Client do
62
62
 
63
63
  let(:response_line_1) do
64
64
  { "results" => [{ "statement_id" => 0,
65
- "series" => [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 327]] }] }] }
65
+ "series" => [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w[time value], "values" => [["2015-07-08T07:15:22Z", 327]] }] }] }
66
66
  end
67
67
  let(:response_line_2) do
68
68
  { "results" => [{ "statement_id" => 0,
69
- "series" => [{ "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]] }] }] }
69
+ "series" => [{ "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]] }] }] }
70
70
  end
71
71
  let(:response_line_3) do
72
72
  { "results" => [{ "statement_id" => 0,
73
- "series" => [{ "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 943]] }] }] }
73
+ "series" => [{ "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w[time value], "values" => [["2015-07-08T07:15:22Z", 943]] }] }] }
74
74
  end
75
75
  let(:response_line_4) do
76
76
  { "results" => [{ "statement_id" => 0,
77
- "series" => [{ "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
+ "series" => [{ "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]] }] }] }
78
78
  end
79
79
  let(:response) do
80
80
  JSON.generate(response_line_1) + "\n" + JSON.generate(response_line_2) + "\n" + JSON.generate(response_line_3) + "\n" + JSON.generate(response_line_4)
@@ -28,7 +28,7 @@ describe InfluxDB::Client do
28
28
  let(:response) do
29
29
  { "results" => [{ "statement_id" => 0,
30
30
  "series" => [{ "name" => "cpu", "tags" => { "region" => "us" },
31
- "columns" => %w(time temp value),
31
+ "columns" => %w[time temp value],
32
32
  "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] }
33
33
  end
34
34
  let(:expected_result) do
@@ -46,8 +46,8 @@ describe InfluxDB::Client do
46
46
  context "with series with different tags" do
47
47
  let(:response) do
48
48
  { "results" => [{ "statement_id" => 0,
49
- "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
50
- { "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]] }] }] }
49
+ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w[time temp value], "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
50
+ { "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]] }] }] }
51
51
  end
52
52
  let(:expected_result) do
53
53
  [{ "name" => "cpu", "tags" => { "region" => "pl" },
@@ -66,10 +66,10 @@ describe InfluxDB::Client do
66
66
  context "with multiple series with different tags" do
67
67
  let(:response) do
68
68
  { "results" => [{ "statement_id" => 0,
69
- "series" => [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 327]] },
70
- { "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]] },
71
- { "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w(time value), "values" => [["2015-07-08T07:15:22Z", 943]] },
72
- { "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]] }] }] }
69
+ "series" => [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w[time value], "values" => [["2015-07-08T07:15:22Z", 327]] },
70
+ { "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]] },
71
+ { "name" => "access_times.service_2", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "columns" => %w[time value], "values" => [["2015-07-08T07:15:22Z", 943]] },
72
+ { "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]] }] }] }
73
73
  end
74
74
  let(:expected_result) do
75
75
  [{ "name" => "access_times.service_1", "tags" => { "code" => "200", "result" => "failure", "status" => "OK" }, "values" => [{ "time" => "2015-07-08T07:15:22Z", "value" => 327 }] },
@@ -87,8 +87,8 @@ describe InfluxDB::Client do
87
87
  context "with multiple series for explicit value only" do
88
88
  let(:response) do
89
89
  { "results" => [{ "statement_id" => 0,
90
- "series" => [{ "name" => "access_times.service_1", "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 873], ["2015-07-08T07:15:22Z", 327]] },
91
- { "name" => "access_times.service_2", "columns" => %w(time value), "values" => [["2015-07-08T06:15:22Z", 606], ["2015-07-08T07:15:22Z", 943]] }] }] }
90
+ "series" => [{ "name" => "access_times.service_1", "columns" => %w[time value], "values" => [["2015-07-08T06:15:22Z", 873], ["2015-07-08T07:15:22Z", 327]] },
91
+ { "name" => "access_times.service_2", "columns" => %w[time value], "values" => [["2015-07-08T06:15:22Z", 606], ["2015-07-08T07:15:22Z", 943]] }] }] }
92
92
  end
93
93
  let(:expected_result) do
94
94
  [{ "name" => "access_times.service_1", "tags" => nil, "values" => [{ "time" => "2015-07-08T06:15:22Z", "value" => 873 }, { "time" => "2015-07-08T07:15:22Z", "value" => 327 }] },
@@ -104,8 +104,8 @@ describe InfluxDB::Client do
104
104
  context "with a block" do
105
105
  let(:response) do
106
106
  { "results" => [{ "statement_id" => 0,
107
- "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
108
- { "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]] }] }] }
107
+ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w[time temp value], "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
108
+ { "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]] }] }] }
109
109
  end
110
110
 
111
111
  let(:expected_result) do
@@ -132,8 +132,8 @@ describe InfluxDB::Client do
132
132
 
133
133
  let(:response) do
134
134
  { "results" => [{ "statement_id" => 0,
135
- "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [[1_438_580_576, 34, 0.343443]] },
136
- { "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]] }] }] }
135
+ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w[time temp value], "values" => [[1_438_580_576, 34, 0.343443]] },
136
+ { "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]] }] }] }
137
137
  end
138
138
  let(:expected_result) do
139
139
  [{ "name" => "cpu", "tags" => { "region" => "pl" },
@@ -155,7 +155,7 @@ describe InfluxDB::Client do
155
155
 
156
156
  let(:response) do
157
157
  { "results" => [{ "statement_id" => 0,
158
- "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [[1_438_580_576, 34, 0.343443]] }] }] }
158
+ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w[time temp value], "values" => [[1_438_580_576, 34, 0.343443]] }] }] }
159
159
  end
160
160
  let(:expected_result) do
161
161
  [{ "name" => "cpu", "tags" => { "region" => "pl" }, "values" => [{ "time" => 1_438_580_576, "temp" => 34, "value" => 0.343443 }] }]
@@ -171,7 +171,7 @@ describe InfluxDB::Client do
171
171
  let(:extra_params) { { db: 'overriden_db' } }
172
172
  let(:response) do
173
173
  { "results" => [{ "series" => [{ "name" => "cpu", "tags" => { "region" => "us" },
174
- "columns" => %w(time temp value),
174
+ "columns" => %w[time temp value],
175
175
  "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] }] }
176
176
  end
177
177
  let(:expected_result) do
@@ -192,11 +192,11 @@ describe InfluxDB::Client do
192
192
  let(:response) do
193
193
  { "results" => [{ "statement_id" => 0,
194
194
  "series" => [{ "name" => "cpu", "tags" => { "region" => "us" },
195
- "columns" => %w(time temp value),
195
+ "columns" => %w[time temp value],
196
196
  "values" => [["2015-07-07T14:58:37Z", 92, 0.3445], ["2015-07-07T14:59:09Z", 68, 0.8787]] }] },
197
197
  { "statement_id" => 1,
198
198
  "series" => [{ "name" => "memory", "tags" => { "region" => "us" },
199
- "columns" => %w(time free total),
199
+ "columns" => %w[time free total],
200
200
  "values" => [["2015-07-07T14:58:37Z", 96_468_992, 134_217_728], ["2015-07-07T14:59:09Z", 71_303_168, 134_217_728]] }] }] }
201
201
  end
202
202
  let(:expected_result) do
@@ -217,11 +217,11 @@ describe InfluxDB::Client do
217
217
  context "with series with different tags" do
218
218
  let(:response) do
219
219
  { "results" => [{ "statement_id" => 0,
220
- "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w(time temp value), "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
221
- { "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]] }] },
220
+ "series" => [{ "name" => "cpu", "tags" => { "region" => "pl" }, "columns" => %w[time temp value], "values" => [["2015-07-07T15:13:04Z", 34, 0.343443]] },
221
+ { "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]] }] },
222
222
  { "statement_id" => 1,
223
- "series" => [{ "name" => "memory", "tags" => { "region" => "pl" }, "columns" => %w(time free total), "values" => [["2015-07-07T15:13:04Z", 35_651_584, 134_217_728]] },
224
- { "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]] }] }] }
223
+ "series" => [{ "name" => "memory", "tags" => { "region" => "pl" }, "columns" => %w[time free total], "values" => [["2015-07-07T15:13:04Z", 35_651_584, 134_217_728]] },
224
+ { "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]] }] }] }
225
225
  end
226
226
  let(:expected_result) do
227
227
  [{ "name" => "cpu", "tags" => { "region" => "pl" },
@@ -245,11 +245,11 @@ describe InfluxDB::Client do
245
245
  context "with a block" do
246
246
  let(:response) do
247
247
  { "results" => [{ "statement_id" => 0,
248
- "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]] }] },
248
+ "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
250
  { "statement_id" => 1,
251
- "series" => [{ "name" => "memory", "tags" => { "region" => "pl" }, "columns" => %w(time free total), "values" => [["2015-07-07T15:13:04Z", 35_651_584, 134_217_728]] },
252
- { "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]] }] }] }
251
+ "series" => [{ "name" => "memory", "tags" => { "region" => "pl" }, "columns" => %w[time free total], "values" => [["2015-07-07T15:13:04Z", 35_651_584, 134_217_728]] },
252
+ { "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]] }] }] }
253
253
  end
254
254
 
255
255
  let(:expected_result) do