influxdb-client 2.6.0.pre.5155 → 2.7.0.pre.5385

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: 7c3cb5622439e906e3bbd8cf17ff632bc37926bb7284dbe60f9c89a2ac42cd1c
4
- data.tar.gz: db66657282c2796fb546c92522c5d3de4ef4feb07b280fafdff0894d26cb4114
3
+ metadata.gz: 59638b2257c9c4118413af42d3643a8a0c7576e52d22c60ad729a2defd0c30a4
4
+ data.tar.gz: d0e6eba3994028a0068cc3aaf3fb8b0e904f48635122e3af0d63bb7e8dfefe5d
5
5
  SHA512:
6
- metadata.gz: 87abbc007c3aab02846d74a8885dda62f002f38cc4511ab7d470670650c949069c555df8781a7a55ce8468592f942ccf5cb3ef66d447a2f96d730aaebf7e4272
7
- data.tar.gz: b53af4d1e7536218c23b658b9b899594eb357044c352f1732c70ced0357d87c10cb71592488716a773c1a8fc7d3018f2530872dec412272ff94ffa3344c9e54a
6
+ metadata.gz: b20bba93481704ec376c5204e2d4c9766b6a2a4252b09e341fe9fa545de88d5382e40a8c5e4d0072bf32acd72162c0685a43774ba6d3780ccdac6b4aa808d290
7
+ data.tar.gz: a92b3d2aac9f19d8cfb29716d0b20c64f796deeec1f44763baa906cfcd886d6e16a709c0f4ab8698cd97f489407dfd11a21ed7327e1e5cffb2a14187861e7137
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
- ## 2.6.0 [unreleased]
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
+ ## 2.6.0 [2022-06-24]
2
7
 
3
8
  ### Bug Fixes
4
9
  1. [#105](https://github.com/influxdata/influxdb-client-ruby/pull/105): Add missing require for `PatchBucketRequest` model
data/README.md CHANGED
@@ -64,13 +64,13 @@ The client can be installed manually or with bundler.
64
64
  To install the client gem manually:
65
65
 
66
66
  ```
67
- gem install influxdb-client -v 2.5.0
67
+ gem install influxdb-client -v 2.6.0
68
68
  ```
69
69
 
70
70
  For management API:
71
71
 
72
72
  ```
73
- gem install influxdb-client-apis -v 2.5.0
73
+ gem install influxdb-client-apis -v 2.6.0
74
74
  ```
75
75
 
76
76
  ## Usage
@@ -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.pre.5155
4
+ version: 2.7.0.pre.5385
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-05-25 00:00:00.000000000 Z
11
+ date: 2022-07-15 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