influxdb-client 1.8.0.pre.1133 → 1.8.0.pre.1218

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,7 @@ class WriteApiIntegrationTest < MiniTest::Test
27
27
  end
28
28
 
29
29
  def test_write_into_influx_db
30
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
30
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
31
31
  bucket: 'my-bucket',
32
32
  org: 'my-org',
33
33
  precision: InfluxDB2::WritePrecision::NANOSECOND,
@@ -58,7 +58,7 @@ class WriteApiIntegrationTest < MiniTest::Test
58
58
  query = { 'query': 'from(bucket: "my-bucket") |> range(start: -15m, stop: now()) '\
59
59
  "|> filter(fn: (r) => r._measurement == \"#{measurement}\")", 'type': 'flux' }
60
60
 
61
- uri = URI.parse('http://localhost:9999/api/v2/query?org=my-org')
61
+ uri = URI.parse('http://localhost:8086/api/v2/query?org=my-org')
62
62
  request = Net::HTTP::Post.new(uri.request_uri)
63
63
  request['Authorization'] = 'Token my-token'
64
64
  request[InfluxDB2::DefaultApi::HEADER_CONTENT_TYPE] = 'application/json'
@@ -26,7 +26,7 @@ class WriteApiTest < MiniTest::Test
26
26
  end
27
27
 
28
28
  def test_required_arguments
29
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token')
29
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token')
30
30
  write_api = client.create_write_api
31
31
 
32
32
  # precision
@@ -44,7 +44,7 @@ class WriteApiTest < MiniTest::Test
44
44
  end
45
45
 
46
46
  def test_default_arguments_
47
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
47
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
48
48
  bucket: 'my-bucket',
49
49
  org: 'my-org',
50
50
  precision: InfluxDB2::WritePrecision::NANOSECOND)
@@ -55,9 +55,9 @@ class WriteApiTest < MiniTest::Test
55
55
  end
56
56
 
57
57
  def test_write_line_protocol
58
- stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
58
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
59
59
  .to_return(status: 204)
60
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
60
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
61
61
  bucket: 'my-bucket',
62
62
  org: 'my-org',
63
63
  precision: InfluxDB2::WritePrecision::NANOSECOND,
@@ -65,14 +65,14 @@ class WriteApiTest < MiniTest::Test
65
65
 
66
66
  client.create_write_api.write(data: 'h2o,location=west value=33i 15')
67
67
 
68
- assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
68
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
69
69
  times: 1, body: 'h2o,location=west value=33i 15')
70
70
  end
71
71
 
72
72
  def test_write_point
73
- stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
73
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
74
74
  .to_return(status: 204)
75
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
75
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
76
76
  bucket: 'my-bucket',
77
77
  org: 'my-org',
78
78
  precision: InfluxDB2::WritePrecision::NANOSECOND,
@@ -82,32 +82,32 @@ class WriteApiTest < MiniTest::Test
82
82
  .add_tag('location', 'europe')
83
83
  .add_field('level', 2))
84
84
 
85
- assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
85
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
86
86
  times: 1, body: 'h2o,location=europe level=2i')
87
87
  end
88
88
 
89
89
  def test_write_hash
90
- stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
90
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
91
91
  .to_return(status: 204)
92
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
92
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
93
93
  bucket: 'my-bucket',
94
94
  org: 'my-org',
95
95
  precision: InfluxDB2::WritePrecision::NANOSECOND,
96
96
  use_ssl: false)
97
97
 
98
98
  client.create_write_api.write(data: { name: 'h2o',
99
- tags: { host: 'aws', region: 'us' },
99
+ tags: { region: 'us', host: 'aws' },
100
100
  fields: { level: 5, saturation: '99%' }, time: 123 })
101
101
 
102
102
  expected = 'h2o,host=aws,region=us level=5i,saturation="99%" 123'
103
- assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
103
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
104
104
  times: 1, body: expected)
105
105
  end
106
106
 
107
107
  def test_write_collection
108
- stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
108
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
109
109
  .to_return(status: 204)
110
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
110
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
111
111
  bucket: 'my-bucket',
112
112
  org: 'my-org',
113
113
  precision: InfluxDB2::WritePrecision::NANOSECOND,
@@ -125,14 +125,14 @@ class WriteApiTest < MiniTest::Test
125
125
 
126
126
  expected = "h2o,location=west value=33i 15\nh2o,location=europe level=2i"\
127
127
  "\nh2o,host=aws,region=us level=5i,saturation=\"99%\" 123"
128
- assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
128
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
129
129
  times: 1, body: expected)
130
130
  end
131
131
 
132
132
  def test_array_of_array
