influxdb-client 1.8.0.pre.1240 → 1.8.0.pre.1263

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
  SHA256:
3
- metadata.gz: e49b8841c9ce5b13c24595d8fec2b2ed6eb8fe6676b606b9a10ef851d8ea98a9
4
- data.tar.gz: 328d60cf43f6d5c1a43e5ac22945a76175c2752b370a5ca155a7236aedbe79be
3
+ metadata.gz: 5ba6e1a795cfc14a92d8b180805d0f29f5f2e3900df425d8cbee91d65f9abaae
4
+ data.tar.gz: 65538d4807625678690f99c00fe899d9ef1507a7cbab9475756a9584d9275c51
5
5
  SHA512:
6
- metadata.gz: 5a20d45c4dad7031e96bedb7ac76c3f146a17d8bec00fad5eba2d6cba062bcef172b5c389dce7db589b8d5481256cc246d652c48019fb6087b4d49f88c45c7d6
7
- data.tar.gz: 707f373b6a72790a4e34b40490077b2da5e2bd1b2fd703d48237a1a80a4b5fe1053bb2b4263fb8f586e37c85544ac3b292f22d9c8012f101e0db56f483ba617c
6
+ metadata.gz: d82be29fca952ff4b1e430326ba1c08b7ae11222a273cdc17bd1632ac7f3e9b7865e98a5c9c96ecca6ad86a606a4043875a14a0fafc9ce5ba42cc28b30f08988
7
+ data.tar.gz: 578d4451054165478ed70636ec30c8024ff78c9d56f10cc6898256eb005a5c0d67ee31582e96c36106c1eb9f6a84afe23018e2513057c294a2b5dbec32303268
@@ -2,6 +2,7 @@
2
2
 
3
3
  ### Features
4
4
  1. [#36](https://github.com/influxdata/influxdb-client-ruby/issues/36): Added support for default tags
5
+ 1. [#53](https://github.com/influxdata/influxdb-client-ruby/pull/53): Default strategy for batching worker is best-effort
5
6
 
6
7
  ### API
7
8
  1. [#50](https://github.com/influxdata/influxdb-client-ruby/pull/50): Default port changed from 9999 -> 8086
data/README.md CHANGED
@@ -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,
@@ -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)
@@ -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
@@ -338,38 +338,34 @@ class WriteApiRetryStrategyTest < MiniTest::Test
338
338
  batch_size: 1, retry_interval: 2_000, max_retries: 3,
339
339
  max_retry_delay: 5_000, exponential_base: 2)
340
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)
341
+ @client.create_write_api(write_options: write_options).write(data: point)
345
342
 
346
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
347
- times: 1, body: request)
343
+ sleep(0.5)
348
344
 
349
- sleep(2)
345
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
346
+ times: 1, body: request)
350
347
 
351
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
352
- times: 2, body: request)
348
+ sleep(2)
353
349
 
354
- sleep(4)
350
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
351
+ times: 2, body: request)
355
352
 
356
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
357
- times: 3, body: request)
353
+ sleep(4)
358
354
 
359
- sleep(5)
355
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
356
+ times: 3, body: request)
360
357
 
361
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
362
- times: 4, body: request)
358
+ sleep(5)
363
359
 
364
- sleep(5)
360
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
361
+ times: 4, body: request)
365
362
 
366
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
367
- times: 4, body: request)
363
+ sleep(5)
368
364
 
369
- sleep(5)
370
- end
365
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
366
+ times: 4, body: request)
371
367
 
372
- assert_equal('429', error.code)
368
+ sleep(5)
373
369
 
374
370
  assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
375
371
  times: 4, body: request)
@@ -384,7 +380,8 @@ class WriteApiRetryStrategyTest < MiniTest::Test
384
380
 
385
381
  write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
386
382
  batch_size: 1, retry_interval: 2_000, max_retries: 3,
387
- max_retry_delay: 5_000, exponential_base: 2)
383
+ max_retry_delay: 5_000, exponential_base: 2,
384
+ batch_abort_on_exception: true)
388
385
 
389
386
  error = assert_raises InfluxDB2::InfluxError do
390
387
  @client.create_write_api(write_options: write_options).write(data: 'h2o,location=west value=33i 15')
@@ -420,33 +417,29 @@ class WriteApiRetryStrategyTest < MiniTest::Test
420
417
  batch_size: 1, retry_interval: 2_000, max_retries: 3,
421
418
  max_retry_delay: 5_000, exponential_base: 2)
422
419
 
423
- error = assert_raises InfluxDB2::InfluxError do
424
- @client.create_write_api(write_options: write_options).write(data: point)
425
-
426
- sleep(0.5)
420
+ @client.create_write_api(write_options: write_options).write(data: point)
427
421
 
428
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
429
- times: 1, body: request)
422
+ sleep(0.5)
430
423
 
