influxdb-client 1.1.0.pre.380 → 1.1.0.pre.459
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -0
- data/README.md +23 -1
- data/lib/influxdb2/client/client.rb +6 -2
- data/lib/influxdb2/client/point.rb +1 -0
- data/lib/influxdb2/client/worker.rb +89 -0
- data/lib/influxdb2/client/write_api.rb +108 -6
- data/test/influxdb/write_api_batching_test.rb +153 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e48f3342f7073bb62a53a8665fb07e2ec1ce83d35badca54004db480b85eb5d
|
4
|
+
data.tar.gz: 4eda6f75500868cbb32cb7cb46abdf63e20cc3332952d5504d8d9e3e520860e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6fb77e117b116a87d58d3d8cc2bfb27c3557eeea523a4518892a6d6821653eea41bb0bf0c115a11039ef9bf6ec110deca808247c0d2bfc2cc7f73f04cebe72eb
|
7
|
+
data.tar.gz: 7ec5e8619def15d7e67d09c6ee068761aee2c902fc9be753ebba3cb173371f824717d778186a7ede2baf4db1a899f9df20ce0092920fb737035b44aa6d878030
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
### Features
|
4
4
|
1. [#14](https://github.com/influxdata/influxdb-client-ruby/issues/14): Added QueryApi
|
5
5
|
2. [#17](https://github.com/influxdata/influxdb-client-ruby/issues/17): Added possibility to stream query result
|
6
|
+
3. [#19](https://github.com/influxdata/influxdb-client-ruby/issues/19): Added WriteOptions and possibility to batch write
|
6
7
|
|
7
8
|
## 1.0.0.beta [2020-01-17]
|
8
9
|
|
data/README.md
CHANGED
@@ -105,6 +105,7 @@ end
|
|
105
105
|
```
|
106
106
|
|
107
107
|
### Writing data
|
108
|
+
The [WriteApi](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/write_api.rb) supports synchronous and batching writes into InfluxDB 2.0. In default api uses synchronous write. To enable batching you can use WriteOption.
|
108
109
|
|
109
110
|
```ruby
|
110
111
|
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
@@ -116,6 +117,28 @@ write_api = client.create_write_api
|
|
116
117
|
write_api.write(data: 'h2o,location=west value=33i 15')
|
117
118
|
```
|
118
119
|
|
120
|
+
#### Batching
|
121
|
+
The writes are processed in batches which are configurable by `WriteOptions`:
|
122
|
+
|
123
|
+
| Property | Description | Default Value |
|
124
|
+
| --- | --- | --- |
|
125
|
+
| **batchSize** | the number of data point to collect in batch | 1000 |
|
126
|
+
| **flushInterval** | the number of milliseconds before the batch is written | 1000 |
|
127
|
+
|
128
|
+
```ruby
|
129
|
+
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
130
|
+
batch_size: 10, flush_interval: 5_000)
|
131
|
+
client = InfluxDB2::Client.new('http://localhost:9999',
|
132
|
+
'my-token',
|
133
|
+
bucket: 'my-bucket',
|
134
|
+
org: 'my-org',
|
135
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
136
|
+
use_ssl: false)
|
137
|
+
|
138
|
+
write_api = client.create_write_api(write_options: write_options)
|
139
|
+
write_api.write(data: 'h2o,location=west value=33i 15')
|
140
|
+
```
|
141
|
+
|
119
142
|
#### Time precision
|
120
143
|
|
121
144
|
Configure default time precision:
|
@@ -135,7 +158,6 @@ client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
|
135
158
|
write_api = client.create_write_api
|
136
159
|
write_api.write(data: 'h2o,location=west value=33i 15', precision: InfluxDB2::WritePrecision::SECOND)
|
137
160
|
```
|
138
|
-
|
139
161
|
Allowed values for precision are:
|
140
162
|
- `InfluxDB::WritePrecision::NANOSECOND` for nanosecond
|
141
163
|
- `InfluxDB::WritePrecision::MICROSECOND` for microsecond
|
@@ -45,6 +45,7 @@ module InfluxDB2
|
|
45
45
|
# @option options [bool] :use_ssl Turn on/off SSL for HTTP communication
|
46
46
|
# the body line-protocol
|
47
47
|
def initialize(url, token, options = nil)
|
48
|
+
@auto_closeable = []
|
48
49
|
@options = options ? options.dup : {}
|
49
50
|
@options[:url] = url if url.is_a? String
|
50
51
|
@options[:token] = token if token.is_a? String
|
@@ -56,8 +57,10 @@ module InfluxDB2
|
|
56
57
|
# Write time series data into InfluxDB thought WriteApi.
|
57
58
|
#
|
58
59
|
# @return [WriteApi] New instance of WriteApi.
|
59
|
-
def create_write_api
|
60
|
-
WriteApi.new(options: @options)
|
60
|
+
def create_write_api(write_options: InfluxDB2::SYNCHRONOUS)
|
61
|
+
write_api = WriteApi.new(options: @options, write_options: write_options)
|
62
|
+
@auto_closeable.push(write_api)
|
63
|
+
write_api
|
61
64
|
end
|
62
65
|
|
63
66
|
# Get the Query client.
|
@@ -72,6 +75,7 @@ module InfluxDB2
|
|
72
75
|
# @return [ true ] Always true.
|
73
76
|
def close!
|
74
77
|
@closed = true
|
78
|
+
@auto_closeable.each(&:close!)
|
75
79
|
true
|
76
80
|
end
|
77
81
|
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module InfluxDB2
|
22
|
+
# Worker for handling write batching queue
|
23
|
+
#
|
24
|
+
class Worker
|
25
|
+
def initialize(api_client, write_options)
|
26
|
+
@api_client = api_client
|
27
|
+
@write_options = write_options
|
28
|
+
|
29
|
+
@queue = Queue.new
|
30
|
+
@queue_event = Queue.new
|
31
|
+
|
32
|
+
@queue_event.push(true)
|
33
|
+
|
34
|
+
@thread_flush = Thread.new do
|
35
|
+
until api_client.closed
|
36
|
+
sleep @write_options.flush_interval / 1_000
|
37
|
+
check_background_queue
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
@thread_size = Thread.new do
|
42
|
+
until api_client.closed
|
43
|
+
check_background_queue(size: true) if @queue.length >= @write_options.batch_size
|
44
|
+
sleep 0.01
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def push(payload)
|
50
|
+
@queue.push(payload)
|
51
|
+
end
|
52
|
+
|
53
|
+
def check_background_queue(size: false, flush_all: false)
|
54
|
+
@queue_event.pop
|
55
|
+
data = {}
|
56
|
+
points = 0
|
57
|
+
|
58
|
+
if size && @queue.length < @write_options.batch_size
|
59
|
+
@queue_event.push(true)
|
60
|
+
return
|
61
|
+
end
|
62
|
+
|
63
|
+
while (flush_all || points < @write_options.batch_size) && !@queue.empty?
|
64
|
+
begin
|
65
|
+
item = @queue.pop(true)
|
66
|
+
key = item.key
|
67
|
+
data[key] = [] unless data.key?(key)
|
68
|
+
data[key] << item.data
|
69
|
+
points += 1
|
70
|
+
rescue ThreadError
|
71
|
+
return
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
write(data) unless data.values.flatten.empty?
|
76
|
+
@queue_event.push(true)
|
77
|
+
end
|
78
|
+
|
79
|
+
def flush_all
|
80
|
+
check_background_queue(flush_all: true) unless @queue.empty?
|
81
|
+
end
|
82
|
+
|
83
|
+
def write(data)
|
84
|
+
data.each do |key, points|
|
85
|
+
@api_client.write_raw(points.join("\n"), precision: key.precision, bucket: key.bucket, org: key.org)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -17,8 +17,31 @@
|
|
17
17
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
|
+
require_relative 'worker'
|
20
21
|
|
21
22
|
module InfluxDB2
|
23
|
+
module WriteType
|
24
|
+
SYNCHRONOUS = 1
|
25
|
+
BATCHING = 2
|
26
|
+
end
|
27
|
+
|
28
|
+
# Creates write api configuration.
|
29
|
+
#
|
30
|
+
# @param write_type: methods of write (batching, asynchronous, synchronous)
|
31
|
+
# @param batch_size: the number of data point to collect in batch
|
32
|
+
# @param flush_interval: flush data at least in this interval
|
33
|
+
class WriteOptions
|
34
|
+
def initialize(write_type: WriteType::SYNCHRONOUS, batch_size: 1_000, flush_interval: 1_000)
|
35
|
+
@write_type = write_type
|
36
|
+
@batch_size = batch_size
|
37
|
+
@flush_interval = flush_interval
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_reader :write_type, :batch_size, :flush_interval
|
41
|
+
end
|
42
|
+
|
43
|
+
SYNCHRONOUS = InfluxDB2::WriteOptions.new(write_type: WriteType::SYNCHRONOUS)
|
44
|
+
|
22
45
|
# Precision constants.
|
23
46
|
#
|
24
47
|
class WritePrecision
|
@@ -39,9 +62,13 @@ module InfluxDB2
|
|
39
62
|
#
|
40
63
|
class WriteApi < DefaultApi
|
41
64
|
# @param [Hash] options The options to be used by the client.
|
42
|
-
|
65
|
+
# @param [WriteOptions] write_options Write api configuration.
|
66
|
+
def initialize(options:, write_options: SYNCHRONOUS)
|
43
67
|
super(options: options)
|
68
|
+
@write_options = write_options
|
69
|
+
@closed = false
|
44
70
|
end
|
71
|
+
attr_reader :closed
|
45
72
|
|
46
73
|
# Write data into specified Bucket.
|
47
74
|
#
|
@@ -83,33 +110,108 @@ module InfluxDB2
|
|
83
110
|
_check('bucket', bucket_param)
|
84
111
|
_check('org', org_param)
|
85
112
|
|
86
|
-
payload = _generate_payload(data)
|
113
|
+
payload = _generate_payload(data, bucket: bucket_param, org: org_param, precision: precision_param)
|
87
114
|
return nil if payload.nil?
|
88
115
|
|
116
|
+
if WriteType::BATCHING == @write_options.write_type
|
117
|
+
_worker.push(payload)
|
118
|
+
else
|
119
|
+
write_raw(payload, precision: precision_param, bucket: bucket_param, org: org_param)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# @return [ true ] Always true.
|
124
|
+
def close!
|
125
|
+
_worker.flush_all unless _worker.nil?
|
126
|
+
@closed = true
|
127
|
+
true
|
128
|
+
end
|
129
|
+
|
130
|
+
# @param [String] payload data as String
|
131
|
+
# @param [WritePrecision] precision The precision for the unix timestamps within the body line-protocol
|
132
|
+
# @param [String] bucket specifies the destination bucket for writes
|
133
|
+
# @param [String] org specifies the destination organization for writes
|
134
|
+
def write_raw(payload, precision: nil, bucket: nil, org: nil)
|
135
|
+
precision_param = precision || @options[:precision]
|
136
|
+
bucket_param = bucket || @options[:bucket]
|
137
|
+
org_param = org || @options[:org]
|
138
|
+
_check('precision', precision_param)
|
139
|
+
_check('bucket', bucket_param)
|
140
|
+
_check('org', org_param)
|
141
|
+
|
142
|
+
return nil unless payload.instance_of?(String) || payload.empty?
|
143
|
+
|
89
144
|
uri = URI.parse(File.join(@options[:url], '/api/v2/write'))
|
90
145
|
uri.query = URI.encode_www_form(bucket: bucket_param, org: org_param, precision: precision_param.to_s)
|
91
146
|
|
92
147
|
_post(payload, uri)
|
93
148
|
end
|
94
149
|
|
150
|
+
# Item for batching queue
|
151
|
+
class BatchItem
|
152
|
+
def initialize(key, data)
|
153
|
+
@key = key
|
154
|
+
@data = data
|
155
|
+
end
|
156
|
+
attr_reader :key, :data
|
157
|
+
end
|
158
|
+
|
159
|
+
# Key for batch item
|
160
|
+
class BatchItemKey
|
161
|
+
def initialize(bucket, org, precision = DEFAULT_WRITE_PRECISION)
|
162
|
+
@bucket = bucket
|
163
|
+
@org = org
|
164
|
+
@precision = precision
|
165
|
+
end
|
166
|
+
attr_reader :bucket, :org, :precision
|
167
|
+
|
168
|
+
def ==(other)
|
169
|
+
@bucket == other.bucket && @org == other.org && @precision == other.precision
|
170
|
+
end
|
171
|
+
|
172
|
+
alias eql? ==
|
173
|
+
|
174
|
+
def hash
|
175
|
+
@bucket.hash ^ @org.hash ^ @precision.hash # XOR
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
95
179
|
private
|
96
180
|
|
97
|
-
|
181
|
+
WORKER_MUTEX = Mutex.new
|
182
|
+
def _worker
|
183
|
+
return nil unless @write_options.write_type == WriteType::BATCHING
|
184
|
+
|
185
|
+
return @worker if @worker
|
186
|
+
|
187
|
+
WORKER_MUTEX.synchronize do
|
188
|
+
# this return is necessary because the previous mutex holder
|
189
|
+
# might have already assigned the @worker
|
190
|
+
return @worker if @worker
|
191
|
+
|
192
|
+
@worker = Worker.new(self, @write_options)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def _generate_payload(data, precision: nil, bucket: nil, org: nil)
|
98
197
|
if data.nil?
|
99
198
|
nil
|
100
199
|
elsif data.is_a?(Point)
|
101
|
-
data.to_line_protocol
|
200
|
+
_generate_payload(data.to_line_protocol, bucket: bucket, org: org, precision: data.precision ||
|
201
|
+
DEFAULT_WRITE_PRECISION)
|
102
202
|
elsif data.is_a?(String)
|
103
203
|
if data.empty?
|
104
204
|
nil
|
205
|
+
elsif @write_options.write_type == WriteType::BATCHING
|
206
|
+
BatchItem.new(BatchItemKey.new(bucket, org, precision), data)
|
105
207
|
else
|
106
208
|
data
|
107
209
|
end
|
108
210
|
elsif data.is_a?(Hash)
|
109
|
-
_generate_payload(Point.from_hash(data))
|
211
|
+
_generate_payload(Point.from_hash(data), bucket: bucket, org: org, precision: precision)
|
110
212
|
elsif data.respond_to? :map
|
111
213
|
data.map do |item|
|
112
|
-
_generate_payload(item)
|
214
|
+
_generate_payload(item, bucket: bucket, org: org, precision: precision)
|
113
215
|
end.reject(&:nil?).join("\n".freeze)
|
114
216
|
end
|
115
217
|
end
|
@@ -0,0 +1,153 @@
|
|
1
|
+
# The MIT License
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'test_helper'
|
22
|
+
|
23
|
+
class WriteApiBatchingTest < MiniTest::Test
|
24
|
+
def setup
|
25
|
+
WebMock.disable_net_connect!
|
26
|
+
|
27
|
+
@write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
28
|
+
batch_size: 2, flush_interval: 5_000)
|
29
|
+
@client = InfluxDB2::Client.new('http://localhost:9999',
|
30
|
+
'my-token',
|
31
|
+
bucket: 'my-bucket',
|
32
|
+
org: 'my-org',
|
33
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
34
|
+
use_ssl: false)
|
35
|
+
|
36
|
+
@write_client = @client.create_write_api(write_options: @write_options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def teardown
|
40
|
+
@client.close!
|
41
|
+
|
42
|
+
assert_equal true, @write_client.closed
|
43
|
+
|
44
|
+
WebMock.reset!
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_batch_size
|
48
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
49
|
+
.to_return(status: 204)
|
50
|
+
|
51
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=1.0 1')
|
52
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=2.0 2')
|
53
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=3.0 3')
|
54
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=4.0 4')
|
55
|
+
|
56
|
+
sleep(1)
|
57
|
+
|
58
|
+
request1 = "h2o_feet,location=coyote_creek level\\ water_level=1.0 1\n" \
|
59
|
+
'h2o_feet,location=coyote_creek level\\ water_level=2.0 2'
|
60
|
+
request2 = "h2o_feet,location=coyote_creek level\\ water_level=3.0 3\n" \
|
61
|
+
'h2o_feet,location=coyote_creek level\\ water_level=4.0 4'
|
62
|
+
|
63
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
64
|
+
times: 1, body: request1)
|
65
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
66
|
+
times: 1, body: request2)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_batch_size_group_by
|
70
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
71
|
+
.to_return(status: 204)
|
72
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=s')
|
73
|
+
.to_return(status: 204)
|
74
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org-a&precision=ns')
|
75
|
+
.to_return(status: 204)
|
76
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket2&org=my-org-a&precision=ns')
|
77
|
+
.to_return(status: 204)
|
78
|
+
|
79
|
+
bucket = 'my-bucket'
|
80
|
+
bucket2 = 'my-bucket2'
|
81
|
+
org_a = 'my-org-a'
|
82
|
+
|
83
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=1.0 1', bucket: bucket, org: 'my-org')
|
84
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=2.0 2', bucket: bucket, org: 'my-org',
|
85
|
+
precision: InfluxDB2::WritePrecision::SECOND)
|
86
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=3.0 3', bucket: bucket, org: org_a)
|
87
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=4.0 4', bucket: bucket, org: org_a)
|
88
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=5.0 5', bucket: bucket2, org: org_a)
|
89
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=6.0 6', bucket: bucket, org: org_a)
|
90
|
+
|
91
|
+
sleep(1)
|
92
|
+
|
93
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
94
|
+
times: 1, body: 'h2o_feet,location=coyote_creek level\\ water_level=1.0 1')
|
95
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=s',
|
96
|
+
times: 1, body: 'h2o_feet,location=coyote_creek level\\ water_level=2.0 2')
|
97
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org-a&precision=ns',
|
98
|
+
times: 1, body: "h2o_feet,location=coyote_creek level\\ water_level=3.0 3\n" \
|
99
|
+
'h2o_feet,location=coyote_creek level\\ water_level=4.0 4')
|
100
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket2&org=my-org-a&precision=ns',
|
101
|
+
times: 1, body: 'h2o_feet,location=coyote_creek level\\ water_level=5.0 5')
|
102
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org-a&precision=ns',
|
103
|
+
times: 1, body: 'h2o_feet,location=coyote_creek level\\ water_level=6.0 6')
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_flush_interval
|
107
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
108
|
+
.to_return(status: 204)
|
109
|
+
|
110
|
+
request1 = "h2o_feet,location=coyote_creek level\\ water_level=1.0 1\n" \
|
111
|
+
'h2o_feet,location=coyote_creek level\\ water_level=2.0 2'
|
112
|
+
request2 = 'h2o_feet,location=coyote_creek level\\ water_level=3.0 3'
|
113
|
+
|
114
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=1.0 1')
|
115
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=2.0 2')
|
116
|
+
|
117
|
+
sleep(1)
|
118
|
+
|
119
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
120
|
+
times: 1, body: request1)
|
121
|
+
|
122
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=3.0 3')
|
123
|
+
|
124
|
+
sleep(2)
|
125
|
+
|
126
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
127
|
+
times: 0, body: request2)
|
128
|
+
|
129
|
+
sleep(3)
|
130
|
+
|
131
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
132
|
+
times: 1, body: request2)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_flush_all_by_close_client
|
136
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
137
|
+
.to_return(status: 204)
|
138
|
+
|
139
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=1.0 1')
|
140
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=2.0 2')
|
141
|
+
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=3.0 3')
|
142
|
+
|
143
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
144
|
+
times: 0, body: 'h2o_feet,location=coyote_creek level\\ water_level=3.0 3')
|
145
|
+
|
146
|
+
@client.close!
|
147
|
+
|
148
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
149
|
+
times: 1, body: "h2o_feet,location=coyote_creek level\\ water_level=1.0 1\n" \
|
150
|
+
"h2o_feet,location=coyote_creek level\\ water_level=2.0 2\n" \
|
151
|
+
'h2o_feet,location=coyote_creek level\\ water_level=3.0 3')
|
152
|
+
end
|
153
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: influxdb-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.0.pre.
|
4
|
+
version: 1.1.0.pre.459
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub Bednar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- lib/influxdb2/client/point.rb
|
158
158
|
- lib/influxdb2/client/query_api.rb
|
159
159
|
- lib/influxdb2/client/version.rb
|
160
|
+
- lib/influxdb2/client/worker.rb
|
160
161
|
- lib/influxdb2/client/write_api.rb
|
161
162
|
- test/influxdb/client_test.rb
|
162
163
|
- test/influxdb/flux_csv_parser_test.rb
|
@@ -164,6 +165,7 @@ files:
|
|
164
165
|
- test/influxdb/query_api_integration_test.rb
|
165
166
|
- test/influxdb/query_api_stream_test.rb
|
166
167
|
- test/influxdb/query_api_test.rb
|
168
|
+
- test/influxdb/write_api_batching_test.rb
|
167
169
|
- test/influxdb/write_api_integration_test.rb
|
168
170
|
- test/influxdb/write_api_test.rb
|
169
171
|
- test/test_helper.rb
|
@@ -200,6 +202,7 @@ test_files:
|
|
200
202
|
- test/influxdb/query_api_integration_test.rb
|
201
203
|
- test/influxdb/query_api_stream_test.rb
|
202
204
|
- test/influxdb/query_api_test.rb
|
205
|
+
- test/influxdb/write_api_batching_test.rb
|
203
206
|
- test/influxdb/write_api_integration_test.rb
|
204
207
|
- test/influxdb/write_api_test.rb
|
205
208
|
- test/test_helper.rb
|