133
- stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
133
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
134
134
  .to_return(status: 204)
135
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
135
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
136
136
  bucket: 'my-bucket',
137
137
  org: 'my-org',
138
138
  precision: InfluxDB2::WritePrecision::NANOSECOND,
@@ -144,14 +144,14 @@ class WriteApiTest < MiniTest::Test
144
144
  expected = "h2o,location=west value=33i 15\nh2o,location=west value=34i 16"\
145
145
  "\nh2o,location=west value=35i 17"
146
146
 
147
- assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
147
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
148
148
  times: 1, body: expected)
149
149
  end
150
150
 
151
151
  def test_authorization_header
152
- stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
152
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
153
153
  .to_return(status: 204)
154
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
154
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
155
155
  bucket: 'my-bucket',
156
156
  org: 'my-org',
157
157
  precision: InfluxDB2::WritePrecision::NANOSECOND,
@@ -159,31 +159,31 @@ class WriteApiTest < MiniTest::Test
159
159
 
160
160
  client.create_write_api.write(data: 'h2o,location=west value=33i 15')
161
161
 
162
- assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
162
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
163
163
  times: 1, headers: { 'Authorization' => 'Token my-token' })
164
164
  end
165
165
 
166
166
  def test_without_data
167
- stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
167
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
168
168
  .to_return(status: 204)
169
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
169
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
170
170
  bucket: 'my-bucket',
171
171
  org: 'my-org',
172
172
  precision: InfluxDB2::WritePrecision::NANOSECOND)
173
173
 
174
174
  client.create_write_api.write(data: '')
175
175
 
176
- assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns', times: 0)
176
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns', times: 0)
177
177
  end
178
178
 
179
179
  def test_influx_exception
180
180
  error_body = '{"code":"invalid","message":"unable to parse '\
181
181
  '\'h2o_feet, location=coyote_creek water_level=1.0 1\': missing tag key"}'
182
182
 
183
- stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
183
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
184
184
  .to_return(status: 400, headers: { 'X-Platform-Error-Code' => 'invalid' }, body: error_body)
185
185
 
186
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
186
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
187
187
  bucket: 'my-bucket',
188
188
  org: 'my-org',
189
189
  precision: InfluxDB2::WritePrecision::NANOSECOND,
@@ -199,14 +199,14 @@ class WriteApiTest < MiniTest::Test
199
199
  end
200
200
 
201
201
  def test_follow_redirect
202
- stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
202
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
203
203
  .to_return(status: 307, headers:
204
204
  { 'location' => 'http://localhost:9090/api/v2/write?bucket=my-bucket&org=my-org&precision=ns' })
205
205
  .then.to_return(status: 204)
206
206
  stub_request(:any, 'http://localhost:9090/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
207
207
  .to_return(status: 204)
208
208
 
209
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
209
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
210
210
  bucket: 'my-bucket',
211
211
  org: 'my-org',
212
212
  precision: InfluxDB2::WritePrecision::NANOSECOND,
@@ -214,18 +214,18 @@ class WriteApiTest < MiniTest::Test
214
214
 
215
215
  client.create_write_api.write(data: 'h2o,location=west value=33i 15')
216
216
 
217
- assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
217
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
218
218
  times: 1, body: 'h2o,location=west value=33i 15')
219
219
  assert_requested(:post, 'http://localhost:9090/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
220
220
  times: 1, body: 'h2o,location=west value=33i 15')
221
221
  end
222
222
 
223
223
  def test_follow_redirect_max
