influxdb-client 2.6.0 → 2.7.0.pre.5564

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: a2397da91eddd8ef5f3b3772d56bee3701f1955595ad26a79f43e8a699a5d9ce
4
- data.tar.gz: d21539d763ba6bace37b1e8057d4dbce75d804238ad01e02cc53c9de0eec5658
3
+ metadata.gz: e7b9486c651993c5d71cd67e4e593654ae24eb116f3e6df1c3a96cb87b27e678
4
+ data.tar.gz: 4b3a6b8c747e728f581dc8d792cf16c3ea0c29a42b5f1ee2f0c7983f75330c60
5
5
  SHA512:
6
- metadata.gz: bc0253e73cc79dc8f8be90f55cb006e5ac4e0a07397d0cf367e42990da14fb10668dc29533dc0cffe22b2ebfc86a5cd4bb7fb74a9f85558e5a1b665f1e6a8ecd
7
- data.tar.gz: ad11b47fe3630d768cf953db28eda8c8498e2b9fb78d34e5995f4e688f80ab7710f12cc51a3b2e26274e70f19aaead64cd20fa63aaadb22f49b52270ee0123dd
6
+ metadata.gz: 1b1d2aa68f76718434f290f95eddaf86477e34387dc33b6c8a2414a2e415c3d3dd6f0825f17ad5224a38dd7a6610945cc7a9639bb5718b3f496d707a6ab4f4ad
7
+ data.tar.gz: f064ffc9bb803f49f66aab0b1644e2796cb5ac95d4d628e2c52970c5f0708c770cf54e786156b01ca616f202f1abca5873a56b989b0262235112197421e65f09
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 2.7.0 [unreleased]
2
+
3
+ ### Features
4
+ 1. [#106](https://github.com/influxdata/influxdb-client-ruby/pull/106): Add logging for HTTP requests
5
+
6
+ ### Others
7
+ 1. [#108](https://github.com/influxdata/influxdb-client-ruby/pull/108): Use local repository for `influxdb-client-apis` development
8
+
1
9
  ## 2.6.0 [2022-06-24]
2
10
 
3
11
  ### Bug Fixes
data/README.md CHANGED
@@ -85,18 +85,20 @@ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token')
85
85
 
86
86
  #### Client Options
87
87
 
88
- | Option | Description | Type | Default |
89
- |---|---|---|---|
90
- | bucket | Default destination bucket for writes | String | none |
91
- | org | Default organization bucket for writes | String | none |
92
- | precision | Default precision for the unix timestamps within the body line-protocol | String | none |
93
- | open_timeout | Number of seconds to wait for the connection to open | Integer | 10 |
94
- | write_timeout | Number of seconds to wait for one block of data to be written | Integer | 10 |
95
- | read_timeout | Number of seconds to wait for one block of data to be read | Integer | 10 |
96
- | max_redirect_count | Maximal number of followed HTTP redirects | Integer | 10 |
97
- | redirect_forward_authorization | Pass Authorization header to different domain during HTTP redirect. | bool | false |
98
- | use_ssl | Turn on/off SSL for HTTP communication | bool | true |
99
- | verify_mode | Sets the flags for the certification verification at beginning of SSL/TLS session. | `OpenSSL::SSL::VERIFY_NONE` or `OpenSSL::SSL::VERIFY_PEER` | none |
88
+ | Option | Description | Type | Default |
89
+ |--------------------------------|------------------------------------------------------------------------------------|------------------------------------------------------------|----------|
90
+ | bucket | Default destination bucket for writes | String | none |
91
+ | org | Default organization bucket for writes | String | none |
92
+ | precision | Default precision for the unix timestamps within the body line-protocol | String | none |
93
+ | open_timeout | Number of seconds to wait for the connection to open | Integer | 10 |
94
+ | write_timeout | Number of seconds to wait for one block of data to be written | Integer | 10 |
95
+ | read_timeout | Number of seconds to wait for one block of data to be read | Integer | 10 |
96
+ | max_redirect_count | Maximal number of followed HTTP redirects | Integer | 10 |
97
+ | redirect_forward_authorization | Pass Authorization header to different domain during HTTP redirect. | bool | false |
98
+ | use_ssl | Turn on/off SSL for HTTP communication | bool | true |
99
+ | verify_mode | Sets the flags for the certification verification at beginning of SSL/TLS session. | `OpenSSL::SSL::VERIFY_NONE` or `OpenSSL::SSL::VERIFY_PEER` | none |
100
+ | logger | Logger used for logging. Disable logging by set to false. | Logger | `STDOUT` |
101
+ | debugging | Enable debugging for HTTP request/response. | bool | false |
100
102
 
101
103
  ```ruby
102
104
  client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
@@ -195,17 +197,17 @@ write_api.write(data: 'h2o,location=west value=33i 15')
195
197
  #### Batching
196
198
  The writes are processed in batches which are configurable by `WriteOptions`:
197
199
 
198
- | Property | Description | Default Value |
199
- | --- | --- | --- |
200
- | batchSize | the number of data point to collect in batch | 1_000 |
201
- | flush_interval | the number of milliseconds before the batch is written | 1_000 |
202
- | 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. | 5_000 |
203
- | jitter_interval | the number of milliseconds to increase the batch flush interval by a random amount | 0 |
204
- | max_retries | the number of max retries when write fails | 5 |
205
- | max_retry_delay | maximum delay when retrying write in milliseconds | 125_000 |
206
- | max_retry_time | maximum total retry timeout in milliseconds | 180_000 |
207
- | exponential_base | the base for the exponential retry delay, the next delay is computed using random exponential backoff as a random value within the interval ``retry_interval * exponential_base^(attempts-1)`` and ``retry_interval * exponential_base^(attempts)``. Example for ``retry_interval=5000, exponential_base=2, max_retry_delay=125000, total=5`` Retry delays are random distributed values within the ranges of ``[5000-10000, 10000-20000, 20000-40000, 40000-80000, 80000-125000]`` | 2 |
208
- | batch_abort_on_exception | the batching worker will be aborted after failed retry strategy | false |
200
+ | Property | Description | Default Value |
201
+ |--------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------|
202
+ | batchSize | the number of data point to collect in batch | 1_000 |
203
+ | flush_interval | the number of milliseconds before the batch is written | 1_000 |
204
+ | 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. | 5_000 |
205
+ | jitter_interval | the number of milliseconds to increase the batch flush interval by a random amount | 0 |
206
+ | max_retries | the number of max retries when write fails | 5 |
207
+ | max_retry_delay | maximum delay when retrying write in milliseconds | 125_000 |
208
+ | max_retry_time | maximum total retry timeout in milliseconds | 180_000 |
209
+ | exponential_base | the base for the exponential retry delay, the next delay is computed using random exponential backoff as a random value within the interval ``retry_interval * exponential_base^(attempts-1)`` and ``retry_interval * exponential_base^(attempts)``. Example for ``retry_interval=5000, exponential_base=2, max_retry_delay=125000, total=5`` Retry delays are random distributed values within the ranges of ``[5000-10000, 10000-20000, 20000-40000, 40000-80000, 80000-125000]`` | 2 |
210
+ | batch_abort_on_exception | the batching worker will be aborted after failed retry strategy | false |
209
211
  ```ruby
210
212
  write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
211
213
  batch_size: 10, flush_interval: 5_000,
@@ -347,13 +349,13 @@ The time range could be specified as:
347
349
 
348
350
  The client supports following management API:
349
351
 
350
- | | API docs |
351
- | --- |---------------------------------------------------------------------|
352
- | [**AuthorizationsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/AuthorizationsApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Authorizations |
353
- | [**BucketsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/BucketsApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Buckets |
354
- | [**LabelsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/LabelsApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Labels |
355
- | [**OrganizationsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/OrganizationsApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Organizations |
356
- | [**UsersApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/UsersApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Users |
352
+ | | API docs |
353
+ |-----------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
354
+ | [**AuthorizationsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/AuthorizationsApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Authorizations |
355
+ | [**BucketsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/BucketsApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Buckets |
356
+ | [**LabelsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/LabelsApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Labels |
357
+ | [**OrganizationsApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/OrganizationsApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Organizations |
358
+ | [**UsersApi**](https://influxdata.github.io/influxdb-client-ruby/InfluxDB2/API/UsersApi.html) | https://docs.influxdata.com/influxdb/latest/api/#tag/Users |
357
359
 
358
360
 
359
361
  The following example demonstrates how to use a InfluxDB 2.x Management API to create new bucket. For further information see docs and [examples](/examples).
@@ -449,11 +451,11 @@ To overcome this limitation you have to set the client property `redirect_forwar
449
451
 
450
452
  The following forward compatible APIs are available:
451
453
 
452
- | API | Endpoint | Description |
453
- |:----------|:----------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
454
- | [query_api.rb](lib/influxdb2/client/query_api.rb) | [/api/v2/query](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-query-http-endpoint) | Query data in InfluxDB 1.8.0+ using the InfluxDB 2.x API and [Flux](https://docs.influxdata.com/flux/latest/) _(endpoint should be enabled by [`flux-enabled` option](https://docs.influxdata.com/influxdb/latest/administration/config/#flux-enabled-false))_ |
455
- | [write_api.rb](lib/influxdb2/client/write_api.rb) | [/api/v2/write](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-write-http-endpoint) | Write data to InfluxDB 1.8.0+ using the InfluxDB 2.x API |
456
- | [health_api.rb](lib/influxdb2/client/health_api.rb) | [/health](https://docs.influxdata.com/influxdb/latest/tools/api/#health-http-endpoint) | Check the health of your InfluxDB instance |
454
+ | API | Endpoint | Description |
455
+ |:----------------------------------------------------|:---------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
456
+ | [query_api.rb](lib/influxdb2/client/query_api.rb) | [/api/v2/query](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-query-http-endpoint) | Query data in InfluxDB 1.8.0+ using the InfluxDB 2.x API and [Flux](https://docs.influxdata.com/flux/latest/) _(endpoint should be enabled by [`flux-enabled` option](https://docs.influxdata.com/influxdb/latest/administration/config/#flux-enabled-false))_ |
457
+ | [write_api.rb](lib/influxdb2/client/write_api.rb) | [/api/v2/write](https://docs.influxdata.com/influxdb/latest/tools/api/#api-v2-write-http-endpoint) | Write data to InfluxDB 1.8.0+ using the InfluxDB 2.x API |
458
+ | [health_api.rb](lib/influxdb2/client/health_api.rb) | [/health](https://docs.influxdata.com/influxdb/latest/tools/api/#health-http-endpoint) | Check the health of your InfluxDB instance |
457
459
 
458
460
  For detail info see [InfluxDB 1.8 example](examples/influxdb_18_example.rb).
459
461
 
@@ -37,3 +37,4 @@ require 'influxdb2/client/models/script_create_request'
37
37
  require 'influxdb2/client/models/script_language'
38
38
  require 'influxdb2/client/models/script_update_request'
39
39
  require 'influxdb2/client/models/script_invocation_params'
40
+ require 'influxdb2/client/utils/logging_helper'
@@ -49,6 +49,7 @@ module InfluxDB2
49
49
  # at beginning of SSL/TLS session. Could be one of `OpenSSL::SSL::VERIFY_NONE` or `OpenSSL::SSL::VERIFY_PEER`.
50
50
  # For more info see - https://docs.ruby-lang.org/en/3.0.0/Net/HTTP.html#verify_mode.
51
51
  # @option options [Logger] :logger Logger used for logging. Disable logging by set to false.
52
+ # @option options [bool] :debugging Enable debugging for HTTP request/response.
52
53
  # @option options [Hash] :tags Default tags which will be added to each point written by api.
53
54
  # the body line-protocol
54
55
  def initialize(url, token, options = nil)
@@ -57,6 +58,7 @@ module InfluxDB2
57
58
  @options[:url] = url if url.is_a? String
58
59
  @options[:token] = token if token.is_a? String
59
60
  @options[:logger] = @options[:logger].nil? ? DefaultApi.create_logger : @options[:logger]
61
+ @options[:debugging] = @options[:debugging].nil? ? false : @options[:debugging]
60
62
  @closed = false
61
63
 
62
64
  at_exit { close! }
@@ -102,7 +104,6 @@ module InfluxDB2
102
104
 
103
105
  # Checks the status of InfluxDB instance and version of InfluxDB.
104
106
  #
105
- # @deprecated Use `ping` instead
106
107
  # @return [Ping]
107
108
  def ping
108
109
  PingApi.new(options: @options).ping
@@ -32,25 +32,11 @@ module InfluxDB2
32
32
  def initialize(options:)
33
33
  @options = options
34
34
  @max_redirect_count = @options[:max_redirect_count] || DEFAULT_REDIRECT_COUNT
35
+ @logging_helper = LoggingHelper.new(@options[:logger])
35
36
  end
36
37
 
37
38
  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 }
39
+ @logging_helper.log(level, message)
54
40
  end
55
41
 
56
42
  def self.create_logger
@@ -90,9 +76,17 @@ module InfluxDB2
90
76
  headers.each { |k, v| request[k] = v }
91
77
 
92
78
  request.body = payload
79
+ @logging_helper.before_request(uri, request.method, request, payload) if @options[:debugging]
93
80
 
94
81
  begin
95
82
  response = http.request(request)
83
+ if @options[:debugging]
84
+ @logging_helper.after_request(response.http_version,
85
+ response.code,
86
+ response.message,
87
+ response,
88
+ response)
89
+ end
96
90
  case response
97
91
  when Net::HTTPSuccess then
98
92
  response
@@ -16,13 +16,13 @@ require 'time'
16
16
  module InfluxDB2
17
17
  # The delete predicate request.
18
18
  class DeletePredicateRequest
19
- # RFC3339Nano
19
+ # A timestamp ([RFC3339 date/time format](https://docs.influxdata.com/flux/v0.x/data-types/basic/time/#time-syntax)).
20
20
  attr_accessor :start
21
21
 
22
- # RFC3339Nano
22
+ # A timestamp ([RFC3339 date/time format](https://docs.influxdata.com/flux/v0.x/data-types/basic/time/#time-syntax)).
23
23
  attr_accessor :stop
24
24
 
25
- # InfluxQL-like delete statement
25
+ # An expression in [delete predicate syntax](https://docs.influxdata.com/influxdb/v2.3/reference/syntax/delete-predicate/).
26
26
  attr_accessor :predicate
27
27
 
28
28
  # Attribute mapping from ruby-style variable name to JSON key.
@@ -0,0 +1,66 @@
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
+ # Helper to easy use a logger across the library.
23
+ class LoggingHelper
24
+ # @param [Logger] logger Logger used for logging. Disable logging by set to false.
25
+ def initialize(logger)
26
+ @logger = logger
27
+ end
28
+
29
+ def log(level, message)
30
+ return unless @logger
31
+
32
+ log_level = case level
33
+ when :debug then
34
+ Logger::DEBUG
35
+ when :warn then
36
+ Logger::WARN
37
+ when :error then
38
+ Logger::ERROR
39
+ when :fatal then
40
+ Logger::FATAL
41
+ else
42
+ Logger::INFO
43
+ end
44
+
45
+ @logger.add(log_level) { message }
46
+ end
47
+
48
+ def before_request(uri, method, headers, payload)
49
+ log(:debug, "-> #{method} #{uri}")
50
+ _headers(headers, '->')
51
+ log(:debug, "-> #{payload}") if payload
52
+ end
53
+
54
+ def after_request(http_version, code, message, headers, payload)
55
+ log(:debug, "<- HTTP/#{http_version} #{code} #{message}")
56
+ _headers(headers, '<-')
57
+ log(:debug, "<- #{payload}") if payload
58
+ end
59
+
60
+ def _headers(request, prefix)
61
+ request.each do |k, v|
62
+ log(:debug, "#{prefix} #{k}: #{k.casecmp('authorization').zero? ? '***' : v}")
63
+ end
64
+ end
65
+ end
66
+ end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module InfluxDB2
22
- VERSION = '2.6.0'.freeze
22
+ VERSION = '2.7.0'.freeze
23
23
  end
@@ -116,4 +116,14 @@ class ClientTest < Minitest::Test
116
116
  uri = URI.parse(File.join('http://localhost:8099/', '/api/v2/write'))
117
117
  assert_equal 'http://localhost:8099/api/v2/write', uri.to_s
118
118
  end
119
+
120
+ def test_redacted_auth_header
121
+ output = StringIO.new
122
+ logger = Logger.new output
123
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token', use_ssl: false, logger: logger, debugging: true)
124
+
125
+ client.ping
126
+
127
+ assert_match 'authorization: ***', output.string
128
+ end
119
129
  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: 2.6.0
4
+ version: 2.7.0.pre.5564
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Bednar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-24 00:00:00.000000000 Z
11
+ date: 2022-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -142,6 +142,7 @@ files:
142
142
  - lib/influxdb2/client/ping_api.rb
143
143
  - lib/influxdb2/client/point.rb
144
144
  - lib/influxdb2/client/query_api.rb
145
+ - lib/influxdb2/client/utils/logging_helper.rb
145
146
  - lib/influxdb2/client/version.rb
146
147
  - lib/influxdb2/client/worker.rb
147
148
  - lib/influxdb2/client/write_api.rb
@@ -179,11 +180,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
179
180
  version: 2.2.0
180
181
  required_rubygems_version: !ruby/object:Gem::Requirement
181
182
  requirements:
182
- - - ">="
183
+ - - ">"
183
184
  - !ruby/object:Gem::Version
184
- version: '0'
185
+ version: 1.3.1
185
186
  requirements: []
186
- rubygems_version: 3.0.3.1
187
+ rubygems_version: 3.3.11
187
188
  signing_key:
188
189
  specification_version: 4
189
190
  summary: Ruby library for InfluxDB 2.