influxdb-client 1.6.0 → 1.8.0.pre.1218

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: 20cf81cf2a456afa228493a541328eec06036b33f89f1c55097a8c0fa49369c9
4
- data.tar.gz: c810d0079ec382f83f3d8907be4510b48592646f62fc483c791f88494e3b2a3e
3
+ metadata.gz: 83e17817aa71b99fc2c00c9810031c7a1acbf86e3560b91e1ad277f0213ddd66
4
+ data.tar.gz: d58024ec56f0766126c06b829a49dce98ff83f85dda23990f0cd05d9f9917fc1
5
5
  SHA512:
6
- metadata.gz: 0f44b8975945893946b73abd129ec6f2c3da49bb3d8dc45511de53d9b3d7a022fde44396f02da682d404c0778070a703d4c4fdab1e07187763a080d3850dc7d1
7
- data.tar.gz: 03d1c1463657348726eb82b8aaa061fe0b96be2a2d3baae6e90717bf090923a6e1823cbe70d0017c0023bf785379088077f6ba2eaf2866dbcd8a2e33f89da275
6
+ metadata.gz: 40fede72bad180624c088af3ee92f005ff2dfc357e330012f17b06284b939f8017c018b79bb36e3112a646361b57f492c8d7e45bb402b657ece43796657b7fe4
7
+ data.tar.gz: a1636a76698949e303c749fdcc2936faa31928d140baac04d0449fc1248afbf9c1b4fa2ff427dadd20932ffed512311abad7d682328caf96e39a68f19c096947
@@ -82,6 +82,8 @@ jobs:
82
82
  docker:
83
83
  - image: << parameters.ruby-image >>
84
84
  - image: &influx-image quay.io/influxdb/<< parameters.influxdb-image >>
85
+ environment:
86
+ INFLUXD_HTTP_BIND_ADDRESS: :8086
85
87
  steps:
86
88
  - prepare
87
89
  - test:
@@ -89,13 +91,8 @@ jobs:
89
91
  - storing-test-results
90
92
 
91
93
  deploy-preview:
92
- parameters:
93
- influxdb-image:
94
- type: string
95
- default: *default-influxdb-image
96
94
  docker:
97
95
  - image: *default-ruby-image
98
- - image: *influx-image
99
96
  steps:
100
97
  - run:
101
98
  name: Early return if this build is from a forked repository
@@ -0,0 +1,34 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ ---
5
+
6
+ <!--
7
+
8
+ Thank you for reporting a bug.
9
+
10
+ * Please add a :+1: or comment on a similar existing bug report instead of opening a new one.
11
+ * https://github.com/influxdata/influxdb-client-ruby/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+is%3Aclosed+sort%3Aupdated-desc+label%3Abug+
12
+ * Please check whether the bug can be reproduced with the latest release.
13
+ * The fastest way to fix a bug is to open a Pull Request.
14
+ * https://github.com/influxdata/influxdb-client-ruby/pulls
15
+
16
+ -->
17
+
18
+ __Steps to reproduce:__
19
+ List the minimal actions needed to reproduce the behavior.
20
+
21
+ 1. ...
22
+ 2. ...
23
+ 3. ...
24
+
25
+ __Expected behavior:__
26
+ Describe what you expected to happen.
27
+
28
+ __Actual behavior:__
29
+ Describe What actually happened.
30
+
31
+ __Specifications:__
32
+ - Client Version:
33
+ - InfluxDB Version:
34
+ - Platform:
@@ -0,0 +1,28 @@
1
+ ---
2
+ name: Feature request
3
+ about: Opening a feature request kicks off a discussion
4
+ ---
5
+
6
+ <!--
7
+
8
+ Thank you for suggesting an idea to improve this client.
9
+
10
+ * Please add a :+1: or comment on a similar existing feature request instead of opening a new one.
11
+ * https://github.com/influxdata/influxdb-client-ruby/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+is%3Aclosed+sort%3Aupdated-desc+label%3A%22enhancement%22+
12
+
13
+ -->
14
+
15
+ __Proposal:__
16
+ Short summary of the feature.
17
+
18
+ __Current behavior:__
19
+ Describe what currently happens.
20
+
21
+ __Desired behavior:__
22
+ Describe what you want.
23
+
24
+ __Alternatives considered:__
25
+ Describe other solutions or features you considered.
26
+
27
+ __Use case:__
28
+ Why is this important (helps with prioritizing requests)?
@@ -1,8 +1,16 @@
1
1
  Closes #