224
- stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
224
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
225
225
  .to_return(status: 307, headers:
226
- { 'location' => 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns' })
226
+ { 'location' => 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns' })
227
227
 
228
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
228
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
229
229
  bucket: 'my-bucket',
230
230
  org: 'my-org',
231
231
  precision: InfluxDB2::WritePrecision::NANOSECOND,
@@ -253,10 +253,10 @@ class WriteApiTest < MiniTest::Test
253
253
  end
254
254
 
255
255
  def test_headers
256
- stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
256
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
257
257
  .to_return(status: 204)
258
258
 
259
- client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
259
+ client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
260
260
  bucket: 'my-bucket',
261
261
  org: 'my-org',
262
262
  precision: InfluxDB2::WritePrecision::NANOSECOND,
@@ -269,14 +269,14 @@ class WriteApiTest < MiniTest::Test
269
269
  'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}",
270
270
  'Content-Type' => 'text/plain'
271
271
  }
272
- assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
272
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
273
273
  times: 1, body: 'h2o,location=west value=33i 15', headers: headers)
274
274
  end
275
275
 
276
276
  def test_trailing_slash_in_url
277
- stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
277
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
278
278
  .to_return(status: 204)
279
- client = InfluxDB2::Client.new('http://localhost:9999/', 'my-token',
279
+ client = InfluxDB2::Client.new('http://localhost:8086/', 'my-token',
280
280
  bucket: 'my-bucket',
281
281
  org: 'my-org',
282
282
  precision: InfluxDB2::WritePrecision::NANOSECOND,
@@ -284,7 +284,104 @@ class WriteApiTest < MiniTest::Test
284
284
 
285
285
  client.create_write_api.write(data: 'h2o,location=west value=33i 15')
286
286
 
287
- assert_requested(:post, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
287
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
288
288
  times: 1, body: 'h2o,location=west value=33i 15')
289
289
  end
290
290
  end
291
+
292
+ class PointSettingsTest < MiniTest::Test
293
+ def setup
294
+ WebMock.disable_net_connect!
295
+
296
+ @client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
297
+ bucket: 'my-bucket',
298
+ org: 'my-org',
299
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
300
+ use_ssl: false)
301
+
302
+ @id_tag = '132-987-655'
303
+ @customer_tag = 'California Miner'
304
+ end
305
+
306
+ def test_point_settings
307
+ point_settings = InfluxDB2::PointSettings.new(default_tags:
308
+ { id: @id_tag,
309
+ customer: @customer_tag })
310
+
311
+ default_tags = point_settings.default_tags
312
+
313
+ assert_equal @id_tag, default_tags[:id]
314
+ assert_equal @customer_tag, default_tags[:customer]
315
+ end
316
+
317
+ def test_point_settings_with_add
318
+ point_settings = InfluxDB2::PointSettings.new
319
+ point_settings.add_default_tag('id', @id_tag)
320
+ point_settings.add_default_tag('customer', @customer_tag)
321
+
322
+ default_tags = point_settings.default_tags
323
+
324
+ assert_equal @id_tag, default_tags['id']
325
+ assert_equal @customer_tag, default_tags['customer']
326
+ end
327
+ end
328
+
329
+ class WriteApiDefaultTagsTest < MiniTest::Test
330
+ def setup
331
+ WebMock.disable_net_connect!
332
+
333
+ @id_tag = '132-987-655'
334
+ @customer_tag = 'California Miner'
335
+ @data_center_tag = '${env.data_center}'
336
+
337
+ ENV['data_center'] = 'LA'
338
+
339
+ @client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
340
+ bucket: 'my-bucket',
341
+ org: 'my-org',
342
+ precision: InfluxDB2::WritePrecision::NANOSECOND,
343
+ use_ssl: false,
344
+ tags: { id: @id_tag })
345
+
346
+ point_settings = InfluxDB2::PointSettings.new(default_tags: { customer: @customer_tag })
347
+ point_settings.add_default_tag('data_center', @data_center_tag)
348
+
349
+ @write_api = @client.create_write_api(write_options: InfluxDB2::SYNCHRONOUS,
350
+ point_settings: point_settings)
351
+ end
352
+
353
+ def test_write_using_default_tags
354
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
355
+ .to_return(status: 204)
356
+
357
+ @write_api.write(data: InfluxDB2::Point.new(name: 'h2o')
358
+ .add_tag('location', 'europe')
359
+ .add_field('level', 2))
360
+
361
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
362
+ times: 1, body: 'h2o,customer=California\ Miner,data_center=LA,id=132-987-655,location=europe '\
363
+ 'level=2i')
364
+ end
365
+
366
+ def test_write_collection
367
+ stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
368
+ .to_return(status: 204)
369
+
370
+ point = InfluxDB2::Point.new(name: 'h2o')
371
+ .add_tag('location', 'europe')
372
+ .add_field('level', 2)
373
+
374
+ hash = { name: 'h2o',
375
+ tags: { host: 'aws', region: 'us' },
376
+ fields: { level: 5, saturation: '99%' }, time: 123 }
377
+
378
+ @write_api.write(data: ['h2o,location=west value=33i 15', nil, '', point, hash])
379
+
380
+ expected = 'h2o,location=west value=33i 15'\
381
+ "\nh2o,customer=California\\ Miner,data_center=LA,id=132-987-655,location=europe level=2i"\
382
+ "\nh2o,customer=California\\ Miner,data_center=LA,host=aws,id=132-987-655,region=us "\
383
+ 'level=5i,saturation="99%" 123'
384
+ assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
385
+ times: 1, body: expected)
386
+ end
387
+ 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.8.0.pre.1133
4
+ version: 1.8.0.pre.1218
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-08-14 00:00:00.000000000 Z
11
+ date: 2020-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler