influxdb 0.3.8 → 0.3.9

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
  SHA1:
3
- metadata.gz: 1338ae151de766b8f05c29b117133b19e4d993e0
4
- data.tar.gz: e9f74096f0c73ca57877354f14919e02a81d5db6
3
+ metadata.gz: 4126a6d8021cd7ae64f6ebc12bd9760ef482c9df
4
+ data.tar.gz: 33c78e146fc49a8d0302ae0f4704837d1f3f5b9d
5
5
  SHA512:
6
- metadata.gz: a18bb479c32e71163beb834f8141bdc4cf6ce4bb2f4e4f153ca0a0b28c820be8f765e1cc29a89d37868b7878fb6b9c9921f56347b5e9c4cf12802d9b8a7da66a
7
- data.tar.gz: 2f008e1a615393c162cb1491317495f47b076484a275b6e9e01e42995b68835cd92523224d008dad24413a8b8739647cee82274e827359db5b20d75e8560dbf5
6
+ metadata.gz: 0b9ec022755c6e03bb0c2473102358c3f60b64eb80a44160ae5b0398d413e5f90c293e596a0996935a35e2ef50a2c90d091a6cb0690eab380bdca5e24b9b06e7
7
+ data.tar.gz: 0058ee385c54b9b0a70bf794ab16b5a94a617825b58f4a9821fbdc668b0fa37bddea415fb762eab1b6cd7e3d517c2dc5da8d8ed9d9e35ea5fb50d796d27d9de0
data/.rubocop.yml CHANGED
@@ -12,6 +12,12 @@ AllCops:
12
12
  Rails:
13
13
  Enabled: false
14
14
 
15
+ Style/FrozenStringLiteralComment:
16
+ Enabled: false
17
+
18
+ Style/NumericPredicate:
19
+ Enabled: false
20
+
15
21
  Style/StringLiterals:
16
22
  Enabled: false
17
23
 