2
2
 
3
+ ## Proposed Changes
4
+
3
5
  _Briefly describe your proposed changes:_
4
6
 
7
+ ## Checklist
8
+
9
+ <!-- Checkboxes below this note can be erased if not applicable to your Pull Request. -->
10
+
5
11
  - [ ] CHANGELOG.md updated
6
12
  - [ ] Rebased/mergeable
7
- - [ ] Tests pass
8
- - [ ] Sign [CLA](https://influxdata.com/community/cla/) (if not already signed)
13
+ - [ ] A test has been added if appropriate
14
+ - [ ] `rake test` completes successfully
15
+ - [ ] Commit messages are in [semantic format](https://seesparkbox.com/foundry/semantic_commit_messages)
16
+ - [ ] Sign [CLA](https://influxdata.com/community/cla/) (if not already signed)
@@ -0,0 +1,3 @@
1
+ # docs: https://github.com/probot/semantic-pull-requests#configuration
2
+ # Always validate the PR title AND all the commits
3
+ titleAndCommits: true
@@ -39,3 +39,5 @@ Metrics/CyclomaticComplexity:
39
39
  Max: 15
40
40
  Metrics/PerceivedComplexity:
41
41
  Max: 15
42
+ Metrics/ParameterLists:
43
+ Max: 10
@@ -1,3 +1,16 @@
1
+ ## 1.8.0 [unreleased]
2
+
3
+ ### Features
4
+ 1. [#36](https://github.com/influxdata/influxdb-client-ruby/issues/36): Added support for default tags
5
+
6
+ ### API
7
+ 1. [#50](https://github.com/influxdata/influxdb-client-ruby/pull/50): Default port changed from 9999 -> 8086
8
+
9
+ ## 1.7.0 [2020-08-14]
10
+
11
+ ### Features
12
+ 1. [#47](https://github.com/influxdata/influxdb-client-ruby/pull/47): Added max_retries, max_retry_delay and exponential_base to WriteApi
13
+
1
14
  ## 1.6.0 [2020-07-17]
2
15
 
3
16
  ### Bug Fixes
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.6.0
26
+ gem install influxdb-client -v 1.7.0
27
27
  ```
28
28
 
29
29
  ## Usage
@@ -33,7 +33,7 @@ gem install influxdb-client -v 1.6.0
33
33
  Use **InfluxDB::Client** to create a client connected to a running InfluxDB 2 instance.
34
34
 
35
35
  ```ruby
36
- client = InfluxDB2::Client.new('https://localhost:9999', 'my-token')
36
+ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token')
37
37
  ```
38
38
 
39
39
  #### Client Options
@@ -50,7 +50,7 @@ client = InfluxDB2::Client.new('https://localhost:9999', 'my-token')
50
50
  | use_ssl | Turn on/off SSL for HTTP communication | bool | true |
51
51
 
52
52
  ```ruby
53
- client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
53
+ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
54
54
  bucket: 'my-bucket',
55
55
  org: 'my-org',
56
56
  precision: InfluxDB2::WritePrecision::NANOSECOND)
@@ -68,7 +68,7 @@ The result retrieved by [QueryApi](https://github.com/influxdata/influxdb-client
68
68
 
69
69
  Synchronously executes the Flux query and return result as unprocessed String
70
70
  ```ruby
71
- client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
71
+ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
72
72
  bucket: 'my-bucket',
73
73
  org: 'my-org')
74
74
 
@@ -78,7 +78,7 @@ result = query_api.query_raw(query: 'from(bucket:"' + bucket + '") |> range(star
78
78
  #### Synchronous query
79
79
  Synchronously executes the Flux query and return result as a Array of [FluxTables](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/flux_table.rb)
80
80
  ```ruby
81
- client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
81
+ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
82
82
  bucket: 'my-bucket',
83
83
  org: 'my-org')
84
84
 
@@ -89,7 +89,7 @@ result = query_api.query(query: 'from(bucket:"' + bucket + '") |> range(start: 1
89
89
  #### Query stream
90
90
  Synchronously executes the Flux query and return stream of [FluxRecord](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/flux_table.rb)
91
91
  ```ruby
92
- client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
92
+ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
93
93
  bucket: 'my-bucket',
94
94
  org: 'my-org')
95
95
 
@@ -107,7 +107,7 @@ end
107
107
  The [WriteApi](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/write_api.rb) supports synchronous and batching writes into InfluxDB 2.0. In default api uses synchronous write. To enable batching you can use WriteOption.
108
108
 
109
109
  ```ruby
110
- client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
110
+ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
111
111
  bucket: 'my-bucket',
112
112
  org: 'my-org',
113
113
  precision: InfluxDB2::WritePrecision::NANOSECOND)
@@ -123,13 +123,17 @@ The writes are processed in batches which are configurable by `WriteOptions`:
123
123
  | --- | --- | --- |
124
124
  | batchSize | the number of data point to collect in batch | 1000 |
125
125
  | flush_interval | the number of milliseconds before the batch is written | 1000 |
126
- | 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. | 1000 |
126
+ | 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. | 5000 |
127
127
  | jitter_interval | the number of milliseconds to increase the batch flush interval by a random amount | 0 |
128
-
128
+ | max_retries | the number of max retries when write fails | 5 |
129
+ | max_retry_delay | maximum delay when retrying write in milliseconds | 180000 |
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 |
129
131
  ```ruby
130
132
  write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
131
- batch_size: 10, flush_interval: 5_000)
132
- client = InfluxDB2::Client.new('http://localhost:9999',
133
+ batch_size: 10, flush_interval: 5_000,
134
+ max_retries: 3, max_retry_delay: 15_000,
135
+ exponential_base: 2)
136
+ client = InfluxDB2::Client.new('http://localhost:8086',
133
137
  'my-token',
134
138
  bucket: 'my-bucket',
135
139
  org: 'my-org',
@@ -144,7 +148,7 @@ write_api.write(data: 'h2o,location=west value=33i 15')
144
148
 
145
149
  Configure default time precision:
146
150
  ```ruby
147
- client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
151
+ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
148
152
  bucket: 'my-bucket',
149
153
  org: 'my-org',
150
154
  precision: InfluxDB2::WritePrecision::NANOSECOND)
@@ -152,7 +156,7 @@ client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
152
156
 
153
157
  Configure precision per write:
154
158
  ```ruby
155
- client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
159
+ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
156
160
  bucket: 'my-bucket',
157
161
  org: 'my-org')
158
162
 
@@ -169,7 +173,7 @@ Allowed values for precision are:
169
173
 
170
174
  Default `bucket` and `organization` destination are configured via `InfluxDB::Client`:
171
175
  ```ruby
172
- client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
176
+ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
173
177
  bucket: 'my-bucket',
174
178
  org: 'my-org')
175
179
  ```
@@ -177,7 +181,7 @@ client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
177
181
  but there is also possibility to override configuration per write:
178
182
 
179
183
  ```ruby
180
- client = InfluxDB2::Client.new('https://localhost:9999', 'my-token')
184
+ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token')
181
185
 
182
186
  write_api = client.create_write_api
183
187
  write_api.write(data: 'h2o,location=west value=33i 15', bucket: 'production-data', org: 'customer-1')
@@ -193,7 +197,7 @@ The data could be written as:
193
197
  1. `Array` of above items
194
198
 
195
199
  ```ruby
196
- client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
200
+ client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
197
201
  bucket: 'my-bucket',
198
202
  org: 'my-org',
199
203
  precision: InfluxDB2::WritePrecision::NANOSECOND)
@@ -210,12 +214,42 @@ write_api = client.create_write_api
210
214
  write_api.write(data: ['h2o,location=west value=33i 15', point, hash])
211
215
  ```
212
216
 
217
+ #### Default Tags
218
+
219
+ Sometimes is useful to store same information in every measurement e.g. `hostname`, `location`, `customer`.
220
+ The client is able to use static value, app settings or env variable as a tag value.
221
+
222
+ The expressions:
223
+ - `California Miner` - static value
224
+ - `${env.hostname}` - environment property
225
+
226
+ ##### Via API
227
+
228
+ ```ruby
229
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
230
+ bucket: 'my-bucket',
231
+ org: 'my-org',
232
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
233
+ use_ssl: false,
234
+ tags: { id: '132-987-655' })
235
+
236
+ point_settings = InfluxDB2::PointSettings.new(default_tags: { customer: 'California Miner' })
237
+ point_settings.add_default_tag('data_center', '${env.data_center}')
238
+
239
+ write_api = client.create_write_api(write_options: InfluxDB2::SYNCHRONOUS,
240
+ point_settings: point_settings)
241
+
242
+ write_api.write(data: InfluxDB2::Point.new(name: 'h2o')
243
+ .add_tag('location', 'europe')
244
+ .add_field('level', 2))
245
+ ```
246
+
213
247
  ### Delete data
214
248
 
215
249
  The [DeleteApi](https://github.com/influxdata/influxdb-client-ruby/blob/master/lib/influxdb2/client/delete_api.rb) supports deletes [points](https://v2.docs.influxdata.com/v2.0/reference/glossary/#point) from an InfluxDB bucket.
216
250
 
217
251
  ```ruby
218
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
252
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
219
253
  bucket: 'my-bucket',
220
254
  org: 'my-org',
221
255
  precision: InfluxDB2::WritePrecision::NANOSECOND)
@@ -24,12 +24,12 @@
24
24
  set -e
25
25
 
26
26
  echo "Wait to start InfluxDB 2.0"
27
- wget -S --spider --tries=20 --retry-connrefused --waitretry=5 http://localhost:9999/metrics
27
+ wget -S --spider --tries=20 --retry-connrefused --waitretry=5 http://localhost:8086/metrics
28
28
 
29
29
  echo
30
30
  echo "Post onBoarding request, to setup initial user (my-user@my-password), org (my-org) and bucketSetup (my-bucket)"
31
31
  echo
32
- curl -i -X POST http://localhost:9999/api/v2/setup -H 'accept: application/json' \
32
+ curl -i -X POST http://localhost:8086/api/v2/setup -H 'accept: application/json' \
33
33
  -d '{
34
34
  "username": "my-user",
35
35
  "password": "my-password",
@@ -49,9 +49,10 @@ echo
49
49
  docker pull "${INFLUXDB_V2_IMAGE}" || true
50
50
  docker run \
51
51
  --detach \
52
+ --env INFLUXD_HTTP_BIND_ADDRESS=:8086 \
52
53
  --name influxdb_v2 \
53
54
  --network influx_network \
54
- --publish 9999:9999 \
55
+ --publish 8086:8086 \
55
56
  "${INFLUXDB_V2_IMAGE}"
56
57
 
57
58
  #
@@ -29,10 +29,10 @@ module InfluxDB2
29
29
  # Instantiate a new InfluxDB client.
30
30
  #
31
31
  # @example Instantiate a client.
32
- # InfluxDBClient::Client.new(url: 'https://localhost:9999', token: 'my-token')
32
+ # InfluxDBClient::Client.new(url: 'https://localhost:8086', token: 'my-token')
33
33
  #
34
34
  # @param [Hash] options The options to be used by the client.
35
- # @param [String] url InfluxDB URL to connect to (ex. https://localhost:9999).
35
+ # @param [String] url InfluxDB URL to connect to (ex. https://localhost:8086).
36
36
  # @param [String] token Access Token used for authenticating/authorizing the InfluxDB request sent by client.
37
37
  #
38
38
  # @option options [String] :bucket the default destination bucket for writes
@@ -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 [Hash] :tags Default tags which will be added to each point written by api.
46
47
  # the body line-protocol
47
48
  def initialize(url, token, options = nil)
48
49
  @auto_closeable = []
@@ -57,8 +58,8 @@ module InfluxDB2
57
58
  # Write time series data into InfluxDB thought WriteApi.
58
59
  #
59
60
  # @return [WriteApi] New instance of WriteApi.
60
- def create_write_api(write_options: InfluxDB2::SYNCHRONOUS)
61
- write_api = WriteApi.new(options: @options, write_options: write_options)
61
+ def create_write_api(write_options: InfluxDB2::SYNCHRONOUS, point_settings: InfluxDB2::DEFAULT_POINT_SETTINGS)
62
+ write_api = WriteApi.new(options: @options, write_options: write_options, point_settings: point_settings)
62
63
  @auto_closeable.push(write_api)
63
64
  write_api
64
65
  end
@@ -83,6 +83,8 @@ module InfluxDB2
83
83
  else
84
84
  raise InfluxError.from_response(response)
85
85
  end
86
+ rescue *InfluxError::HTTP_ERRORS => error
87
+ raise InfluxError.from_error(error)
86
88
  ensure
87
89
  http.finish if http.started?
88
90
  end
@@ -1,19 +1,33 @@
1
1
  module InfluxDB2
2
2
  # InfluxError that is raised during HTTP communication.
3
3
  class InfluxError < StandardError
4
+ HTTP_ERRORS = [
5
+ EOFError,
6
+ Errno::ECONNREFUSED,
7
+ Errno::ECONNRESET,
8
+ Errno::EINVAL,
9
+ Net::HTTPBadResponse,
10
+ Net::HTTPHeaderSyntaxError,
11
+ Net::ProtocolError,
12
+ Timeout::Error
13
+ ].freeze
14
+
4
15
  # HTTP status code
5
16
  attr_reader :code
6
17
  # Reference code unique to the error type
7
18
  attr_reader :reference
8
19
  # The Retry-After header describes when to try the request again.
9
20
  attr_reader :retry_after
21
+ # original error
22
+ attr_reader :original
10
23
 
11
- def initialize(message:, code:, reference:, retry_after:)
24
+ def initialize(original = nil, message:, code:, reference:, retry_after:)
12
25
  super(message)
13
26
 
14
27
  @code = code
15
28
  @reference = reference
16
29
  @retry_after = retry_after
30
+ @original = original
17
31
  end
18
32
 
19
33
  def self.from_response(response)
@@ -27,5 +41,10 @@ module InfluxDB2
27
41
  obj = new(message: message, code: '', reference: '', retry_after: '')
28
42
  obj
29
43
  end
44
+
45
+ def self.from_error(error)
46
+ obj = new(error, message: error.message, code: '', reference: '', retry_after: '')
47
+ obj
48
+ end
30
49
  end
31
50
  end
@@ -138,7 +138,7 @@ module InfluxDB2
138
138
  def _escape_tags
139
139
  return if @tags.nil?
140
140
 
141
- @tags.sort.to_h.map do |k, v|
141
+ @tags.sort_by { |x, _| x.to_s }.to_h.map do |k, v|
142
142
  key = _escape_key(k.to_s)
143
143
  value = _escape_key(v.to_s)
144
144
  if key.empty? || value.empty?
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module InfluxDB2
22
- VERSION = '1.6.0'.freeze
22
+ VERSION = '1.8.0'.freeze
23
23
  end