influxdb-client 1.9.0.pre.1301 → 1.9.0.pre.1331

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: 2d671be12047966afd88d59cf5d96f5422e1154bbd4d7698329fa90c4f382ed4
4
- data.tar.gz: 93bc78686d5bdf9eedd526969e73d87a0356ea1ba9e21073e525f4ab6a956adf
3
+ metadata.gz: 13f587f991c459071204269e2e9efd40dc01b3e586710769beef4c70cb85071b
4
+ data.tar.gz: d8ef882a6370da524e67e926230196011a577f25d27fa0b80bd5372a3842027f
5
5
  SHA512:
6
- metadata.gz: b3425542284cf56e6c3531697bbe0edcdb24eab9e0fb2b90f675555eeaadac45c7edc316646bf72cf181383bad23ee3eae03c27078ff5f2048586d93fa12647d
7
- data.tar.gz: 6ad395bd8498e81231b61701d8cb2c86aa268638a1c31ac50189aa6b7219d8f9466dbd79ff78242259bb4369c890951ef73b41de5611f41a0baa8aeb2cb9dc92
6
+ metadata.gz: 6333aa4d6ed7ce13b520d1659362e057a023c1beef668e23d9fdaa4eb89046f76a3a0f770a6dcdc3dfd3e9b593289d1fc696462c56310a3dc5f14d0449401e82
7
+ data.tar.gz: d97d59e3a14bfaf828801bbbb81d1abd00f5e865eed54bcddf8588732330c4f452a8d0d0d85cba4535d4a50b9731eaaa02a3ecdaaeee943f2760aae59902534e
@@ -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,5 +1,8 @@
1
1
  ## 1.9.0 [unreleased]
2
2
 
3
+ ### Features
4
+ 1. [#55](https://github.com/influxdata/influxdb-client-runy/pull/55): Improved logging message for retries
5
+
3
6
  ## 1.8.0 [2020-10-02]
4
7
 
5
8
  ### Features
@@ -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)
@@ -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
@@ -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
@@ -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
@@ -594,4 +596,32 @@ class WriteApiRetryStrategyTest < MiniTest::Test
594
596
  assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
595
597
  times: 1, body: 'h2o,location=europe level=2.0 1')
596
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
597
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.9.0.pre.1301
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-10-02 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