influxdb-client 1.8.0.pre.1240 → 1.9.0.pre.1331

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e49b8841c9ce5b13c24595d8fec2b2ed6eb8fe6676b606b9a10ef851d8ea98a9
4
- data.tar.gz: 328d60cf43f6d5c1a43e5ac22945a76175c2752b370a5ca155a7236aedbe79be
3
+ metadata.gz: 13f587f991c459071204269e2e9efd40dc01b3e586710769beef4c70cb85071b
4
+ data.tar.gz: d8ef882a6370da524e67e926230196011a577f25d27fa0b80bd5372a3842027f
5
5
  SHA512:
6
- metadata.gz: 5a20d45c4dad7031e96bedb7ac76c3f146a17d8bec00fad5eba2d6cba062bcef172b5c389dce7db589b8d5481256cc246d652c48019fb6087b4d49f88c45c7d6
7
- data.tar.gz: 707f373b6a72790a4e34b40490077b2da5e2bd1b2fd703d48237a1a80a4b5fe1053bb2b4263fb8f586e37c85544ac3b292f22d9c8012f101e0db56f483ba617c
6
+ metadata.gz: 6333aa4d6ed7ce13b520d1659362e057a023c1beef668e23d9fdaa4eb89046f76a3a0f770a6dcdc3dfd3e9b593289d1fc696462c56310a3dc5f14d0449401e82
7
+ data.tar.gz: d97d59e3a14bfaf828801bbbb81d1abd00f5e865eed54bcddf8588732330c4f452a8d0d0d85cba4535d4a50b9731eaaa02a3ecdaaeee943f2760aae59902534e
@@ -78,7 +78,7 @@ jobs:
78
78
  default: &default-ruby-image "circleci/ruby:2.6-stretch"
79
79
  influxdb-image:
80
80
  type: string
81
- default: &default-influxdb-image "influxdb:2.0.0-beta"
81
+ default: &default-influxdb-image "influxdb:2.0.0-rc"
82
82
  docker:
83
83
  - image: << parameters.ruby-image >>
84
84
  - image: &influx-image quay.io/influxdb/<< parameters.influxdb-image >>
@@ -34,7 +34,7 @@ Metrics/MethodLength:
34
34
  Metrics/ClassLength:
35
35
  Max: 300
36
36
  Metrics/AbcSize:
37
- Max: 40
37
+ Max: 50
38
38
  Metrics/CyclomaticComplexity:
39
39
  Max: 15
40
40
  Metrics/PerceivedComplexity:
@@ -1,7 +1,13 @@
1
- ## 1.8.0 [unreleased]
1
+ ## 1.9.0 [unreleased]
2
+
3
+ ### Features
4
+ 1. [#55](https://github.com/influxdata/influxdb-client-runy/pull/55): Improved logging message for retries
5
+
6
+ ## 1.8.0 [2020-10-02]
2
7
 
3
8
  ### Features
4
9
  1. [#36](https://github.com/influxdata/influxdb-client-ruby/issues/36): Added support for default tags
10
+ 1. [#53](https://github.com/influxdata/influxdb-client-ruby/pull/53): Default strategy for batching worker is best-effort
5
11
 
6
12
  ### API
7
13
  1. [#50](https://github.com/influxdata/influxdb-client-ruby/pull/50): Default port changed from 9999 -> 8086
data/README.md CHANGED
@@ -23,7 +23,7 @@ The client can be installed manually or with bundler.
23
23
  To install the client gem manually:
24
24
 
25
25
  ```
26
- gem install influxdb-client -v 1.7.0
26
+ gem install influxdb-client -v 1.8.0
27
27
  ```
28
28
 
29
29
  ## Usage
@@ -128,6 +128,7 @@ The writes are processed in batches which are configurable by `WriteOptions`:
128
128
  | max_retries | the number of max retries when write fails | 5 |
129
129
  | max_retry_delay | maximum delay when retrying write in milliseconds | 180000 |
130
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 |
131
+ | batch_abort_on_exception | the batching worker will be aborted after failed retry strategy | false |
131
132
  ```ruby
132
133
  write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
133
134
  batch_size: 10, flush_interval: 5_000,
@@ -27,7 +27,7 @@ DEFAULT_DOCKER_REGISTRY="quay.io/influxdb/"
27
27
  DOCKER_REGISTRY="${DOCKER_REGISTRY:-$DEFAULT_DOCKER_REGISTRY}"
28
28
 
29
29
  DEFAULT_INFLUXDB_V2_REPOSITORY="influxdb"
30
- DEFAULT_INFLUXDB_V2_VERSION="2.0.0-beta"
30
+ DEFAULT_INFLUXDB_V2_VERSION="2.0.0-rc"
31
31
  INFLUXDB_V2_REPOSITORY="${INFLUXDB_V2_REPOSITORY:-$DEFAULT_INFLUXDB_V2_REPOSITORY}"
32
32
  INFLUXDB_V2_VERSION="${INFLUXDB_V2_VERSION:-$DEFAULT_INFLUXDB_V2_VERSION}"
33
33
  INFLUXDB_V2_IMAGE=${DOCKER_REGISTRY}${INFLUXDB_V2_REPOSITORY}:${INFLUXDB_V2_VERSION}
@@ -43,6 +43,7 @@ module InfluxDB2
43
43
  # @option options [Integer] :read_timeout Number of seconds to wait for one block of data to be read
44
44
  # @option options [Integer] :max_redirect_count Maximal number of followed HTTP redirects
45
45
  # @option options [bool] :use_ssl Turn on/off SSL for HTTP communication
46
+ # @option options [Logger] :logger Logger used for logging. Disable logging by set to false.
46
47
  # @option options [Hash] :tags Default tags which will be added to each point written by api.
47
48
  # the body line-protocol
48
49
  def initialize(url, token, options = nil)
@@ -50,6 +51,7 @@ module InfluxDB2
50
51
  @options = options ? options.dup : {}
51
52
  @options[:url] = url if url.is_a? String
52
53
  @options[:token] = token if token.is_a? String
54
+ @options[:logger] = @options[:logger].nil? ? DefaultApi.create_logger : @options[:logger]
53
55
  @closed = false
54
56
 
55
57
  at_exit { close! }
@@ -18,6 +18,8 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
+ require 'logger'
22
+
21
23
  module InfluxDB2
22
24
  # default api
23
25
  class DefaultApi
@@ -32,6 +34,29 @@ module InfluxDB2
32
34
  @max_redirect_count = @options[:max_redirect_count] || DEFAULT_REDIRECT_COUNT
33
35
  end
34
36
 
37
+ def log(level, message)
38
+ return unless @options[:logger]
39
+
40
+ log_level = case level
41
+ when :debug then
42
+ Logger::DEBUG
43
+ when :warn then
44
+ Logger::WARN
45
+ when :error then
46
+ Logger::ERROR
47
+ when :fatal then
48
+ Logger::FATAL
49
+ else
50
+ Logger::INFO
51
+ end
52
+
53
+ @options[:logger].add(log_level) { message }
54
+ end
55
+
56
+ def self.create_logger
57
+ Logger.new(STDOUT)
58
+ end
59
+
35
60
  private
36
61
 
37
62
  def _parse_uri(api_path)
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module InfluxDB2
22
- VERSION = '1.8.0'.freeze
22
+ VERSION = '1.9.0'.freeze
23
23
  end
@@ -37,7 +37,7 @@ module InfluxDB2
37
37
  _check_background_queue
38
38
  end
39
39
  end
40
- @thread_flush.abort_on_exception = true
40
+ @thread_flush.abort_on_exception = @write_options.batch_abort_on_exception
41
41
 
42
42
  @thread_size = Thread.new do
43
43
  until api_client.closed
@@ -45,7 +45,7 @@ module InfluxDB2
45
45
  sleep 0.01
46
46
  end
47
47
  end
48
- @thread_size.abort_on_exception = true
48
+ @thread_size.abort_on_exception = @write_options.batch_abort_on_exception
49
49
  end
50
50
 
51
51
  def push(payload)
@@ -116,6 +116,10 @@ module InfluxDB2
116
116
  e.retry_after.to_f
117
117
  end
118
118
 
119
+ message = 'The retriable error occurred during writing of data. '\
120
+ "Reason: '#{e.message}'. Retry in: #{timeout}s."
121
+
122
+ @api_client.log(:warn, message)
119
123
  sleep timeout
120
124
  _write_raw(key, points, attempts + 1, retry_interval * @write_options.exponential_base)
121
125
  end
@@ -39,8 +39,10 @@ module InfluxDB2
39
39
  # by a random amount
40
40
  # @param [Integer] exponential_base: base for the exponential retry delay, the next delay is computed as
41
41
  # "exponential_base^(attempts-1) + random(jitter_interval)"
42
+ # @param [Boolean] batch_abort_on_exception: batching worker will be aborted after failed retry strategy
42
43
  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)
44
+ jitter_interval: 0, max_retries: 5, max_retry_delay: 180_000, exponential_base: 5,
45
+ batch_abort_on_exception: false)
44
46
  _check_not_negative('batch_size', batch_size)
45
47
  _check_not_negative('flush_interval', flush_interval)
46
48
  _check_not_negative('retry_interval', retry_interval)
@@ -56,10 +58,11 @@ module InfluxDB2
56
58
  @max_retries = max_retries
57
59
  @max_retry_delay = max_retry_delay
58
60
  @exponential_base = exponential_base
61
+ @batch_abort_on_exception = batch_abort_on_exception
59
62
  end
60
63
 
61
64
  attr_reader :write_type, :batch_size, :flush_interval, :retry_interval, :jitter_interval,
62
- :max_retries, :max_retry_delay, :exponential_base
65
+ :max_retries, :max_retry_delay, :exponential_base, :batch_abort_on_exception
63
66
 
64
67
  def _check_not_negative(key, value)
65
68
  raise ArgumentError, "The '#{key}' should be positive or zero, but is: #{value}" if value <= 0
@@ -0,0 +1,60 @@
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
+ require 'influxdb2/client/default_api'
23
+
24
+ class DefaultApiTest < MiniTest::Test
25
+ def setup
26
+ @logger = MockLogger.new
27
+ @api = InfluxDB2::DefaultApi.new(options: { logger: @logger })
28
+ end
29
+
30
+ def test_level
31
+ @api.log(:debug, 'debug message')
32
+ @api.log(:warn, 'warn message')
33
+ @api.log(:error, 'error message')
34
+ @api.log(:info, 'info message')
35
+ @api.log(:others, 'others message')
36
+
37
+ assert_equal 5, @logger.messages.count
38
+
39
+ assert_equal Logger::DEBUG, @logger.messages[0][0]
40
+ assert_equal 'debug message', @logger.messages[0][1]
41
+
42
+ assert_equal Logger::WARN, @logger.messages[1][0]
43
+ assert_equal 'warn message', @logger.messages[1][1]
44
+
45
+ assert_equal Logger::ERROR, @logger.messages[2][0]
46
+ assert_equal 'error message', @logger.messages[2][1]
47
+
48
+ assert_equal Logger::INFO, @logger.messages[3][0]
49
+ assert_equal 'info message', @logger.messages[3][1]
50
+
51
+ assert_equal Logger::INFO, @logger.messages[4][0]
52
+ assert_equal 'others message', @logger.messages[4][1]
53
+ end
54
+
55
+ def test_supports_false
56
+ @api = InfluxDB2::DefaultApi.new(options: { logger: false })
57
+
58
+ @api.log(:info, 'without error')
59
+ end
60
+ end
@@ -73,12 +73,16 @@ class DeleteApiIntegrationTest < MiniTest::Test
73
73
  end
74
74
 
75
75
  def test_delete_all
76
+ # TODO: https://github.com/influxdata/influxdb/issues/19545
77
+ skip
76
78
  @client.create_delete_api.delete(Time.utc(2010, 10, 15, 7, 20, 15), Time.utc(2020, 10, 14, 8, 20, 15))
77
79
 
78
80
  assert_equal 0, _query_count
79
81
  end
80
82
 
81
83
  def test_delete_without_interval
84
+ # TODO: https://github.com/influxdata/influxdb/issues/19545
85
+ skip
82
86
  error = assert_raises InfluxDB2::InfluxError do
83
87
  @client.create_delete_api.delete(nil, nil)
84
88
  end
@@ -226,6 +226,7 @@ class WriteApiRetryStrategyTest < MiniTest::Test
226
226
  def setup
227
227
  WebMock.disable_net_connect!
228
228
 
229
+ @logger = MockLogger.new
229
230
  @write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
230
231
  batch_size: 2, flush_interval: 5_000, retry_interval: 2_000)
231
232
  @client = InfluxDB2::Client.new('http://localhost:8086',
@@ -233,7 +234,8 @@ class WriteApiRetryStrategyTest < MiniTest::Test
233
234
  bucket: 'my-bucket',
234
235
  org: 'my-org',
235
236
  precision: InfluxDB2::WritePrecision::NANOSECOND,
236
- use_ssl: false)
237
+ use_ssl: false,
238
+ logger: @logger)
237
239
 
238
240
  @write_client = @client.create_write_api(write_options: @write_options)
239
241
  end
@@ -338,38 +340,34 @@ class WriteApiRetryStrategyTest < MiniTest::Test
338
340
  batch_size: 1, retry_interval: 2_000, max_retries: 3,
339
341
  max_retry_delay: 5_000, exponential_base: 2)
340
342
 
341
- error = assert_raises InfluxDB2::InfluxError do
342
- @client.create_write_api(write_options: write_options).write(data: point)
343
-
344
- sleep(0.5)
343
+ @client.create_write_api(write_options: write_options).write(data: point)
345
344
 
346
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
347
- times: 1, body: request)
345
+ sleep(0.5)
348
346
 
349
- sleep(2)
347
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
348
+ times: 1, body: request)
350
349
 
351
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
352
- times: 2, body: request)
350
+ sleep(2)
353
351
 
354
- sleep(4)
352
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
353
+ times: 2, body: request)
355
354
 
356
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
357
- times: 3, body: request)
355
+ sleep(4)
358
356
 
359
- sleep(5)
357
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
358
+ times: 3, body: request)
360
359
 
361
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
362
- times: 4, body: request)
360
+ sleep(5)
363
361
 
364
- sleep(5)
362
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
363
+ times: 4, body: request)
365
364
 
366
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
367
- times: 4, body: request)
365
+ sleep(5)
368
366
 
369
- sleep(5)
370
- end
367
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
368
+ times: 4, body: request)
371
369
 
372
- assert_equal('429', error.code)
370
+ sleep(5)
373
371
 
374
372
  assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
375
373
  times: 4, body: request)
@@ -384,7 +382,8 @@ class WriteApiRetryStrategyTest < MiniTest::Test
384
382
 
385
383
  write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
386
384
  batch_size: 1, retry_interval: 2_000, max_retries: 3,
387
- max_retry_delay: 5_000, exponential_base: 2)
385
+ max_retry_delay: 5_000, exponential_base: 2,
386
+ batch_abort_on_exception: true)
388
387
 
389
388
  error = assert_raises InfluxDB2::InfluxError do
390
389
  @client.create_write_api(write_options: write_options).write(data: 'h2o,location=west value=33i 15')
@@ -420,33 +419,29 @@ class WriteApiRetryStrategyTest < MiniTest::Test
420
419
  batch_size: 1, retry_interval: 2_000, max_retries: 3,
421
420
  max_retry_delay: 5_000, exponential_base: 2)
422
421
 
423
- error = assert_raises InfluxDB2::InfluxError do
424
- @client.create_write_api(write_options: write_options).write(data: point)
425
-
426
- sleep(0.5)
422
+ @client.create_write_api(write_options: write_options).write(data: point)
427
423
 
428
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
429
- times: 1, body: request)
424
+ sleep(0.5)
430
425
 
431
- sleep(3)
426
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
427
+ times: 1, body: request)
432
428
 
433
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
434
- times: 2, body: request)
429
+ sleep(3)
435
430
 
436
- sleep(3)
431
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
432
+ times: 2, body: request)
437
433
 
438
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
439
- times: 3, body: request)
434
+ sleep(3)
440
435
 
441
- sleep(3)
436
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
437
+ times: 3, body: request)
442
438
 
443
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
444
- times: 4, body: request)
439
+ sleep(3)
445
440
 
446
- sleep(3)
447
- end
441
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
442
+ times: 4, body: request)
448
443
 
449
- assert_equal('429', error.code)
444
+ sleep(3)
450
445
 
451
446
  assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
452
447
  times: 4, body: request)
@@ -473,38 +468,37 @@ class WriteApiRetryStrategyTest < MiniTest::Test
473
468
  batch_size: 1, retry_interval: 2_000, max_retries: 3,
474
469
  max_retry_delay: 5_000, exponential_base: 2)
475
470
 
476
- error = assert_raises InfluxDB2::InfluxError do
477
- @client.create_write_api(write_options: write_options).write(data: point)
471
+ @client.create_write_api(write_options: write_options).write(data: point)
478
472
 
479
- sleep(0.5)
473
+ sleep(0.5)
480
474
 
481
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
482
- times: 1, body: request)
475
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
476
+ times: 1, body: request)
483
477
 
484
- sleep(2)
478
+ sleep(2)
485
479
 
486
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
487
- times: 2, body: request)
480
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
481
+ times: 2, body: request)
488
482
 
489
- sleep(4)
483
+ sleep(4)
490
484
 
491
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
492
- times: 3, body: request)
485
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
486
+ times: 3, body: request)
493
487
 
494
- sleep(5)
488
+ sleep(5)
495
489
 
496
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
497
- times: 4, body: request)
490
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
491
+ times: 4, body: request)
498
492
 
499
- sleep(5)
493
+ sleep(5)
500
494
 
501
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
502
- times: 4, body: request)
495
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
496
+ times: 4, body: request)
503
497
 
504
- sleep(5)
505
- end
498
+ sleep(5)
506
499
 
507
- assert_equal('Connection refused - ' + error_message, error.message)
500
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
501
+ times: 4, body: request)
508
502
  end
509
503
 
510
504
  def test_write_connection_error
@@ -545,4 +539,89 @@ class WriteApiRetryStrategyTest < MiniTest::Test
545
539
  assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
546
540
  times: 3, body: request)
547
541
  end
542
+
543
+ def test_abort_on_exception
544
+ error_body = '{"code":"invalid","message":"unable to parse '\
545
+ '\'h2o,location=europe 1\'"}'
546
+
547
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
548
+ .to_return(status: 400, headers: { 'X-Platform-Error-Code' => 'invalid' }, body: error_body)
549
+ .to_return(status: 204)
550
+
551
+ write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
552
+ batch_size: 1, retry_interval: 500, max_retries: 1,
553
+ max_retry_delay: 5_000, exponential_base: 1,
554
+ batch_abort_on_exception: true)
555
+
556
+ write_api = @client.create_write_api(write_options: write_options)
557
+
558
+ error = assert_raises InfluxDB2::InfluxError do
559
+ write_api.write(data: 'h2o,location=europe 1')
560
+ write_api.write(data: 'h2o,location=europe level=2.0 1')
561
+
562
+ sleep(2)
563
+ end
564
+
565
+ assert_equal("unable to parse 'h2o,location=europe 1'", error.message)
566
+
567
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
568
+ times: 1, body: 'h2o,location=europe 1')
569
+
570
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
571
+ times: 0, body: 'h2o,location=europe level=2.0 1')
572
+ end
573
+
574
+ def test_abort_on_exception_next_batch
575
+ error_body = '{"code":"invalid","message":"unable to parse '\
576
+ '\'h2o,location=europe 1\'"}'
577
+
578
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
579
+ .to_return(status: 400, headers: { 'X-Platform-Error-Code' => 'invalid' }, body: error_body)
580
+ .to_return(status: 204)
581
+
582
+ write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
583
+ batch_size: 1, retry_interval: 500, max_retries: 1,
584
+ max_retry_delay: 5_000, exponential_base: 1)
585
+
586
+ write_api = @client.create_write_api(write_options: write_options)
587
+
588
+ write_api.write(data: 'h2o,location=europe 1')
589
+ write_api.write(data: 'h2o,location=europe level=2.0 1')
590
+
591
+ sleep(2)
592
+
593
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
594
+ times: 1, body: 'h2o,location=europe 1')
595
+
596
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
597
+ times: 1, body: 'h2o,location=europe level=2.0 1')
598
+ end
599
+
600
+ def test_retry_contains_message
601
+ error_body = '{"code":"temporarily unavailable","message":"Server is temporarily unavailable to accept writes."}'
602
+
603
+ stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
604
+ .to_return(status: 429, headers: { 'X-Platform-Error-Code' => 'temporarily unavailable', 'Retry-After' => '3' },
605
+ body: error_body).then
606
+ .to_return(status: 204)
607
+
608
+ request = "h2o_feet,location=coyote_creek water_level=1.0 1\n" \
609
+ 'h2o_feet,location=coyote_creek water_level=2.0 2'
610
+
611
+ @write_client.write(data: ['h2o_feet,location=coyote_creek water_level=1.0 1',
612
+ InfluxDB2::Point.new(name: 'h2o_feet')
613
+ .add_tag('location', 'coyote_creek')
614
+ .add_field('water_level', 2.0)
615
+ .time(2, InfluxDB2::WritePrecision::NANOSECOND)])
616
+
617
+ sleep(5)
618
+
619
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
620
+ times: 2, body: request)
621
+
622
+ message = 'The retriable error occurred during writing of data. '\
623
+ "Reason: 'Server is temporarily unavailable to accept writes.'. Retry in: 3.0s."
624
+
625
+ assert_equal(message, @logger.messages[0][1])
626
+ end
548
627
  end
@@ -37,3 +37,15 @@ require 'minitest/reporters'
37
37
  Minitest::Reporters.use!
38
38
 
39
39
  require 'webmock/minitest'
40
+
41
+ class MockLogger
42
+ attr_accessor :messages
43
+
44
+ def initialize
45
+ @messages = []
46
+ end
47
+
48
+ def add(level, &block)
49
+ @messages << [level, yield(block)]
50
+ end
51
+ 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.8.0.pre.1240
4
+ version: 1.9.0.pre.1331
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-09-16 00:00:00.000000000 Z
11
+ date: 2020-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -168,6 +168,7 @@ files:
168
168
  - lib/influxdb2/client/worker.rb
169
169
  - lib/influxdb2/client/write_api.rb
170
170
  - test/influxdb/client_test.rb
171
+ - test/influxdb/default_api_test.rb
171
172
  - test/influxdb/delete_api_integration_test.rb
172
173
  - test/influxdb/delete_api_test.rb
173
174
  - test/influxdb/flux_csv_parser_test.rb
@@ -207,6 +208,7 @@ specification_version: 4
207
208
  summary: Ruby library for InfluxDB 2.
208
209
  test_files:
209
210
  - test/influxdb/client_test.rb
211
+ - test/influxdb/default_api_test.rb
210
212
  - test/influxdb/delete_api_integration_test.rb
211
213
  - test/influxdb/delete_api_test.rb
212
214
  - test/influxdb/flux_csv_parser_test.rb