431
- sleep(3)
424
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
425
+ times: 1, body: request)
432
426
 
433
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
434
- times: 2, body: request)
427
+ sleep(3)
435
428
 
436
- sleep(3)
429
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
430
+ times: 2, body: request)
437
431
 
438
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
439
- times: 3, body: request)
432
+ sleep(3)
440
433
 
441
- sleep(3)
434
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
435
+ times: 3, body: request)
442
436
 
443
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
444
- times: 4, body: request)
437
+ sleep(3)
445
438
 
446
- sleep(3)
447
- end
439
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
440
+ times: 4, body: request)
448
441
 
449
- assert_equal('429', error.code)
442
+ sleep(3)
450
443
 
451
444
  assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
452
445
  times: 4, body: request)
@@ -473,38 +466,37 @@ class WriteApiRetryStrategyTest < MiniTest::Test
473
466
  batch_size: 1, retry_interval: 2_000, max_retries: 3,
474
467
  max_retry_delay: 5_000, exponential_base: 2)
475
468
 
476
- error = assert_raises InfluxDB2::InfluxError do
477
- @client.create_write_api(write_options: write_options).write(data: point)
469
+ @client.create_write_api(write_options: write_options).write(data: point)
478
470
 
479
- sleep(0.5)
471
+ sleep(0.5)
480
472
 
481
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
482
- times: 1, body: request)
473
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
474
+ times: 1, body: request)
483
475
 
484
- sleep(2)
476
+ sleep(2)
485
477
 
486
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
487
- times: 2, body: request)
478
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
479
+ times: 2, body: request)
488
480
 
489
- sleep(4)
481
+ sleep(4)
490
482
 
491
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
492
- times: 3, body: request)
483
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
484
+ times: 3, body: request)
493
485
 
494
- sleep(5)
486
+ sleep(5)
495
487
 
496
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
497
- times: 4, body: request)
488
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
489
+ times: 4, body: request)
498
490
 
499
- sleep(5)
491
+ sleep(5)
500
492
 
501
- assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
502
- times: 4, body: request)
493
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
494
+ times: 4, body: request)
503
495
 
504
- sleep(5)
505
- end
496
+ sleep(5)
506
497
 
507
- assert_equal('Connection refused - ' + error_message, error.message)
498
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
499
+ times: 4, body: request)
508
500
  end
509
501
 
510
502
  def test_write_connection_error
@@ -545,4 +537,61 @@ class WriteApiRetryStrategyTest < MiniTest::Test
545
537
  assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
546
538
  times: 3, body: request)
547
539
  end
540
+
541
+ def test_abort_on_exception
542
+ error_body = '{"code":"invalid","message":"unable to parse '\
543
+ '\'h2o,location=europe 1\'"}'
544
+
545
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
546
+ .to_return(status: 400, headers: { 'X-Platform-Error-Code' => 'invalid' }, body: error_body)
547
+ .to_return(status: 204)
548
+
549
+ write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
550
+ batch_size: 1, retry_interval: 500, max_retries: 1,
551
+ max_retry_delay: 5_000, exponential_base: 1,
552
+ batch_abort_on_exception: true)
553
+
554
+ write_api = @client.create_write_api(write_options: write_options)
555
+
556
+ error = assert_raises InfluxDB2::InfluxError do
557
+ write_api.write(data: 'h2o,location=europe 1')
558
+ write_api.write(data: 'h2o,location=europe level=2.0 1')
559
+
560
+ sleep(2)
561
+ end
562
+
563
+ assert_equal("unable to parse 'h2o,location=europe 1'", error.message)
564
+
565
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
566
+ times: 1, body: 'h2o,location=europe 1')
567
+
568
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
569
+ times: 0, body: 'h2o,location=europe level=2.0 1')
570
+ end
571
+
572
+ def test_abort_on_exception_next_batch
573
+ error_body = '{"code":"invalid","message":"unable to parse '\
574
+ '\'h2o,location=europe 1\'"}'
575
+
576
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
577
+ .to_return(status: 400, headers: { 'X-Platform-Error-Code' => 'invalid' }, body: error_body)
578
+ .to_return(status: 204)
579
+
580
+ write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
581
+ batch_size: 1, retry_interval: 500, max_retries: 1,
582
+ max_retry_delay: 5_000, exponential_base: 1)
583
+
584
+ write_api = @client.create_write_api(write_options: write_options)
585
+
586
+ write_api.write(data: 'h2o,location=europe 1')
587
+ write_api.write(data: 'h2o,location=europe level=2.0 1')
588
+
589
+ sleep(2)
590
+
591
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
592
+ times: 1, body: 'h2o,location=europe 1')
593
+
594
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
595
+ times: 1, body: 'h2o,location=europe level=2.0 1')
596
+ end
548
597
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.8.0.pre.1263
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Bednar