influxdb-client 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/PULL_REQUEST_TEMPLATE +4 -4
- data/.rubocop.yml +2 -2
- data/CHANGELOG.md +15 -0
- data/README.md +26 -4
- data/bin/generate-sources.sh +1 -8
- data/influxdb-client.gemspec +1 -1
- data/lib/influxdb2/client.rb +1 -0
- data/lib/influxdb2/client/client.rb +7 -0
- data/lib/influxdb2/client/default_api.rb +21 -2
- data/lib/influxdb2/client/delete_api.rb +80 -0
- data/lib/influxdb2/client/flux_csv_parser.rb +7 -2
- data/lib/influxdb2/client/influx_error.rb +7 -3
- data/lib/influxdb2/client/models/delete_predicate_request.rb +215 -0
- data/lib/influxdb2/client/query_api.rb +1 -1
- data/lib/influxdb2/client/version.rb +1 -1
- data/lib/influxdb2/client/worker.rb +39 -13
- data/lib/influxdb2/client/write_api.rb +32 -8
- data/test/influxdb/delete_api_integration_test.rb +100 -0
- data/test/influxdb/delete_api_test.rb +121 -0
- data/test/influxdb/flux_csv_parser_test.rb +75 -0
- data/test/influxdb/query_api_integration_test.rb +1 -1
- data/test/influxdb/query_api_test.rb +21 -0
- data/test/influxdb/write_api_batching_test.rb +140 -1
- data/test/influxdb/write_api_integration_test.rb +2 -1
- data/test/influxdb/write_api_test.rb +40 -0
- metadata +12 -6
@@ -33,7 +33,7 @@ class QueryApiIntegrationTest < MiniTest::Test
|
|
33
33
|
|
34
34
|
def test_query
|
35
35
|
now = Time.now.utc
|
36
|
-
measurement = 'h2o_query_' + now.to_i.to_s
|
36
|
+
measurement = 'h2o_query_' + now.to_i.to_s + now.nsec.to_s
|
37
37
|
|
38
38
|
@client.create_write_api.write(data: InfluxDB2::Point.new(name: measurement)
|
39
39
|
.add_tag('location', 'europe')
|
@@ -72,4 +72,25 @@ class QueryApiTest < MiniTest::Test
|
|
72
72
|
assert_equal 10, record1.value
|
73
73
|
assert_equal 'free', record1.field
|
74
74
|
end
|
75
|
+
|
76
|
+
def test_headers
|
77
|
+
stub_request(:post, 'http://localhost:9999/api/v2/query?org=my-org')
|
78
|
+
.to_return(body: SUCCESS_DATA)
|
79
|
+
|
80
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
81
|
+
bucket: 'my-bucket',
|
82
|
+
org: 'my-org',
|
83
|
+
use_ssl: false)
|
84
|
+
|
85
|
+
client.create_query_api
|
86
|
+
.query(query: 'from(bucket:"my-bucket") |> range(start: 1970-01-01T00:00:00.000000001Z) |> last()')
|
87
|
+
|
88
|
+
headers = {
|
89
|
+
'Authorization' => 'Token my-token',
|
90
|
+
'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}",
|
91
|
+
'Content-Type' => 'application/json'
|
92
|
+
}
|
93
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/query?org=my-org',
|
94
|
+
times: 1, headers: headers)
|
95
|
+
end
|
75
96
|
end
|
@@ -25,7 +25,7 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
25
25
|
WebMock.disable_net_connect!
|
26
26
|
|
27
27
|
@write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
28
|
-
batch_size: 2, flush_interval: 5_000)
|
28
|
+
batch_size: 2, flush_interval: 5_000, retry_interval: 2_000)
|
29
29
|
@client = InfluxDB2::Client.new('http://localhost:9999',
|
30
30
|
'my-token',
|
31
31
|
bucket: 'my-bucket',
|
@@ -44,6 +44,29 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
44
44
|
WebMock.reset!
|
45
45
|
end
|
46
46
|
|
47
|
+
def test_batch_configuration
|
48
|
+
error = assert_raises ArgumentError do
|
49
|
+
InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING, batch_size: 0)
|
50
|
+
end
|
51
|
+
assert_equal "The 'batch_size' should be positive or zero, but is: 0", error.message
|
52
|
+
|
53
|
+
error = assert_raises ArgumentError do
|
54
|
+
InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING, flush_interval: -10)
|
55
|
+
end
|
56
|
+
assert_equal "The 'flush_interval' should be positive or zero, but is: -10", error.message
|
57
|
+
|
58
|
+
error = assert_raises ArgumentError do
|
59
|
+
InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING, retry_interval: 0)
|
60
|
+
end
|
61
|
+
assert_equal "The 'retry_interval' should be positive or zero, but is: 0", error.message
|
62
|
+
|
63
|
+
InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING, jitter_interval: 0)
|
64
|
+
error = assert_raises ArgumentError do
|
65
|
+
InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING, jitter_interval: -10)
|
66
|
+
end
|
67
|
+
assert_equal "The 'jitter_interval' should be positive number, but is: -10", error.message
|
68
|
+
end
|
69
|
+
|
47
70
|
def test_batch_size
|
48
71
|
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
49
72
|
.to_return(status: 204)
|
@@ -136,6 +159,19 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
136
159
|
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
137
160
|
.to_return(status: 204)
|
138
161
|
|
162
|
+
@client.close!
|
163
|
+
|
164
|
+
@write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
165
|
+
batch_size: 10, flush_interval: 5_000)
|
166
|
+
@client = InfluxDB2::Client.new('http://localhost:9999',
|
167
|
+
'my-token',
|
168
|
+
bucket: 'my-bucket',
|
169
|
+
org: 'my-org',
|
170
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
171
|
+
use_ssl: false)
|
172
|
+
|
173
|
+
@write_client = @client.create_write_api(write_options: @write_options)
|
174
|
+
|
139
175
|
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=1.0 1')
|
140
176
|
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=2.0 2')
|
141
177
|
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=3.0 3')
|
@@ -150,4 +186,107 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
150
186
|
"h2o_feet,location=coyote_creek level\\ water_level=2.0 2\n" \
|
151
187
|
'h2o_feet,location=coyote_creek level\\ water_level=3.0 3')
|
152
188
|
end
|
189
|
+
|
190
|
+
def test_retry_interval_by_config
|
191
|
+
error_body = '{"code":"temporarily unavailable","message":"Token is temporarily over quota. '\
|
192
|
+
'The Retry-After header describes when to try the write again."}'
|
193
|
+
|
194
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
195
|
+
.to_return(status: 429, headers: { 'X-Platform-Error-Code' => 'temporarily unavailable' }, body: error_body).then
|
196
|
+
.to_return(status: 204)
|
197
|
+
|
198
|
+
request = "h2o_feet,location=coyote_creek water_level=1.0 1\n" \
|
199
|
+
'h2o_feet,location=coyote_creek water_level=2.0 2'
|
200
|
+
|
201
|
+
@write_client.write(data: ['h2o_feet,location=coyote_creek water_level=1.0 1',
|
202
|
+
'h2o_feet,location=coyote_creek water_level=2.0 2'])
|
203
|
+
|
204
|
+
sleep(0.5)
|
205
|
+
|
206
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
207
|
+
times: 1, body: request)
|
208
|
+
|
209
|
+
sleep(1)
|
210
|
+
|
211
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
212
|
+
times: 1, body: request)
|
213
|
+
|
214
|
+
sleep(1)
|
215
|
+
|
216
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
217
|
+
times: 2, body: request)
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_retry_interval_by_header
|
221
|
+
error_body = '{"code":"temporarily unavailable","message":"Server is temporarily unavailable to accept writes. '\
|
222
|
+
'The Retry-After header describes when to try the write again."}'
|
223
|
+
|
224
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
225
|
+
.to_return(status: 503, headers: { 'X-Platform-Error-Code' => 'temporarily unavailable', 'Retry-After' => '3' },
|
226
|
+
body: error_body).then
|
227
|
+
.to_return(status: 204)
|
228
|
+
|
229
|
+
request = "h2o_feet,location=coyote_creek water_level=1.0 1\n" \
|
230
|
+
'h2o_feet,location=coyote_creek water_level=2.0 2'
|
231
|
+
|
232
|
+
@write_client.write(data: ['h2o_feet,location=coyote_creek water_level=1.0 1',
|
233
|
+
InfluxDB2::Point.new(name: 'h2o_feet')
|
234
|
+
.add_tag('location', 'coyote_creek')
|
235
|
+
.add_field('water_level', 2.0)
|
236
|
+
.time(2, InfluxDB2::WritePrecision::NANOSECOND)])
|
237
|
+
|
238
|
+
sleep(0.5)
|
239
|
+
|
240
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
241
|
+
times: 1, body: request)
|
242
|
+
|
243
|
+
sleep(1)
|
244
|
+
|
245
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
246
|
+
times: 1, body: request)
|
247
|
+
|
248
|
+
sleep(1)
|
249
|
+
|
250
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
251
|
+
times: 1, body: request)
|
252
|
+
|
253
|
+
sleep(1)
|
254
|
+
|
255
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
256
|
+
times: 2, body: request)
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_jitter_interval
|
260
|
+
@client.close!
|
261
|
+
|
262
|
+
@client = InfluxDB2::Client.new('http://localhost:9999',
|
263
|
+
'my-token',
|
264
|
+
bucket: 'my-bucket',
|
265
|
+
org: 'my-org',
|
266
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
267
|
+
use_ssl: false)
|
268
|
+
|
269
|
+
@write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
270
|
+
batch_size: 2, flush_interval: 5_000, jitter_interval: 2_000)
|
271
|
+
@write_client = @client.create_write_api(write_options: @write_options)
|
272
|
+
|
273
|
+
stub_request(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
274
|
+
.to_return(status: 204)
|
275
|
+
|
276
|
+
request = "h2o_feet,location=coyote_creek water_level=1.0 1\n" \
|
277
|
+
'h2o_feet,location=coyote_creek water_level=2.0 2'
|
278
|
+
|
279
|
+
@write_client.write(data: ['h2o_feet,location=coyote_creek water_level=1.0 1',
|
280
|
+
'h2o_feet,location=coyote_creek water_level=2.0 2'])
|
281
|
+
|
282
|
+
sleep(0.05)
|
283
|
+
|
284
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
285
|
+
times: 0, body: request)
|
286
|
+
|
287
|
+
sleep(2)
|
288
|
+
|
289
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
290
|
+
times: 1, body: request)
|
291
|
+
end
|
153
292
|
end
|
@@ -35,7 +35,7 @@ class WriteApiIntegrationTest < MiniTest::Test
|
|
35
35
|
|
36
36
|
now = Time.now.utc
|
37
37
|
|
38
|
-
measurement = 'h2o_' + now.to_i.to_s
|
38
|
+
measurement = 'h2o_' + now.to_i.to_s + now.nsec.to_s
|
39
39
|
point = InfluxDB2::Point.new(name: measurement)
|
40
40
|
.add_tag('location', 'europe')
|
41
41
|
.add_field('level', 2)
|
@@ -61,6 +61,7 @@ class WriteApiIntegrationTest < MiniTest::Test
|
|
61
61
|
uri = URI.parse('http://localhost:9999/api/v2/query?org=my-org')
|
62
62
|
request = Net::HTTP::Post.new(uri.request_uri)
|
63
63
|
request['Authorization'] = 'Token my-token'
|
64
|
+
request[InfluxDB2::DefaultApi::HEADER_CONTENT_TYPE] = 'application/json'
|
64
65
|
request.body = query.to_json
|
65
66
|
|
66
67
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -129,6 +129,25 @@ class WriteApiTest < MiniTest::Test
|
|
129
129
|
times: 1, body: expected)
|
130
130
|
end
|
131
131
|
|
132
|
+
def test_array_of_array
|
133
|
+
stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
134
|
+
.to_return(status: 204)
|
135
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
136
|
+
bucket: 'my-bucket',
|
137
|
+
org: 'my-org',
|
138
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
139
|
+
use_ssl: false)
|
140
|
+
|
141
|
+
client.create_write_api.write(data: ['h2o,location=west value=33i 15', ['h2o,location=west value=34i 16',
|
142
|
+
'h2o,location=west value=35i 17']])
|
143
|
+
|
144
|
+
expected = "h2o,location=west value=33i 15\nh2o,location=west value=34i 16"\
|
145
|
+
"\nh2o,location=west value=35i 17"
|
146
|
+
|
147
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
148
|
+
times: 1, body: expected)
|
149
|
+
end
|
150
|
+
|
132
151
|
def test_authorization_header
|
133
152
|
stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
134
153
|
.to_return(status: 204)
|
@@ -232,4 +251,25 @@ class WriteApiTest < MiniTest::Test
|
|
232
251
|
|
233
252
|
assert_equal 'The time precision not_supported is not supported.', error.message
|
234
253
|
end
|
254
|
+
|
255
|
+
def test_headers
|
256
|
+
stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
257
|
+
.to_return(status: 204)
|
258
|
+
|
259
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
260
|
+
bucket: 'my-bucket',
|
261
|
+
org: 'my-org',
|
262
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
263
|
+
use_ssl: false)
|
264
|
+
|
265
|
+
client.create_write_api.write(data: 'h2o,location=west value=33i 15')
|
266
|
+
|
267
|
+
headers = {
|
268
|
+
'Authorization' => 'Token my-token',
|
269
|
+
'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}",
|
270
|
+
'Content-Type' => 'text/plain'
|
271
|
+
}
|
272
|
+
assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
273
|
+
times: 1, body: 'h2o,location=west value=33i 15', headers: headers)
|
274
|
+
end
|
235
275
|
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.
|
4
|
+
version: 1.2.0
|
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-
|
11
|
+
date: 2020-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,16 +70,16 @@ dependencies:
|
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 12.3.3
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 12.3.3
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rubocop
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,9 +149,11 @@ files:
|
|
149
149
|
- lib/influxdb2/client.rb
|
150
150
|
- lib/influxdb2/client/client.rb
|
151
151
|
- lib/influxdb2/client/default_api.rb
|
152
|
+
- lib/influxdb2/client/delete_api.rb
|
152
153
|
- lib/influxdb2/client/flux_csv_parser.rb
|
153
154
|
- lib/influxdb2/client/flux_table.rb
|
154
155
|
- lib/influxdb2/client/influx_error.rb
|
156
|
+
- lib/influxdb2/client/models/delete_predicate_request.rb
|
155
157
|
- lib/influxdb2/client/models/dialect.rb
|
156
158
|
- lib/influxdb2/client/models/query.rb
|
157
159
|
- lib/influxdb2/client/point.rb
|
@@ -160,6 +162,8 @@ files:
|
|
160
162
|
- lib/influxdb2/client/worker.rb
|
161
163
|
- lib/influxdb2/client/write_api.rb
|
162
164
|
- test/influxdb/client_test.rb
|
165
|
+
- test/influxdb/delete_api_integration_test.rb
|
166
|
+
- test/influxdb/delete_api_test.rb
|
163
167
|
- test/influxdb/flux_csv_parser_test.rb
|
164
168
|
- test/influxdb/point_test.rb
|
165
169
|
- test/influxdb/query_api_integration_test.rb
|
@@ -197,6 +201,8 @@ specification_version: 4
|
|
197
201
|
summary: Ruby library for InfluxDB 2.
|
198
202
|
test_files:
|
199
203
|
- test/influxdb/client_test.rb
|
204
|
+
- test/influxdb/delete_api_integration_test.rb
|
205
|
+
- test/influxdb/delete_api_test.rb
|
200
206
|
- test/influxdb/flux_csv_parser_test.rb
|
201
207
|
- test/influxdb/point_test.rb
|
202
208
|
- test/influxdb/query_api_integration_test.rb
|