influxdb-client 1.7.0.pre.1015 → 1.7.0.pre.1121
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 +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +3 -0
- data/README.md +7 -3
- data/lib/influxdb2/client/default_api.rb +2 -0
- data/lib/influxdb2/client/influx_error.rb +20 -1
- data/lib/influxdb2/client/worker.rb +17 -5
- data/lib/influxdb2/client/write_api.rb +14 -3
- data/test/influxdb/write_api_batching_test.rb +275 -19
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f97e3e086f7c291167f6aa7e1433294a603cd65fc1e673e9f75daa7459c2d0a2
|
4
|
+
data.tar.gz: 1f8be80e71b870bb4d2b7ef5839b9434665a53b76b8706b6a8d480eca9f56185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 646f4d4553df39f808f5ec8f7cbc23e014bf893faf32c86f1ce9e0631c3744bafb996413ab317ca6835c481d907271b3fb297a73e0866ace6c8acd569fbe9ab3
|
7
|
+
data.tar.gz: 26e1400b766d2f4a13bc145513f10d6f16f043b993b80d58f3bbd2d294d61d1857385213b0397f14648f68e6a1fab6d8de4c4f8fc9b2077c39bfeb9a70bd4c82
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -123,12 +123,16 @@ The writes are processed in batches which are configurable by `WriteOptions`:
|
|
123
123
|
| --- | --- | --- |
|
124
124
|
| batchSize | the number of data point to collect in batch | 1000 |
|
125
125
|
| flush_interval | the number of milliseconds before the batch is written | 1000 |
|
126
|
-
| retry_interval | the number of milliseconds to retry unsuccessful write. The retry interval is used when the InfluxDB server does not specify "Retry-After" header. |
|
126
|
+
| retry_interval | the number of milliseconds to retry unsuccessful write. The retry interval is used when the InfluxDB server does not specify "Retry-After" header. | 5000 |
|
127
127
|
| jitter_interval | the number of milliseconds to increase the batch flush interval by a random amount | 0 |
|
128
|
-
|
128
|
+
| max_retries | the number of max retries when write fails | 5 |
|
129
|
+
| max_retry_delay | maximum delay when retrying write in milliseconds | 180000 |
|
130
|
+
| exponential_base | the base for the exponential retry delay, the next delay is computed as `retry_interval * exponential_base^(attempts - 1) + random(jitter_interval)` | 5 |
|
129
131
|
```ruby
|
130
132
|
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
131
|
-
batch_size: 10, flush_interval: 5_000
|
133
|
+
batch_size: 10, flush_interval: 5_000,
|
134
|
+
max_retries: 3, max_retry_delay: 15_000,
|
135
|
+
exponential_base: 2)
|
132
136
|
client = InfluxDB2::Client.new('http://localhost:9999',
|
133
137
|
'my-token',
|
134
138
|
bucket: 'my-bucket',
|
@@ -1,19 +1,33 @@
|
|
1
1
|
module InfluxDB2
|
2
2
|
# InfluxError that is raised during HTTP communication.
|
3
3
|
class InfluxError < StandardError
|
4
|
+
HTTP_ERRORS = [
|
5
|
+
EOFError,
|
6
|
+
Errno::ECONNREFUSED,
|
7
|
+
Errno::ECONNRESET,
|
8
|
+
Errno::EINVAL,
|
9
|
+
Net::HTTPBadResponse,
|
10
|
+
Net::HTTPHeaderSyntaxError,
|
11
|
+
Net::ProtocolError,
|
12
|
+
Timeout::Error
|
13
|
+
].freeze
|
14
|
+
|
4
15
|
# HTTP status code
|
5
16
|
attr_reader :code
|
6
17
|
# Reference code unique to the error type
|
7
18
|
attr_reader :reference
|
8
19
|
# The Retry-After header describes when to try the request again.
|
9
20
|
attr_reader :retry_after
|
21
|
+
# original error
|
22
|
+
attr_reader :original
|
10
23
|
|
11
|
-
def initialize(message:, code:, reference:, retry_after:)
|
24
|
+
def initialize(original = nil, message:, code:, reference:, retry_after:)
|
12
25
|
super(message)
|
13
26
|
|
14
27
|
@code = code
|
15
28
|
@reference = reference
|
16
29
|
@retry_after = retry_after
|
30
|
+
@original = original
|
17
31
|
end
|
18
32
|
|
19
33
|
def self.from_response(response)
|
@@ -27,5 +41,10 @@ module InfluxDB2
|
|
27
41
|
obj = new(message: message, code: '', reference: '', retry_after: '')
|
28
42
|
obj
|
29
43
|
end
|
44
|
+
|
45
|
+
def self.from_error(error)
|
46
|
+
obj = new(error, message: error.message, code: '', reference: '', retry_after: '')
|
47
|
+
obj
|
48
|
+
end
|
30
49
|
end
|
31
50
|
end
|
@@ -31,6 +31,8 @@ module InfluxDB2
|
|
31
31
|
|
32
32
|
@queue_event.push(true)
|
33
33
|
|
34
|
+
Thread.abort_on_exception = true
|
35
|
+
|
34
36
|
@thread_flush = Thread.new do
|
35
37
|
until api_client.closed
|
36
38
|
sleep @write_options.flush_interval.to_f / 1_000
|
@@ -94,22 +96,32 @@ module InfluxDB2
|
|
94
96
|
|
95
97
|
def _write(data)
|
96
98
|
data.each do |key, points|
|
97
|
-
_write_raw(key, points)
|
99
|
+
_write_raw(key, points, 1, @write_options.retry_interval)
|
98
100
|
end
|
99
101
|
end
|
100
102
|
|
101
|
-
def _write_raw(key, points)
|
103
|
+
def _write_raw(key, points, attempts, retry_interval)
|
102
104
|
if @write_options.jitter_interval > 0
|
103
105
|
jitter_delay = (@write_options.jitter_interval.to_f / 1_000) * rand
|
104
106
|
sleep jitter_delay
|
105
107
|
end
|
106
108
|
@api_client.write_raw(points.join("\n"), precision: key.precision, bucket: key.bucket, org: key.org)
|
107
109
|
rescue InfluxError => e
|
108
|
-
raise e if
|
110
|
+
raise e if attempts > @write_options.max_retries
|
111
|
+
raise e if (e.code.nil? || e.code.to_i < 429) && !_connection_error(e.original)
|
112
|
+
|
113
|
+
timeout = if e.retry_after.empty?
|
114
|
+
[retry_interval.to_f, @write_options.max_retry_delay.to_f].min / 1_000
|
115
|
+
else
|
116
|
+
e.retry_after.to_f
|
117
|
+
end
|
109
118
|
|
110
|
-
timeout = e.retry_after.empty? ? @write_options.retry_interval.to_f / 1_000 : e.retry_after.to_f
|
111
119
|
sleep timeout
|
112
|
-
_write_raw(key, points)
|
120
|
+
_write_raw(key, points, attempts + 1, retry_interval * @write_options.exponential_base)
|
121
|
+
end
|
122
|
+
|
123
|
+
def _connection_error(error)
|
124
|
+
InfluxError::HTTP_ERRORS.any? { |c| error.instance_of? c }
|
113
125
|
end
|
114
126
|
end
|
115
127
|
end
|
@@ -34,21 +34,32 @@ module InfluxDB2
|
|
34
34
|
# @param [Integer] retry_interval: number of milliseconds to retry unsuccessful write.
|
35
35
|
# The retry interval is used when the InfluxDB server does not specify "Retry-After" header.
|
36
36
|
# @param [Integer] jitter_interval: the number of milliseconds to increase the batch flush interval
|
37
|
+
# @param [Integer] max_retries: max number of retries when write fails
|
38
|
+
# @param [Integer] max_retry_delay: maximum delay when retrying write in milliseconds
|
37
39
|
# by a random amount
|
38
|
-
|
39
|
-
|
40
|
+
# @param [Integer] exponential_base: base for the exponential retry delay, the next delay is computed as
|
41
|
+
# "exponential_base^(attempts-1) + random(jitter_interval)"
|
42
|
+
def initialize(write_type: WriteType::SYNCHRONOUS, batch_size: 1_000, flush_interval: 1_000, retry_interval: 5_000,
|
43
|
+
jitter_interval: 0, max_retries: 5, max_retry_delay: 180_000, exponential_base: 5)
|
40
44
|
_check_not_negative('batch_size', batch_size)
|
41
45
|
_check_not_negative('flush_interval', flush_interval)
|
42
46
|
_check_not_negative('retry_interval', retry_interval)
|
43
47
|
_check_positive('jitter_interval', jitter_interval)
|
48
|
+
_check_positive('max_retries', jitter_interval)
|
49
|
+
_check_positive('max_retry_delay', jitter_interval)
|
50
|
+
_check_positive('exponential_base', exponential_base)
|
44
51
|
@write_type = write_type
|
45
52
|
@batch_size = batch_size
|
46
53
|
@flush_interval = flush_interval
|
47
54
|
@retry_interval = retry_interval
|
48
55
|
@jitter_interval = jitter_interval
|
56
|
+
@max_retries = max_retries
|
57
|
+
@max_retry_delay = max_retry_delay
|
58
|
+
@exponential_base = exponential_base
|
49
59
|
end
|
50
60
|
|
51
|
-
attr_reader :write_type, :batch_size, :flush_interval, :retry_interval, :jitter_interval
|
61
|
+
attr_reader :write_type, :batch_size, :flush_interval, :retry_interval, :jitter_interval,
|
62
|
+
:max_retries, :max_retry_delay, :exponential_base
|
52
63
|
|
53
64
|
def _check_not_negative(key, value)
|
54
65
|
raise ArgumentError, "The '#{key}' should be positive or zero, but is: #{value}" if value <= 0
|
@@ -187,6 +187,65 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
187
187
|
'h2o_feet,location=coyote_creek level\\ water_level=3.0 3')
|
188
188
|
end
|
189
189
|
|
190
|
+
def test_jitter_interval
|
191
|
+
@client.close!
|
192
|
+
|
193
|
+
@client = InfluxDB2::Client.new('http://localhost:9999',
|
194
|
+
'my-token',
|
195
|
+
bucket: 'my-bucket',
|
196
|
+
org: 'my-org',
|
197
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
198
|
+
use_ssl: false)
|
199
|
+
|
200
|
+
@write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
201
|
+
batch_size: 2, flush_interval: 5_000, jitter_interval: 2_000)
|
202
|
+
@write_client = @client.create_write_api(write_options: @write_options)
|
203
|
+
|
204
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
205
|
+
.to_return(status: 204)
|
206
|
+
|
207
|
+
request = "h2o_feet,location=coyote_creek water_level=1.0 1\n" \
|
208
|
+
'h2o_feet,location=coyote_creek water_level=2.0 2'
|
209
|
+
|
210
|
+
@write_client.write(data: ['h2o_feet,location=coyote_creek water_level=1.0 1',
|
211
|
+
'h2o_feet,location=coyote_creek water_level=2.0 2'])
|
212
|
+
|
213
|
+
sleep(0.05)
|
214
|
+
|
215
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
216
|
+
times: 0, body: request)
|
217
|
+
|
218
|
+
sleep(2)
|
219
|
+
|
220
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
221
|
+
times: 1, body: request)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
class WriteApiRetryStrategyTest < MiniTest::Test
|
226
|
+
def setup
|
227
|
+
WebMock.disable_net_connect!
|
228
|
+
|
229
|
+
@write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
230
|
+
batch_size: 2, flush_interval: 5_000, retry_interval: 2_000)
|
231
|
+
@client = InfluxDB2::Client.new('http://localhost:9999',
|
232
|
+
'my-token',
|
233
|
+
bucket: 'my-bucket',
|
234
|
+
org: 'my-org',
|
235
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
236
|
+
use_ssl: false)
|
237
|
+
|
238
|
+
@write_client = @client.create_write_api(write_options: @write_options)
|
239
|
+
end
|
240
|
+
|
241
|
+
def teardown
|
242
|
+
@client.close!
|
243
|
+
|
244
|
+
assert_equal true, @write_client.closed
|
245
|
+
|
246
|
+
WebMock.reset!
|
247
|
+
end
|
248
|
+
|
190
249
|
def test_retry_interval_by_config
|
191
250
|
error_body = '{"code":"temporarily unavailable","message":"Token is temporarily over quota. '\
|
192
251
|
'The Retry-After header describes when to try the write again."}'
|
@@ -211,7 +270,7 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
211
270
|
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
212
271
|
times: 1, body: request)
|
213
272
|
|
214
|
-
sleep(
|
273
|
+
sleep(5)
|
215
274
|
|
216
275
|
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
217
276
|
times: 2, body: request)
|
@@ -256,37 +315,234 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
256
315
|
times: 2, body: request)
|
257
316
|
end
|
258
317
|
|
259
|
-
def
|
260
|
-
|
318
|
+
def test_max_retries
|
319
|
+
error_body = '{"code":"temporarily unavailable","message":"Server is temporarily unavailable to accept writes. '\
|
320
|
+
'The Retry-After header describes when to try the write again."}'
|
261
321
|
|
262
|
-
|
263
|
-
'my-token',
|
264
|
-
bucket: 'my-bucket',
|
265
|
-
org: 'my-org',
|
266
|
-
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
267
|
-
use_ssl: false)
|
322
|
+
headers = { 'X-Platform-Error-Code' => 'temporarily unavailable' }
|
268
323
|
|
269
|
-
|
270
|
-
|
271
|
-
|
324
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
325
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
326
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
327
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
328
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
329
|
+
.to_return(status: 429, headers: headers, body: error_body) # not called
|
330
|
+
|
331
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
332
|
+
.add_tag('location', 'europe')
|
333
|
+
.add_field('level', 2.0)
|
334
|
+
|
335
|
+
request = 'h2o,location=europe level=2.0'
|
336
|
+
|
337
|
+
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
338
|
+
batch_size: 1, retry_interval: 2_000, max_retries: 3,
|
339
|
+
max_retry_delay: 5_000, exponential_base: 2)
|
340
|
+
|
341
|
+
error = assert_raises InfluxDB2::InfluxError do
|
342
|
+
@client.create_write_api(write_options: write_options).write(data: point)
|
343
|
+
|
344
|
+
sleep(0.5)
|
345
|
+
|
346
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
347
|
+
times: 1, body: request)
|
348
|
+
|
349
|
+
sleep(2)
|
350
|
+
|
351
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
352
|
+
times: 2, body: request)
|
353
|
+
|
354
|
+
sleep(4)
|
355
|
+
|
356
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
357
|
+
times: 3, body: request)
|
358
|
+
|
359
|
+
sleep(5)
|
360
|
+
|
361
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
362
|
+
times: 4, body: request)
|
363
|
+
|
364
|
+
sleep(5)
|
365
|
+
|
366
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
367
|
+
times: 4, body: request)
|
368
|
+
|
369
|
+
sleep(5)
|
370
|
+
end
|
371
|
+
|
372
|
+
assert_equal('429', error.code)
|
373
|
+
|
374
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
375
|
+
times: 4, body: request)
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_influx_exception
|
379
|
+
error_body = '{"code":"invalid","message":"unable to parse '\
|
380
|
+
'\'h2o_feet, location=coyote_creek water_level=1.0 1\': missing tag key"}'
|
381
|
+
|
382
|
+
stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
383
|
+
.to_return(status: 400, headers: { 'X-Platform-Error-Code' => 'invalid' }, body: error_body)
|
384
|
+
|
385
|
+
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
386
|
+
batch_size: 1, retry_interval: 2_000, max_retries: 3,
|
387
|
+
max_retry_delay: 5_000, exponential_base: 2)
|
388
|
+
|
389
|
+
error = assert_raises InfluxDB2::InfluxError do
|
390
|
+
@client.create_write_api(write_options: write_options).write(data: 'h2o,location=west value=33i 15')
|
391
|
+
|
392
|
+
sleep(1)
|
393
|
+
end
|
394
|
+
|
395
|
+
assert_equal '400', error.code
|
396
|
+
assert_equal 'invalid', error.reference
|
397
|
+
assert_equal "unable to parse 'h2o_feet, location=coyote_creek water_level=1.0 1': missing tag key", error.message
|
398
|
+
end
|
399
|
+
|
400
|
+
def test_max_retries_by_header
|
401
|
+
error_body = '{"code":"temporarily unavailable","message":"Server is temporarily unavailable to accept writes. '\
|
402
|
+
'The Retry-After header describes when to try the write again."}'
|
403
|
+
|
404
|
+
headers = { 'X-Platform-Error-Code' => 'temporarily unavailable', 'Retry-After' => '3' }
|
405
|
+
|
406
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
407
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
408
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
409
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
410
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
411
|
+
.to_return(status: 429, headers: headers, body: error_body) # not called
|
412
|
+
|
413
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
414
|
+
.add_tag('location', 'europe')
|
415
|
+
.add_field('level', 2.0)
|
416
|
+
|
417
|
+
request = 'h2o,location=europe level=2.0'
|
418
|
+
|
419
|
+
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
420
|
+
batch_size: 1, retry_interval: 2_000, max_retries: 3,
|
421
|
+
max_retry_delay: 5_000, exponential_base: 2)
|
422
|
+
|
423
|
+
error = assert_raises InfluxDB2::InfluxError do
|
424
|
+
@client.create_write_api(write_options: write_options).write(data: point)
|
425
|
+
|
426
|
+
sleep(0.5)
|
427
|
+
|
428
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
429
|
+
times: 1, body: request)
|
430
|
+
|
431
|
+
sleep(3)
|
432
|
+
|
433
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
434
|
+
times: 2, body: request)
|
435
|
+
|
436
|
+
sleep(3)
|
437
|
+
|
438
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
439
|
+
times: 3, body: request)
|
440
|
+
|
441
|
+
sleep(3)
|
442
|
+
|
443
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
444
|
+
times: 4, body: request)
|
445
|
+
|
446
|
+
sleep(3)
|
447
|
+
end
|
448
|
+
|
449
|
+
assert_equal('429', error.code)
|
450
|
+
|
451
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
452
|
+
times: 4, body: request)
|
453
|
+
end
|
454
|
+
|
455
|
+
def test_connection_error
|
456
|
+
error_message = 'Failed to open TCP connection to localhost:9999' \
|
457
|
+
'(Connection refused - connect(2) for "localhost" port 9999)'
|
272
458
|
|
273
459
|
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
460
|
+
.to_raise(Errno::ECONNREFUSED.new(error_message))
|
461
|
+
.to_raise(Errno::ECONNREFUSED.new(error_message))
|
462
|
+
.to_raise(Errno::ECONNREFUSED.new(error_message))
|
463
|
+
.to_raise(Errno::ECONNREFUSED.new(error_message))
|
464
|
+
.to_raise(Errno::ECONNREFUSED.new(error_message))
|
465
|
+
|
466
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
467
|
+
.add_tag('location', 'europe')
|
468
|
+
.add_field('level', 2.0)
|
469
|
+
|
470
|
+
request = 'h2o,location=europe level=2.0'
|
471
|
+
|
472
|
+
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
473
|
+
batch_size: 1, retry_interval: 2_000, max_retries: 3,
|
474
|
+
max_retry_delay: 5_000, exponential_base: 2)
|
475
|
+
|
476
|
+
error = assert_raises InfluxDB2::InfluxError do
|
477
|
+
@client.create_write_api(write_options: write_options).write(data: point)
|
478
|
+
|
479
|
+
sleep(0.5)
|
480
|
+
|
481
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
482
|
+
times: 1, body: request)
|
483
|
+
|
484
|
+
sleep(2)
|
485
|
+
|
486
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
487
|
+
times: 2, body: request)
|
488
|
+
|
489
|
+
sleep(4)
|
490
|
+
|
491
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
492
|
+
times: 3, body: request)
|
493
|
+
|
494
|
+
sleep(5)
|
495
|
+
|
496
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
497
|
+
times: 4, body: request)
|
498
|
+
|
499
|
+
sleep(5)
|
500
|
+
|
501
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
502
|
+
times: 4, body: request)
|
503
|
+
|
504
|
+
sleep(5)
|
505
|
+
end
|
506
|
+
|
507
|
+
assert_equal('Connection refused - ' + error_message, error.message)
|
508
|
+
end
|
509
|
+
|
510
|
+
def test_write_connection_error
|
511
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
512
|
+
.to_raise(Errno::ECONNREFUSED.new(''))
|
513
|
+
.to_raise(Errno::ECONNREFUSED.new(''))
|
274
514
|
.to_return(status: 204)
|
275
515
|
|
276
|
-
|
277
|
-
|
516
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
517
|
+
.add_tag('location', 'europe')
|
518
|
+
.add_field('level', 2.0)
|
278
519
|
|
279
|
-
|
280
|
-
'h2o_feet,location=coyote_creek water_level=2.0 2'])
|
520
|
+
request = 'h2o,location=europe level=2.0'
|
281
521
|
|
282
|
-
|
522
|
+
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
523
|
+
batch_size: 1, retry_interval: 2_000, max_retries: 3,
|
524
|
+
max_retry_delay: 5_000, exponential_base: 2)
|
525
|
+
|
526
|
+
@client.create_write_api(write_options: write_options).write(data: point)
|
527
|
+
|
528
|
+
sleep(0.5)
|
283
529
|
|
284
530
|
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
285
|
-
times:
|
531
|
+
times: 1, body: request)
|
286
532
|
|
287
533
|
sleep(2)
|
288
534
|
|
289
535
|
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
290
|
-
times:
|
536
|
+
times: 2, body: request)
|
537
|
+
|
538
|
+
sleep(4)
|
539
|
+
|
540
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
541
|
+
times: 3, body: request)
|
542
|
+
|
543
|
+
sleep(5)
|
544
|
+
|
545
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
546
|
+
times: 3, body: request)
|
291
547
|
end
|
292
548
|
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.7.0.pre.
|
4
|
+
version: 1.7.0.pre.1121
|
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-
|
11
|
+
date: 2020-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|