influxdb-client 1.7.0 → 1.8.0.pre.1289
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +3 -6
- data/CHANGELOG.md +12 -0
- data/README.md +44 -13
- data/bin/influxdb-onboarding.sh +2 -2
- data/bin/influxdb-restart.sh +3 -2
- data/lib/influxdb2/client/client.rb +5 -4
- data/lib/influxdb2/client/point.rb +1 -1
- data/lib/influxdb2/client/version.rb +1 -1
- data/lib/influxdb2/client/worker.rb +2 -2
- data/lib/influxdb2/client/write_api.rb +56 -3
- data/test/influxdb/client_test.rb +10 -10
- data/test/influxdb/delete_api_integration_test.rb +9 -1
- data/test/influxdb/delete_api_test.rb +15 -15
- data/test/influxdb/query_api_integration_test.rb +1 -1
- data/test/influxdb/query_api_stream_test.rb +1 -1
- data/test/influxdb/query_api_test.rb +7 -7
- data/test/influxdb/write_api_batching_test.rb +157 -108
- data/test/influxdb/write_api_integration_test.rb +2 -2
- data/test/influxdb/write_api_test.rb +135 -38
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a455a34d672abc44886ea962bda79e859e60456a3861576b3f342d9ca5feaa6c
|
4
|
+
data.tar.gz: 7528d2af2482bb4f08f494de9aa2bfd6321df632a8f6cc73bce60fd9f55f6e82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fe3874a990d419a02d907298287219e0b89aa7c54d57477e0d9617fae6124560ac459582325342416f3a7a0579daf961c3768e8b19ccc575bdc08e062c8ed97
|
7
|
+
data.tar.gz: f198f24814f717406ce58435554c751b697b66e389d7218d9b63b1c7dc457e4f542bb5320e228e4af86183bcad0a008c16a2d8b18f589e9727a3bc5b2315b150
|
data/.circleci/config.yml
CHANGED
@@ -78,10 +78,12 @@ jobs:
|
|
78
78
|
default: &default-ruby-image "circleci/ruby:2.6-stretch"
|
79
79
|
influxdb-image:
|
80
80
|
type: string
|
81
|
-
default: &default-influxdb-image "influxdb:2.0.0-
|
81
|
+
default: &default-influxdb-image "influxdb:2.0.0-rc"
|
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
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
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
|
+
1. [#53](https://github.com/influxdata/influxdb-client-ruby/pull/53): Default strategy for batching worker is best-effort
|
6
|
+
|
7
|
+
### API
|
8
|
+
1. [#50](https://github.com/influxdata/influxdb-client-ruby/pull/50): Default port changed from 9999 -> 8086
|
9
|
+
|
10
|
+
### Bug Fixes
|
11
|
+
1. [#52](https://github.com/influxdata/influxdb-client-ruby/pull/52): Fixed aborting of background threads
|
12
|
+
|
1
13
|
## 1.7.0 [2020-08-14]
|
2
14
|
|
3
15
|
### Features
|
data/README.md
CHANGED
@@ -33,7 +33,7 @@ gem install influxdb-client -v 1.7.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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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)
|
@@ -128,12 +128,13 @@ 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,
|
134
135
|
max_retries: 3, max_retry_delay: 15_000,
|
135
136
|
exponential_base: 2)
|
136
|
-
client = InfluxDB2::Client.new('http://localhost:
|
137
|
+
client = InfluxDB2::Client.new('http://localhost:8086',
|
137
138
|
'my-token',
|
138
139
|
bucket: 'my-bucket',
|
139
140
|
org: 'my-org',
|
@@ -148,7 +149,7 @@ write_api.write(data: 'h2o,location=west value=33i 15')
|
|
148
149
|
|
149
150
|
Configure default time precision:
|
150
151
|
```ruby
|
151
|
-
client = InfluxDB2::Client.new('https://localhost:
|
152
|
+
client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
|
152
153
|
bucket: 'my-bucket',
|
153
154
|
org: 'my-org',
|
154
155
|
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
@@ -156,7 +157,7 @@ client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
|
156
157
|
|
157
158
|
Configure precision per write:
|
158
159
|
```ruby
|
159
|
-
client = InfluxDB2::Client.new('https://localhost:
|
160
|
+
client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
|
160
161
|
bucket: 'my-bucket',
|
161
162
|
org: 'my-org')
|
162
163
|
|
@@ -173,7 +174,7 @@ Allowed values for precision are:
|
|
173
174
|
|
174
175
|
Default `bucket` and `organization` destination are configured via `InfluxDB::Client`:
|
175
176
|
```ruby
|
176
|
-
client = InfluxDB2::Client.new('https://localhost:
|
177
|
+
client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
|
177
178
|
bucket: 'my-bucket',
|
178
179
|
org: 'my-org')
|
179
180
|
```
|
@@ -181,7 +182,7 @@ client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
|
181
182
|
but there is also possibility to override configuration per write:
|
182
183
|
|
183
184
|
```ruby
|
184
|
-
client = InfluxDB2::Client.new('https://localhost:
|
185
|
+
client = InfluxDB2::Client.new('https://localhost:8086', 'my-token')
|
185
186
|
|
186
187
|
write_api = client.create_write_api
|
187
188
|
write_api.write(data: 'h2o,location=west value=33i 15', bucket: 'production-data', org: 'customer-1')
|
@@ -197,7 +198,7 @@ The data could be written as:
|
|
197
198
|
1. `Array` of above items
|
198
199
|
|
199
200
|
```ruby
|
200
|
-
client = InfluxDB2::Client.new('https://localhost:
|
201
|
+
client = InfluxDB2::Client.new('https://localhost:8086', 'my-token',
|
201
202
|
bucket: 'my-bucket',
|
202
203
|
org: 'my-org',
|
203
204
|
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
@@ -214,12 +215,42 @@ write_api = client.create_write_api
|
|
214
215
|
write_api.write(data: ['h2o,location=west value=33i 15', point, hash])
|
215
216
|
```
|
216
217
|
|
218
|
+
#### Default Tags
|
219
|
+
|
220
|
+
Sometimes is useful to store same information in every measurement e.g. `hostname`, `location`, `customer`.
|
221
|
+
The client is able to use static value, app settings or env variable as a tag value.
|
222
|
+
|
223
|
+
The expressions:
|
224
|
+
- `California Miner` - static value
|
225
|
+
- `${env.hostname}` - environment property
|
226
|
+
|
227
|
+
##### Via API
|
228
|
+
|
229
|
+
```ruby
|
230
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
231
|
+
bucket: 'my-bucket',
|
232
|
+
org: 'my-org',
|
233
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
234
|
+
use_ssl: false,
|
235
|
+
tags: { id: '132-987-655' })
|
236
|
+
|
237
|
+
point_settings = InfluxDB2::PointSettings.new(default_tags: { customer: 'California Miner' })
|
238
|
+
point_settings.add_default_tag('data_center', '${env.data_center}')
|
239
|
+
|
240
|
+
write_api = client.create_write_api(write_options: InfluxDB2::SYNCHRONOUS,
|
241
|
+
point_settings: point_settings)
|
242
|
+
|
243
|
+
write_api.write(data: InfluxDB2::Point.new(name: 'h2o')
|
244
|
+
.add_tag('location', 'europe')
|
245
|
+
.add_field('level', 2))
|
246
|
+
```
|
247
|
+
|
217
248
|
### Delete data
|
218
249
|
|
219
250
|
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.
|
220
251
|
|
221
252
|
```ruby
|
222
|
-
client = InfluxDB2::Client.new('http://localhost:
|
253
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
223
254
|
bucket: 'my-bucket',
|
224
255
|
org: 'my-org',
|
225
256
|
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
data/bin/influxdb-onboarding.sh
CHANGED
@@ -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:
|
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:
|
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",
|
data/bin/influxdb-restart.sh
CHANGED
@@ -27,7 +27,7 @@ DEFAULT_DOCKER_REGISTRY="quay.io/influxdb/"
|
|
27
27
|
DOCKER_REGISTRY="${DOCKER_REGISTRY:-$DEFAULT_DOCKER_REGISTRY}"
|
28
28
|
|
29
29
|
DEFAULT_INFLUXDB_V2_REPOSITORY="influxdb"
|
30
|
-
DEFAULT_INFLUXDB_V2_VERSION="2.0.0-
|
30
|
+
DEFAULT_INFLUXDB_V2_VERSION="2.0.0-rc"
|
31
31
|
INFLUXDB_V2_REPOSITORY="${INFLUXDB_V2_REPOSITORY:-$DEFAULT_INFLUXDB_V2_REPOSITORY}"
|
32
32
|
INFLUXDB_V2_VERSION="${INFLUXDB_V2_VERSION:-$DEFAULT_INFLUXDB_V2_VERSION}"
|
33
33
|
INFLUXDB_V2_IMAGE=${DOCKER_REGISTRY}${INFLUXDB_V2_REPOSITORY}:${INFLUXDB_V2_VERSION}
|
@@ -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
|
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:
|
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:
|
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
|
@@ -31,14 +31,13 @@ module InfluxDB2
|
|
31
31
|
|
32
32
|
@queue_event.push(true)
|
33
33
|
|
34
|
-
Thread.abort_on_exception = true
|
35
|
-
|
36
34
|
@thread_flush = Thread.new do
|
37
35
|
until api_client.closed
|
38
36
|
sleep @write_options.flush_interval.to_f / 1_000
|
39
37
|
_check_background_queue
|
40
38
|
end
|
41
39
|
end
|
40
|
+
@thread_flush.abort_on_exception = @write_options.batch_abort_on_exception
|
42
41
|
|
43
42
|
@thread_size = Thread.new do
|
44
43
|
until api_client.closed
|
@@ -46,6 +45,7 @@ module InfluxDB2
|
|
46
45
|
sleep 0.01
|
47
46
|
end
|
48
47
|
end
|
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
|
@@ -72,6 +75,30 @@ module InfluxDB2
|
|
72
75
|
|
73
76
|
SYNCHRONOUS = InfluxDB2::WriteOptions.new(write_type: WriteType::SYNCHRONOUS)
|
74
77
|
|
78
|
+
# Settings to store default tags.
|
79
|
+
#
|
80
|
+
class PointSettings
|
81
|
+
# @param [Hash] default_tags Default tags which will be added to each point written by api.
|
82
|
+
def initialize(default_tags: nil)
|
83
|
+
@default_tags = default_tags || {}
|
84
|
+
end
|
85
|
+
attr_reader :default_tags
|
86
|
+
|
87
|
+
def add_default_tag(key, expression)
|
88
|
+
@default_tags[key] = expression
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.get_value(value)
|
92
|
+
if value.start_with?('${env.')
|
93
|
+
ENV[value[6..-2]]
|
94
|
+
else
|
95
|
+
value
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
DEFAULT_POINT_SETTINGS = InfluxDB2::PointSettings.new
|
101
|
+
|
75
102
|
# Precision constants.
|
76
103
|
#
|
77
104
|
class WritePrecision
|
@@ -93,10 +120,13 @@ module InfluxDB2
|
|
93
120
|
class WriteApi < DefaultApi
|
94
121
|
# @param [Hash] options The options to be used by the client.
|
95
122
|
# @param [WriteOptions] write_options Write api configuration.
|
96
|
-
|
123
|
+
# @param [PointSettings] point_settings Default tags configuration
|
124
|
+
def initialize(options:, write_options: SYNCHRONOUS, point_settings: InfluxDB2::PointSettings.new)
|
97
125
|
super(options: options)
|
98
126
|
@write_options = write_options
|
127
|
+
@point_settings = point_settings
|
99
128
|
@closed = false
|
129
|
+
@options[:tags].each { |key, value| point_settings.add_default_tag(key, value) } if @options.key?(:tags)
|
100
130
|
end
|
101
131
|
attr_reader :closed
|
102
132
|
|
@@ -140,6 +170,8 @@ module InfluxDB2
|
|
140
170
|
_check('bucket', bucket_param)
|
141
171
|
_check('org', org_param)
|
142
172
|
|
173
|
+
_add_default_tags(data)
|
174
|
+
|
143
175
|
payload = _generate_payload(data, bucket: bucket_param, org: org_param, precision: precision_param)
|
144
176
|
return nil if payload.nil?
|
145
177
|
|
@@ -223,6 +255,27 @@ module InfluxDB2
|
|
223
255
|
end
|
224
256
|
end
|
225
257
|
|
258
|
+
def _add_default_tags(data)
|
259
|
+
default_tags = @point_settings.default_tags
|
260
|
+
|
261
|
+
default_tags.each do |key, expression|
|
262
|
+
value = PointSettings.get_value(expression)
|
263
|
+
_add_default_tag(data, key, value)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
def _add_default_tag(data, key, value)
|
268
|
+
if data.is_a?(Point)
|
269
|
+
data.add_tag(key, value)
|
270
|
+
elsif data.is_a?(Hash)
|
271
|
+
data[:tags][key] = value
|
272
|
+
elsif data.respond_to? :map
|
273
|
+
data.map do |item|
|
274
|
+
_add_default_tag(item, key, value)
|
275
|
+
end.reject(&:nil?)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
226
279
|
def _generate_payload(data, precision: nil, bucket: nil, org: nil)
|
227
280
|
if data.nil?
|
228
281
|
nil
|
@@ -30,41 +30,41 @@ class ClientTest < Minitest::Test
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_client_new
|
33
|
-
refute_nil InfluxDB2::Client.new('http://localhost:
|
33
|
+
refute_nil InfluxDB2::Client.new('http://localhost:8086', 'my-token')
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_client_hash
|
37
|
-
client1 = InfluxDB2::Client.new('http://localhost:
|
38
|
-
client2 = InfluxDB2::Client.new('http://localhost:
|
37
|
+
client1 = InfluxDB2::Client.new('http://localhost:8086', 'my-token')
|
38
|
+
client2 = InfluxDB2::Client.new('http://localhost:8086', 'my-token-diff')
|
39
39
|
|
40
40
|
refute_equal client1.hash, client2.hash
|
41
41
|
assert_equal client1.hash, client1.hash
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_client_eq
|
45
|
-
client1 = InfluxDB2::Client.new('http://localhost:
|
46
|
-
client2 = InfluxDB2::Client.new('http://localhost:
|
45
|
+
client1 = InfluxDB2::Client.new('http://localhost:8086', 'my-token')
|
46
|
+
client2 = InfluxDB2::Client.new('http://localhost:8086', 'my-token-diff')
|
47
47
|
|
48
48
|
refute_equal client1, client2
|
49
49
|
assert_equal client1, client1
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_client_options
|
53
|
-
client = InfluxDB2::Client.new('http://localhost:
|
53
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token')
|
54
54
|
|
55
|
-
assert_equal 'http://localhost:
|
55
|
+
assert_equal 'http://localhost:8086', client.options[:url]
|
56
56
|
assert_equal 'my-token', client.options[:token]
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_close
|
60
|
-
client = InfluxDB2::Client.new('http://localhost:
|
60
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token')
|
61
61
|
|
62
62
|
assert_equal true, client.close!
|
63
63
|
assert_equal true, client.close!
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_get_write_api
|
67
|
-
client = InfluxDB2::Client.new('http://localhost:
|
67
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token')
|
68
68
|
|
69
69
|
write_api = client.create_write_api
|
70
70
|
|
@@ -73,7 +73,7 @@ class ClientTest < Minitest::Test
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def test_health
|
76
|
-
client = InfluxDB2::Client.new('http://localhost:
|
76
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token', use_ssl: false)
|
77
77
|
|
78
78
|
health = client.health
|
79
79
|
assert_equal 'ready for queries and writes', health.message
|