data/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ For the full commit log, [see here](https://github.com/influxdata/influxdb-ruby/
6
6
 
7
7
  - None.
8
8
 
9
+ ## v0.3.9, released 2016-09-20
10
+
11
+ - Changed retry behaviour slightly. When the server responds with an incomplete
12
+ response, we now assume a major server-side problem (insufficient resources,
13
+ e.g. out-of-memory) and cancel any retry attempts (#165, #166).
14
+
9
15
  ## v0.3.8, released 2016-08-31
10
16
 
11
17
  - Added support for named and positional query parameters (#160, @retorquere).
data/README.md CHANGED
@@ -5,23 +5,44 @@
5
5
  The official Ruby client library for [InfluxDB](https://influxdata.com/time-series-platform/influxdb/).
6
6
  Maintained by [@toddboom](https://github.com/toddboom) and [@dmke](https://github.com/dmke).
7
7
 
8
+ ## Contents
9
+
10
+ - [Platform support](#platform-support)
11
+ - [Ruby support](#ruby-support)
12
+ - [Installation](#installation)
13
+ - [Usage](#usage)
14
+ - [Creating a client](#creating-a-client)
15
+ - [Administrative tasks](#administrative-tasks)
16
+ - [Continuous queries](#continuous-queries)
17
+ - [Retention policies](#retention-policies)
18
+ - [Writing data](#writing-data)
19
+ - [Reading data](#reading-data)
20
+ - [Querying](#querying)
21
+ - [De-normalization](#de--normalization)
22
+ - [Streaming response](#streaming-response)
23
+ - [Retry](#retry)
24
+ - [Testing](#testing)
25
+ - [Contributing](#contributing)
26
+
8
27
  ## Platform support
9
28
 
10
- > **Support for InfluxDB v0.8.x is now deprecated**. The final version of this library that
11
- > will support the older InfluxDB interface is `v0.1.9`, which is available as a gem and
12
- > tagged on this repository.
29
+ > **Support for InfluxDB v0.8.x is now deprecated**. The final version of this
30
+ > library that will support the older InfluxDB interface is `v0.1.9`, which is
31
+ > available as a gem and tagged on this repository.
13
32
  >
14
- > If you're reading this message, then you should only expect support for InfluxDB v0.9.1
15
- > and higher.
33
+ > If you're reading this message, then you should only expect support for
34
+ > InfluxDB v0.9.1 and higher.
16
35
 
17
36
  ## Ruby support
18
37
 
19
- This gem should work with Ruby 1.9+, but starting with v0.4, we'll likely drop Ruby 1.9 support.
38
+ This gem should work with Ruby 1.9+, but starting with v0.4, we'll likely drop
39
+ Ruby 1.9 support.
20
40
 
21
- Please note that for Ruby 1.9, you'll need to install the JSON gem in version 1.8.x yourself,
22
- for example by pinning the version in your `Gemfile` (i.e. `gem "json", "~> 1.8.3"`).
41
+ Please note that for Ruby 1.9, you'll need to install the JSON gem in version
42
+ 1.8.x yourself, for example by pinning the version in your `Gemfile` (i.e.
43
+ `gem "json", "~> 1.8.3"`).
23
44
 
24
- ## Install
45
+ ## Installation
25
46
 
26
47
  ```
27
48
  $ [sudo] gem install influxdb
@@ -175,7 +196,8 @@ query = 'SELECT COUNT(name) INTO clicksCount_1h FROM clicks GROUP BY time(1h)'
175
196
  influxdb.create_continuous_query(name, database, query)
176
197
  ```
177
198
 
178
- Additionally, you can specify the resample interval and the time range over which the CQ runs:
199
+ Additionally, you can specify the resample interval and the time range over
200
+ which the CQ runs:
179
201
 
180
202
  ``` ruby
181
203
  influxdb.create_continuous_query(name, database, query, resample_every: "10m", resample_for: "65m")
@@ -203,9 +225,9 @@ influxdb.list_retention_policies(database)
203
225
  Create a retention policy for a database:
204
226
 
205
227
  ``` ruby
206
- database = 'foo'
207
- name = '1h.cpu'
208
- duration = '10m'
228
+ database = 'foo'
229
+ name = '1h.cpu'
230
+ duration = '10m'
209
231
  replication = 2
210
232
 
211
233
  influxdb.create_retention_policy(name, database, duration, replication)
@@ -215,7 +237,7 @@ Delete a retention policy from a database:
215
237
 
216
238
  ``` ruby
217
239
  database = 'foo'
218
- name = '1h.cpu'
240
+ name = '1h.cpu'
219
241
 
220
242
  influxdb.delete_retention_policy(name, database)
221
243
  ```
@@ -223,9 +245,9 @@ influxdb.delete_retention_policy(name, database)
223
245
  Alter a retention policy for a database:
224
246
 
225
247
  ``` ruby
226
- database = 'foo'
227
- name = '1h.cpu'
228
- duration = '10m'
248
+ database = 'foo'
249
+ name = '1h.cpu'
250
+ duration = '10m'
229
251
  replication = 2
230
252
 
231
253
  influxdb.alter_retention_policy(name, database, duration, replication)
@@ -241,9 +263,7 @@ password = 'bar'
241
263
  database = 'site_development'
242
264
  name = 'foobar'
243
265
 
244
- influxdb = InfluxDB::Client.new database,
245
- username: username,
246
- password: password
266
+ influxdb = InfluxDB::Client.new database, username: username, password: password
247
267
 
248
268
  # Enumerator that emits a sine wave
249
269
  Value = (0..360).to_a.map {|i| Math.send(:sin, i / 10.0) * 10 }.each
@@ -251,7 +271,7 @@ Value = (0..360).to_a.map {|i| Math.send(:sin, i / 10.0) * 10 }.each
251
271
  loop do
252
272
  data = {
253
273
  values: { value: Value.next },
254
- tags: { wave: 'sine' } # tags are optional
274
+ tags: { wave: 'sine' } # tags are optional
255
275
  }
256
276
 
257
277
  influxdb.write_point(name, data)
@@ -272,9 +292,10 @@ name = 'foobar'
272
292
  time_precision = 's'
273
293
 
274
294
  # either in the client initialization:
275
- influxdb = InfluxDB::Client.new database, username: username,
276
- password: password,
277
- time_precision: time_precision
295
+ influxdb = InfluxDB::Client.new database,
296
+ username: username,
297
+ password: password,
298
+ time_precision: time_precision
278
299
 
279
300
  data = {
280
301
  values: { value: 0 },
@@ -301,12 +322,12 @@ precision = 's'
301
322
  retention = '1h.cpu'
302
323
 
303
324
  influxdb = InfluxDB::Client.new database,
304
- username: username,
305
- password: password
325
+ username: username,
326
+ password: password
306
327
 
307
328
  data = {
308
- values: { value: 0 },
309
- tags: { foo: 'bar', bar: 'baz' }
329
+ values: { value: 0 },
330
+ tags: { foo: 'bar', bar: 'baz' }
310
331
  timestamp: Time.now.to_i
311
332
  }
312
333
 
@@ -320,12 +341,12 @@ Write multiple points in a batch (performance boost):
320
341
  data = [
321
342
  {
322
343
  series: 'cpu',
323
- tags: { host: 'server_1', region: 'us' },
324
- values: {internal: 5, external: 0.453345}
344
+ tags: { host: 'server_1', region: 'us' },
345
+ values: { internal: 5, external: 0.453345 }
325
346
  },
326
347
  {
327
348
  series: 'gpu',
328
- values: {value: 0.9999},
349
+ values: { value: 0.9999 },
329
350
  }
330
351
  ]
331
352
 
@@ -335,22 +356,20 @@ influxdb.write_points(data)
335
356
 
336
357
  precision = 'm'
337
358
  influxdb.write_points(data, precision)
338
-
339
359
  ```
340
360
 
341
361
  Write multiple points in a batch with a specific retention policy:
342
362
 
343
363
  ``` ruby
344
-
345
364
  data = [
346
365
  {
347
366
  series: 'cpu',
348
- tags: { host: 'server_1', region: 'us' },
349
- values: {internal: 5, external: 0.453345}
367
+ tags: { host: 'server_1', region: 'us' },
368
+ values: { internal: 5, external: 0.453345 }
350
369
  },
351
370
  {
352
371
  series: 'gpu',
353
- values: {value: 0.9999},
372
+ values: { value: 0.9999 },
354
373
  }
355
374
  ]
356
375
 
@@ -371,13 +390,13 @@ database = 'site_development'
371
390
  name = 'foobar'
372
391
 
373
392
  influxdb = InfluxDB::Client.new database,
374
- username: username,
375
- password: password,
376
- async: true
393
+ username: username,
394
+ password: password,
395
+ async: true
377
396
 
378
397
  data = {
379
- values: { value: 0 },
380
- tags: { foo: 'bar', bar: 'baz' }
398
+ values: { value: 0 },
399
+ tags: { foo: 'bar', bar: 'baz' },
381
400
  timestamp: Time.now.to_i
382
401
  }
383
402
 
@@ -400,9 +419,9 @@ async_options = {
400
419
  }
401
420
 
402
421
  influxdb = InfluxDB::Client.new database,
403
- username: username,
404
- password: password,
405
- async: async_options
422
+ username: username,
423
+ password: password,
424
+ async: async_options
406
425
  ```
407
426
 
408
427
 
@@ -419,7 +438,7 @@ name = 'hitchhiker'
419
438
 
420
439
  data = {
421
440
  values: { value: 666 },
422
- tags: { foo: 'bar', bar: 'baz' }
441
+ tags: { foo: 'bar', bar: 'baz' }
423
442
  }
424
443
 
425
444
  influxdb.write_point(name, data)
@@ -435,40 +454,77 @@ password = 'bar'
435
454
  database = 'site_development'
436
455
 
437
456
  influxdb = InfluxDB::Client.new database,
438
- username: username,
439
- password: password
457
+ username: username,
458
+ password: password
440
459
 
441
460
  # without a block:
442
- influxdb.query 'select * from time_series_1' # results are grouped by name, but also their tags
443
-
444
- # result:
445
- # [{"name"=>"time_series_1", "tags"=>{"region"=>"uk"}, "values"=>[{"time"=>"2015-07-09T09:03:31Z", "count"=>32, "value"=>0.9673}, {"time"=>"2015-07-09T09:03:49Z", "count"=>122, "value"=>0.4444}]},
446
- # {"name"=>"time_series_1", "tags"=>{"region"=>"us"}, "values"=>[{"time"=>"2015-07-09T09:02:54Z", "count"=>55, "value"=>0.4343}]}]
461
+ influxdb.query 'select * from time_series_1'
462
+
463
+ # results are grouped by name, but also their tags:
464
+ #
465
+ # [
466
+ # {
467
+ # "name"=>"time_series_1",
468
+ # "tags"=>{"region"=>"uk"},
469
+ # "values"=>[
470
+ # {"time"=>"2015-07-09T09:03:31Z", "count"=>32, "value"=>0.9673},
471
+ # {"time"=>"2015-07-09T09:03:49Z", "count"=>122, "value"=>0.4444}
472
+ # ]
473
+ # },
474
+ # {
475
+ # "name"=>"time_series_1",
476
+ # "tags"=>{"region"=>"us"},
477
+ # "values"=>[
478
+ # {"time"=>"2015-07-09T09:02:54Z", "count"=>55, "value"=>0.4343}
479
+ # ]
480
+ # }
481
+ # ]
447
482
 
448
483
  # with a block:
449
484
  influxdb.query 'select * from time_series_1' do |name, tags, points|
450
- puts "#{name} [ #{tags} ] => #{points}"
485
+ puts "#{name} [ #{tags.inspect} ]"
486
+ points.each do |pt|
487
+ puts " -> #{pt.inspect}"
488
+ end
451
489
  end
452
490
 
453
491
  # result:
454
- # time_series_1 [ {"region"=>"uk"} ] => [{"time"=>"2015-07-09T09:03:31Z", "count"=>32, "value"=>0.9673}, {"time"=>"2015-07-09T09:03:49Z", "count"=>122, "value"=>0.4444}]
455
- # time_series_1 [ {"region"=>"us"} ] => [{"time"=>"2015-07-09T09:02:54Z", "count"=>55, "value"=>0.4343}]
492
+ # time_series_1 [ {"region"=>"uk"} ]
493
+ # -> {"time"=>"2015-07-09T09:03:31Z", "count"=>32, "value"=>0.9673}
494
+ # -> {"time"=>"2015-07-09T09:03:49Z", "count"=>122, "value"=>0.4444}]
495
+ # time_series_1 [ {"region"=>"us"} ]
496
+ # -> {"time"=>"2015-07-09T09:02:54Z", "count"=>55, "value"=>0.4343}
456
497
  ```
457
498
 
458
- If you would rather receive points with integer timestamp, it's possible to set `epoch` parameter:
499
+ If you would rather receive points with integer timestamp, it's possible to set
500
+ `epoch` parameter:
459
501
 
460
502
  ``` ruby
461
503
  # globally, on client initialization:
462
504
  influxdb = InfluxDB::Client.new database, epoch: 's'
463
505
 
464
506
  influxdb.query 'select * from time_series'
465
- # result:
466
- # [{"name"=>"time_series", "tags"=>{"region"=>"uk"}, "values"=>[{"time"=>1438411376, "count"=>32, "value"=>0.9673}]}]
507
+ # [
508
+ # {
509
+ # "name"=>"time_series",
510
+ # "tags"=>{"region"=>"uk"},
511
+ # "values"=>[
512
+ # {"time"=>1438411376, "count"=>32, "value"=>0.9673}
513
+ # ]
514
+ # }
515
+ # ]
467
516
 
468
517
  # or for a specific query call:
469
518
  influxdb.query 'select * from time_series', epoch: 'ms'
470
- # result:
471
- # [{"name"=>"time_series", "tags"=>{"region"=>"uk"}, "values"=>[{"time"=>1438411376000, "count"=>32, "value"=>0.9673}]}]
519
+ # [
520
+ # {
521
+ # "name"=>"time_series",
522
+ # "tags"=>{"region"=>"uk"},
523
+ # "values"=>[
524
+ # {"time"=>1438411376000, "count"=>32, "value"=>0.9673}
525
+ # ]
526
+ # }
527
+ # ]
472
528
  ```
473
529
 
474
530
  Working with parameterized query strings works as expected:
@@ -490,28 +546,54 @@ influxdb.query positional_params_query, params: ["foobar", 42]
490
546
 
491
547
  #### (De-) Normalization
492
548
 
493
- By default, InfluxDB::Client will denormalize points (received from InfluxDB as columns and rows), if you want to get _raw_ data add `denormalize: false` to initialization options or to query itself:
549
+ By default, InfluxDB::Client will denormalize points (received from InfluxDB as
550
+ columns and rows). If you want to get *raw* data add `denormalize: false` to
551
+ the initialization options or to query itself:
494
552
 
495
553
  ``` ruby
496
554
  influxdb.query 'select * from time_series_1', denormalize: false
497
555
 
498
- # result
499
- [{"name"=>"time_series_1", "tags"=>{"region"=>"uk"}, "columns"=>["time", "count", "value"], "values"=>[["2015-07-09T09:03:31Z", 32, 0.9673], ["2015-07-09T09:03:49Z", 122, 0.4444]]},
500
- {"name"=>"time_series_1", "tags"=>{"region"=>"us"}, "columns"=>["time", "count", "value"], "values"=>[["2015-07-09T09:02:54Z", 55, 0.4343]]}]
556
+ # [
557
+ # {
558
+ # "name"=>"time_series_1",
559
+ # "tags"=>{"region"=>"uk"},
560
+ # "columns"=>["time", "count", "value"],
561
+ # "values"=>[
562
+ # ["2015-07-09T09:03:31Z", 32, 0.9673],
563
+ # ["2015-07-09T09:03:49Z", 122, 0.4444]
564
+ # ]
565
+ # },
566
+ # {
567
+ # "name"=>"time_series_1",
568
+ # "tags"=>{"region"=>"us"},
569
+ # "columns"=>["time", "count", "value"],
570
+ # "values"=>[
571
+ # ["2015-07-09T09:02:54Z", 55, 0.4343]
572
+ # ]
573
+ # }
574
+ # ]
501
575
 
502
576
 
503
577
  influxdb.query 'select * from time_series_1', denormalize: false do |name, tags, points|
504
- puts "#{name} [ #{tags} ] => #{points}"
578
+ puts "#{name} [ #{tags.inspect} ]"
579
+ points.each do |key, values|
580
+ puts " #{key.inspect} -> #{values.inspect}"
581
+ end
505
582
  end
506
583
 
507
- # result:
508
- # time_series_1 [ {"region"=>"uk"} ] => {"columns"=>["time", "count", "value"], "values"=>[["2015-07-09T09:03:31Z", 32, 0.9673], ["2015-07-09T09:03:49Z", 122, 0.4444]]}
509
- # time_series_1 [ {"region"=>"us"} ] => {"columns"=>["time", "count", "value"], "values"=>[["2015-07-09T09:02:54Z", 55, 0.4343]]}
584
+
585
+ # time_series_1 [ {"region"=>"uk"} ]
586
+ # columns -> ["time", "count", "value"]
587
+ # values -> [["2015-07-09T09:03:31Z", 32, 0.9673], ["2015-07-09T09:03:49Z", 122, 0.4444]]}
588
+ # time_series_1 [ {"region"=>"us"} ]
589
+ # columns -> ["time", "count", "value"]
590
+ # values -> [["2015-07-09T09:02:54Z", 55, 0.4343]]}
510
591
  ```
511
592
 
512
593
  #### Streaming response
513
594
 
514
- If you expect large quantities of data in a response, you may want to enable JSON streaming by setting a `chunk_size`:
595
+ If you expect large quantities of data in a response, you may want to enable
596
+ JSON streaming by setting a `chunk_size`:
515
597
 
516
598
  ``` ruby
517
599
  influxdb = InfluxDB::Client.new database,
@@ -520,43 +602,37 @@ influxdb = InfluxDB::Client.new database,
520
602
  chunk_size: 10000
521
603
  ```
522
604
 
523
- See the [official documentation](http://docs.influxdata.com/influxdb/v0.13/guides/querying_data/#chunking) for more details.
605
+ See the [official documentation](http://docs.influxdata.com/influxdb/v0.13/guides/querying_data/#chunking)
606
+ for more details.
524
607
 
525
608
 
526
609
  #### Retry
527
610
 
528
- By default, InfluxDB::Client will keep trying to connect to the database when it gets connection denied,
529
- if you want to retry a finite number of times (or disable retries altogether), you should pass the `:retry`
530
- value.
611
+ By default, InfluxDB::Client will keep trying (with exponential fall-off) to
612
+ connect to the database until it gets a connection. If you want to retry only
613
+ a finite number of times (or disable retries altogether), you can pass the
614
+ `:retry` option.
531
615
 
532
- `:retry` can be either `true`, `false` or an `Integer` to retry infinite times, disable retries or retry
533
- a finite number of times, respectively. `0` is equivalent to `false`
616
+ `:retry` can be either `true`, `false` or an `Integer` to retry infinite times,
617
+ disable retries or retry a finite number of times, respectively. Passing `0` is
618
+ equivalent to `false` and `-1` is equivalent to `true`.
534
619
 
535
620
  ```
536
621
  $ irb -r influxdb
537
- > influxdb = InfluxDB::Client.new 'database', :retry => 4
538
- => #<InfluxDB::Client:0x00000002bb5ce0 @database="database", @hosts=["localhost"],
539
- @port=8086, @username="root", @password="root", @use_ssl=false,
540
- @time_precision="s", @initial_delay=0.01, @max_delay=30,
541
- @open_timeout=5, @read_timeout=300, @async=false, @retry=4>
622
+ > influxdb = InfluxDB::Client.new 'database', retry: 8
623
+ => #<InfluxDB::Client:0x00000002bb5ce0 ...>
542
624
 
543
625
  > influxdb.query 'select * from serie limit 1'
544
- E, [2014-06-02T11:04:13.416209 #22825] ERROR -- : [InfluxDB] Failed to
545
- contact host localhost: #<SocketError: getaddrinfo: Name or service not known> -
546
- retrying in 0.01s.
547
- E, [2014-06-02T11:04:13.433646 #22825] ERROR -- : [InfluxDB] Failed to
548
- contact host localhost: #<SocketError: getaddrinfo: Name or service not known> -
549
- retrying in 0.02s.
550
- E, [2014-06-02T11:04:13.462566 #22825] ERROR -- : [InfluxDB] Failed to
551
- contact host localhost: #<SocketError: getaddrinfo: Name or service not known> -
552
- retrying in 0.04s.
553
- E, [2014-06-02T11:04:13.510853 #22825] ERROR -- : [InfluxDB] Failed to
554
- contact host localhost: #<SocketError: getaddrinfo: Name or service not known> -
555
- retrying in 0.08s.
556
- SocketError: Tried 4 times to reconnect but failed.
557
- ```
558
-
559
- If you pass `:retry => -1` it will keep trying forever until it gets the connection.
626
+ E, [2016-08-31T23:55:18.287947 #23476] ERROR -- InfluxDB: Failed to contact host localhost: #<Errno::ECONNREFUSED: Failed to open TCP connection to localhost:8086 (Connection refused - connect(2) for "localhost" port 8086)> - retrying in 0.01s.
627
+ E, [2016-08-31T23:55:18.298455 #23476] ERROR -- InfluxDB: Failed to contact host localhost: #<Errno::ECONNREFUSED: Failed to open TCP connection to localhost:8086 (Connection refused - connect(2) for "localhost" port 8086)> - retrying in 0.02s.
628
+ E, [2016-08-31T23:55:18.319122 #23476] ERROR -- InfluxDB: Failed to contact host localhost: #<Errno::ECONNREFUSED: Failed to open TCP connection to localhost:8086 (Connection refused - connect(2) for "localhost" port 8086)> - retrying in 0.04s.
629
+ E, [2016-08-31T23:55:18.359785 #23476] ERROR -- InfluxDB: Failed to contact host localhost: #<Errno::ECONNREFUSED: Failed to open TCP connection to localhost:8086 (Connection refused - connect(2) for "localhost" port 8086)> - retrying in 0.08s.
630
+ E, [2016-08-31T23:55:18.440422 #23476] ERROR -- InfluxDB: Failed to contact host localhost: #<Errno::ECONNREFUSED: Failed to open TCP connection to localhost:8086 (Connection refused - connect(2) for "localhost" port 8086)> - retrying in 0.16s.
631
+ E, [2016-08-31T23:55:18.600936 #23476] ERROR -- InfluxDB: Failed to contact host localhost: #<Errno::ECONNREFUSED: Failed to open TCP connection to localhost:8086 (Connection refused - connect(2) for "localhost" port 8086)> - retrying in 0.32s.
632
+ E, [2016-08-31T23:55:18.921740 #23476] ERROR -- InfluxDB: Failed to contact host localhost: #<Errno::ECONNREFUSED: Failed to open TCP connection to localhost:8086 (Connection refused - connect(2) for "localhost" port 8086)> - retrying in 0.64s.
633
+ E, [2016-08-31T23:55:19.562428 #23476] ERROR -- InfluxDB: Failed to contact host localhost: #<Errno::ECONNREFUSED: Failed to open TCP connection to localhost:8086 (Connection refused - connect(2) for "localhost" port 8086)> - retrying in 1.28s.
634
+ InfluxDB::ConnectionError: Tried 8 times to reconnect but failed.
635
+ ```
560
636
 
561
637
  ## Testing
562
638
 
data/influxdb.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency "rake"
26
26
  spec.add_development_dependency "bundler", "~> 1.3"
27
- spec.add_development_dependency "rspec", "~> 3.4.0"
28
- spec.add_development_dependency "webmock", "~> 1.24.2"
29
- spec.add_development_dependency "rubocop", "~> 0.39.0"
27
+ spec.add_development_dependency "rspec", "~> 3.5.0"
28
+ spec.add_development_dependency "webmock", "~> 2.1.0"
29
+ spec.add_development_dependency "rubocop", "~> 0.41.2"
30
30
  end
@@ -52,7 +52,9 @@ module InfluxDB
52
52
  http = setup_ssl(http)
53
53
  yield http
54
54
 
55
- rescue Timeout::Error, *InfluxDB::NET_HTTP_EXCEPTIONS => e
55
+ rescue *InfluxDB::NON_RECOVERABLE_EXCEPTIONS => e
56
+ raise InfluxDB::ConnectionError, InfluxDB::NON_RECOVERABLE_MESSAGE
57
+ rescue Timeout::Error, *InfluxDB::RECOVERABLE_EXCEPTIONS => e
56
58
  retry_count += 1
57
59
  if (config.retry == -1 || retry_count <= config.retry) && !stopped?
58
60
  log :error, "Failed to contact host #{host}: #{e.inspect} - retrying in #{delay}s."
@@ -20,9 +20,12 @@ module InfluxDB # :nodoc:
20
20
  class QueryError < Error
21
21
  end
22
22
 
23
+ # When executing queries via HTTP, some errors can more or less safely
24
+ # be ignored and we can retry the query again. This following
25
+ # exception classes shall be deemed as "safe".
26
+ #
23
27
  # Taken from: https://github.com/lostisland/faraday/blob/master/lib/faraday/adapter/net_http.rb
24
- NET_HTTP_EXCEPTIONS = [
25
- EOFError,
28
+ RECOVERABLE_EXCEPTIONS = [
26
29
  Errno::ECONNABORTED,
27
30
  Errno::ECONNREFUSED,
28
31
  Errno::ECONNRESET,
@@ -33,7 +36,17 @@ module InfluxDB # :nodoc:
33
36
  Net::HTTPHeaderSyntaxError,
34
37
  Net::ProtocolError,
35
38
  SocketError,
36
- Zlib::GzipFile::Error,
37
39
  (OpenSSL::SSL::SSLError if defined?(OpenSSL))
38
40
  ].compact.freeze
41
+
42
+ # Exception classes which hint to a larger problem on the server side,
43
+ # like insuffient resources. If we encouter on of the following, wo
44
+ # _don't_ retry a query but escalate it upwards.
45
+ NON_RECOVERABLE_EXCEPTIONS = [
46
+ EOFError,
47
+ Zlib::Error
48
+ ].freeze
49
+
50
+ NON_RECOVERABLE_MESSAGE = "The server has sent incomplete data" \
51
+ " (insufficient resources are a possible cause).".freeze
39
52
  end
@@ -3,8 +3,9 @@ module InfluxDB
3
3
  module RetentionPolicy # :nodoc:
4
4
  def create_retention_policy(name, database, duration, replication, default = false)
5
5
  execute(
6
- "CREATE RETENTION POLICY \"#{name}\" ON #{database} "\
7
- "DURATION #{duration} REPLICATION #{replication}#{default ? ' DEFAULT' : ''}")
6
+ "CREATE RETENTION POLICY \"#{name}\" ON #{database} " \
7
+ "DURATION #{duration} REPLICATION #{replication}#{default ? ' DEFAULT' : ''}"
8
+ )
8
9
  end
9
10
 
10
11
  def list_retention_policies(database)
@@ -24,8 +25,9 @@ module InfluxDB
24
25
 
25
26
  def alter_retention_policy(name, database, duration, replication, default = false)
26
27
  execute(
27
- "ALTER RETENTION POLICY \"#{name}\" ON #{database} "\
28
- "DURATION #{duration} REPLICATION #{replication}#{default ? ' DEFAULT' : ''}")
28
+ "ALTER RETENTION POLICY \"#{name}\" ON #{database} " \
29
+ "DURATION #{duration} REPLICATION #{replication}#{default ? ' DEFAULT' : ''}"
30
+ )
29
31
  end
30
32
  end
31
33
  end
@@ -1,3 +1,3 @@
1
1
  module InfluxDB # :nodoc:
2
- VERSION = "0.3.8".freeze
2
+ VERSION = "0.3.9".freeze
3
3
  end
@@ -17,7 +17,7 @@ describe InfluxDB::Client do
17
17
  let(:query) { "SELECT value FROM requests_per_minute WHERE time > 1437019900" }
18
18
  let(:response) do
19
19
  { "results" => [{ "series" => [{ "name" => "requests_per_minute",
20
- "columns" => %w( time value ) }] }] }
20
+ "columns" => %w(time value) }] }] }
21
21
  end
22
22
 
23
23
  before do
@@ -20,7 +20,7 @@ describe InfluxDB::Client do
20
20
 
21
21
  let(:response) do
22
22
  { "results" => [{ "series" => [{ "name" => "requests_per_minute",
23
- "columns" => %w( time value ) }] }] }
23
+ "columns" => %w(time value) }] }] }
24
24
  end
25
25
 
26
26
  before do
@@ -22,16 +22,19 @@ describe InfluxDB::Client do
22
22
  context "with basic auth" do
23
23
  let(:args) { { auth_method: 'basic_auth' } }
24
24
 
25
- let(:stub_url) { "http://username:password@influxdb.test:9999/" }
26
- let(:url) { subject.send(:full_url, '/') }
25
+ let(:credentials) { "username:password" }
26
+ let(:auth_header) { { "Authorization" => "Basic " + Base64.encode64(credentials).chomp } }
27
+
28
+ let(:stub_url) { "http://influxdb.test:9999/" }
29
+ let(:url) { subject.send(:full_url, '/') }
27
30
 
28
31
  it "GET" do
29
- stub_request(:get, stub_url).to_return(body: '[]')
32
+ stub_request(:get, stub_url).with(headers: auth_header).to_return(body: '[]')
30
33
  expect(subject.get(url, parse: true)).to eq []
31
34
  end
32
35
 
33
36
  it "POST" do
34
- stub_request(:post, stub_url).to_return(status: 204)
37
+ stub_request(:post, stub_url).with(headers: auth_header).to_return(status: 204)
35
38
  expect(subject.post(url, {})).to be_a(Net::HTTPNoContent)
36
39
  end
37
40
  end
@@ -48,7 +48,7 @@ RSpec.describe InfluxDB::Query::Builder do
48
48
  let(:query) { "SELECT value FROM rpm WHERE time > %{1}" }
49
49
  let(:params) { [] }
50
50
 
51
- it { expect { subject }.to raise_error(/key\{1\} not found/) }
51
+ it { expect { subject }.to raise_error(/key.1. not found/) }
52
52
  end
53
53
 
54
54
  context "extra parameters" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Persen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-31 00:00:00.000000000 Z
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -72,42 +72,42 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 3.4.0
75
+ version: 3.5.0
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: 3.4.0
82
+ version: 3.5.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: webmock
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.24.2
89
+ version: 2.1.0
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 1.24.2
96
+ version: 2.1.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.39.0
103
+ version: 0.41.2
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.39.0
110
+ version: 0.41.2
111
111
  description: This is the official Ruby library for InfluxDB.
112
112
  email:
113
113
  - influxdb@googlegroups.com