influxdb 0.4.3 → 0.5.0

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: 32eb764b72ed6837bac8c3ef72761d12770294f2
4
- data.tar.gz: 5cbc233bb93ffd39948d4a0bbd522916c189a04d
3
+ metadata.gz: 170699d0f9146ed26b14a22529a83d4be2df7978
4
+ data.tar.gz: 1ec1e335f75c706b36e1f6a65ac5828d4fdf5f19
5
5
  SHA512:
6
- metadata.gz: 650cf3793a7bca2653ff4b999f6dfa0ec4cd3d1bc95f1bd9e00e402d10bf546ce091d9f88becd633567b9d9c1c69c8b789185b332366e92e91efdc57db841691
7
- data.tar.gz: f78046d93b485dc1e124a0d4a6076e3ed214dc02462ce44f6d9ab5e32fac0928216ab5bd917e5d3ab12bfb02f42000f65dedde1e4648b7e32bd139117ac19755
6
+ metadata.gz: d58bfb635ef085fc5e395f83539f0076ba68d77b919fba914c0000abe7c88447513b13f5298a213c5d32af20e0afb78ffa98a936f26bff8cc5d9d5fd89a4e99c
7
+ data.tar.gz: b560584b6c9722b4d5729715cdaa3b87a0485296d787383847b18be0b7b5761417e746cfb7f8fb223fa6722e3735fca2ab2ec1d776611db8a050bf48886b85aa
data/CHANGELOG.md CHANGED
@@ -6,10 +6,17 @@ For the full commit log, [see here](https://github.com/influxdata/influxdb-ruby/
6
6
 
7
7
  - None yet.
8
8
 
9
- ## v0.4.3, released 2017-10-21
9
+ ## v0.5.0, released 2017-10-21
10
10
 
11
- - Added warning to `InfluxDB::Write::Async#write`, marking the currently
12
- ignored arguments as significant in the next release.
11
+ - Add support for precision, retention policy and database parameters
12
+ to async writer (#140, #202 @rockclimber73)
13
+
14
+ **Attention** You may need to validate that your calls to the write
15
+ API (`InfluxDB::Client#write`, `#write_point`, `#write_points`) don't
16
+ accidentally included a precision, RP, and/or database argument. These
17
+ arguments were ignored until now. This is likely if you have changed
18
+ your client instance configuration in the past, when you added a
19
+ `async: true`. **Updating might cause data inconsistencies!**
13
20
 
14
21
  ## v0.4.2, released 2017-09-26
15
22
 
data/README.md CHANGED
@@ -256,7 +256,7 @@ retention = '1h.cpu'
256
256
  influxdb.write_points(data, precision, retention)
257
257
  ```
258
258
 
259
- Write asynchronously (note that a retention policy cannot be specified for asynchronous writes):
259
+ Write asynchronously:
260
260
 
261
261
  ``` ruby
262
262
  database = 'site_development'
@@ -1,3 +1,3 @@
1
1
  module InfluxDB # :nodoc:
2
- VERSION = "0.4.3".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
@@ -12,17 +12,8 @@ module InfluxDB
12
12
  end
13
13
 
14
14
  def write(data, precision = nil, retention_policy = nil, database = nil)
15
- if !precision.nil? || !retention_policy.nil? || !database.nil?
16
- opts = {
17
- precision: precision,
18
- retention_policy: retention_policy,
19
- database: database,
20
- }.delete_if { |_, v| v.nil? }
21
- warn_arguments(opts)
22
- end
23
-
24
15
  data = data.is_a?(Array) ? data : [data]
25
- data.map { |p| worker.push(p) }
16
+ data.map { |payload| worker.push(payload, precision, retention_policy, database) }
26
17
  end
27
18
 
28
19
  WORKER_MUTEX = Mutex.new
@@ -36,17 +27,6 @@ module InfluxDB
36
27
  end
37
28
  end
38
29
 
39
- private
40
-
41
- def warn_arguments(**which)
42
- warn [
43
- "You are using influxdb in async mode, and have provided one or",
44
- "more parameter which are currently ignored:",
45
- which.map { |k, v| format "%s=%p", k, v }.join(", "),
46
- "Starting with v0.5.0, these arguments will no longer be ignored.",
47
- ].join(" ")
48
- end
49
-
50
30
  class Worker
51
31
  attr_reader :client,
52
32
  :queue,
@@ -77,8 +57,8 @@ module InfluxDB
77
57
  spawn_threads!
78
58
  end
79
59
 
80
- def push(payload)
81
- queue.push(payload)
60
+ def push(payload, precision = nil, retention_policy = nil, database = nil)
61
+ queue.push([payload, precision, retention_policy, database])
82
62
  end
83
63
 
84
64
  def current_threads
@@ -117,22 +97,28 @@ module InfluxDB
117
97
  end
118
98
 
119
99
  loop do
120
- data = []
100
+ data = {}
121
101
 
122
- while data.size < max_post_points && !queue.empty?
102
+ while data.all? { |_, points| points.size < max_post_points } && !queue.empty?
123
103
  begin
124
- p = queue.pop(true)
125
- data.push p
104
+ payload, precision, retention_policy, database = queue.pop(true)
105
+ key = {
106
+ db: database,
107
+ pr: precision,
108
+ rp: retention_policy,
109
+ }
110
+ data[key] ||= []
111
+ data[key] << payload
126
112
  rescue ThreadError
127
113
  next
128
114
  end
129
115
  end
130
116
 
131
- return if data.empty?
117
+ return if data.values.flatten.empty?
132
118
 
133
119
  begin
134
- log(:debug) { "Found data in the queue! (#{data.length} points)" }
135
- client.write(data.join("\n"), nil)
120
+ log(:debug) { "Found data in the queue! (#{sizes(data)})" }
121
+ write(data)
136
122
  rescue StandardError => e
137
123
  log :error, "Cannot write data: #{e.inspect}"
138
124
  end
@@ -145,6 +131,25 @@ module InfluxDB
145
131
  log(:debug) { "Thread exiting, flushing queue." }
146
132
  check_background_queue until queue.empty?
147
133
  end
134
+
135
+ private
136
+
137
+ def write(data)
138
+ data.each do |key, points|
139
+ client.write(points.join("\n"), key[:pr], key[:rp], key[:db])
140
+ end
141
+ end
142
+
143
+ def sizes(data)
144
+ data.map do |key, points|
145
+ without_nils = key.reject { |_, v| v.nil? }
146
+ if without_nils.empty?
147
+ "#{points.size} points"
148
+ else
149
+ "#{key} => #{points.size} points"
150
+ end
151
+ end.join(', ')
152
+ end
148
153
  end
149
154
  end
150
155
  end
@@ -35,6 +35,52 @@ describe InfluxDB::Client do
35
35
  # but cannot be less than 2 due to MAX_POST_POINTS limit
36
36
  expect(post_request).to have_been_requested.at_least_times(2)
37
37
  end
38
+
39
+ context 'when precision, retention_policy and database are given' do
40
+ let(:series) { 'test_series' }
41
+ let(:precision) { 'test_precision' }
42
+ let(:retention_policy) { 'test_period' }
43
+ let(:database) { 'test_database' }
44
+
45
+ it "writes aggregate payload to the client" do
46
+ queue = Queue.new
47
+ allow(client).to receive(:write) do |*args|
48
+ queue.push(args)
49
+ end
50
+
51
+ subject.write_point(series, { values: { t: 60 } }, precision, retention_policy, database)
52
+ subject.write_point(series, { values: { t: 61 } }, precision, retention_policy, database)
53
+
54
+ Timeout.timeout(worker.sleep_interval) do
55
+ expect(queue.pop).to eq ["#{series} t=60i\n#{series} t=61i", precision, retention_policy, database]
56
+ end
57
+ end
58
+
59
+ context 'when different precision, retention_policy and database are given' do
60
+ let(:precision2) { 'test_precision2' }
61
+ let(:retention_policy2) { 'test_period2' }
62
+ let(:database2) { 'test_database2' }
63
+
64
+ it "writes separated payloads for each {precision, retention_policy, database} set" do
65
+ queue = Queue.new
66
+ allow(client).to receive(:write) do |*args|
67
+ queue.push(args)
68
+ end
69
+
70
+ subject.write_point(series, { values: { t: 60 } }, precision, retention_policy, database)
71
+ subject.write_point(series, { values: { t: 61 } }, precision2, retention_policy, database)
72
+ subject.write_point(series, { values: { t: 62 } }, precision, retention_policy2, database)
73
+ subject.write_point(series, { values: { t: 63 } }, precision, retention_policy, database2)
74
+
75
+ Timeout.timeout(worker.sleep_interval) do
76
+ expect(queue.pop).to eq ["#{series} t=60i", precision, retention_policy, database]
77
+ expect(queue.pop).to eq ["#{series} t=61i", precision2, retention_policy, database]
78
+ expect(queue.pop).to eq ["#{series} t=62i", precision, retention_policy2, database]
79
+ expect(queue.pop).to eq ["#{series} t=63i", precision, retention_policy, database2]
80
+ end
81
+ end
82
+ end
83
+ end
38
84
  end
39
85
 
40
86
  describe "async options" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Persen