influxdb 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.travis.yml CHANGED
@@ -4,6 +4,7 @@ language: ruby
4
4
  before_install:
5
5
  - gem update bundler
6
6
  rvm:
7
+ - 1.9.3
7
8
  - 2.0.0
8
9
  - 2.1.10
9
10
  - 2.2.4
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  For the full commit log, [see here](https://github.com/influxdata/influxdb-ruby/commits/master).
4
4
 
5
+ ## Unreleased changes
6
+
7
+ - None.
8
+
9
+ ## v0.3.4, released 2016-06-07
10
+
11
+ - Added resample options to `Client#create_continuous_query` (#149).
12
+ - Fixed resample options to be Ruby 1.9 compatible (#150, @SebastianCoetzee).
13
+ - Mentioned in README, that 0.3.x series is the last one to support Ruby 1.9
14
+
15
+ ## v0.3.3, released 2016-06-06 (yanked)
16
+
17
+ - Added resample options to `Client#create_continuous_query` (#149).
18
+
5
19
  ## v0.3.2, released 2016-06-02
6
20
 
7
21
  - Added config option to authenticate without credentials (#146, @pmenglund).
data/README.md CHANGED
@@ -1,23 +1,34 @@
1
- influxdb-ruby
2
- =============
1
+ # influxdb-ruby
3
2
 
4
3
  [![Build Status](https://travis-ci.org/influxdata/influxdb-ruby.svg?branch=master)](https://travis-ci.org/influxdata/influxdb-ruby)
5
4
 
6
- The official ruby client library for [InfluxDB](https://influxdata.com/time-series-platform/influxdb/). Maintained by [@toddboom](https://github.com/toddboom) and [@dmke](https://github.com/dmke).
5
+ The official Ruby client library for [InfluxDB](https://influxdata.com/time-series-platform/influxdb/).
6
+ Maintained by [@toddboom](https://github.com/toddboom) and [@dmke](https://github.com/dmke).
7
7
 
8
- > **Support for InfluxDB v0.8.x is now deprecated**. The final version of this library that will support the older InfluxDB interface is `v0.1.9`, which is available as a gem and tagged on this repository. If you're reading this message, then you should only expect support for InfluxDB v0.9.1 and higher.
8
+ ## Platform support
9
9
 
10
- Install
11
- -------
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.
13
+ >
14
+ > If you're reading this message, then you should only expect support for InfluxDB v0.9.1
15
+ > and higher.
16
+
17
+ ## Ruby support
18
+
19
+ This gem should work with Ruby 1.9+, but starting with v0.4, we'll likely drop Ruby 1.9 support.
20
+
21
+ ## Install
12
22
 
13
23
  ```
14
24
  $ [sudo] gem install influxdb
15
25
  ```
16
26
 
17
- Or add it to your `Gemfile`, etc.
27
+ Or add it to your `Gemfile`, and run `bundle install`.
18
28
 
19
- Usage
20
- -----
29
+ ## Usage
30
+
31
+ ### Creating a client
21
32
 
22
33
  Connecting to a single host:
23
34
 
@@ -37,6 +48,8 @@ require 'influxdb'
37
48
  influxdb = InfluxDB::Client.new hosts: ["influxdb1.domain.com", "influxdb2.domain.com"]
38
49
  ```
39
50
 
51
+ ### Administrative tasks
52
+
40
53
  Create a database:
41
54
 
42
55
  ``` ruby
@@ -139,6 +152,8 @@ username = 'foobar'
139
152
  influxdb.revoke_cluster_admin_privileges(username)
140
153
  ```
141
154
 
155
+ ### Continuous Queries
156
+
142
157
  List continuous queries of a database:
143
158
 
144
159
  ``` ruby
@@ -157,6 +172,12 @@ query = 'SELECT COUNT(name) INTO clicksCount_1h FROM clicks GROUP BY time(1h)'
157
172
  influxdb.create_continuous_query(name, database, query)
158
173
  ```
159
174
 
175
+ Additionally, you can specify the resample interval and the time range over which the CQ runs:
176
+
177
+ ``` ruby
178
+ influxdb.create_continuous_query(name, database, query, resample_every: "10m", resample_for: "65m")
179
+ ```
180
+
160
181
  Delete a continuous query from a database:
161
182
 
162
183
  ``` ruby
@@ -166,6 +187,8 @@ name = 'clicks_count'
166
187
  influxdb.delete_continuous_query(name, database)
167
188
  ```
168
189
 
190
+ ### Retention Policies
191
+
169
192
  List retention policies of a database:
170
193
 
171
194
  ``` ruby
@@ -205,6 +228,8 @@ replication = 2
205
228
  influxdb.alter_retention_policy(name, database, duration, replication)
206
229
  ```
207
230
 
231
+ ### Writing data
232
+
208
233
  Write some data:
209
234
 
210
235
  ``` ruby
@@ -397,6 +422,8 @@ data = {
397
422
  influxdb.write_point(name, data)
398
423
  ```
399
424
 
425
+ ### Reading data
426
+
400
427
  Querying:
401
428
 
402
429
  ``` ruby
@@ -460,16 +487,15 @@ end
460
487
  # time_series_1 [ {"region"=>"us"} ] => {"columns"=>["time", "count", "value"], "values"=>[["2015-07-09T09:02:54Z", 55, 0.4343]]}
461
488
  ```
462
489
 
463
- By default, InfluxDB::Client will keep trying to connect to the database when it gets connection denied, if you want to retry a finite number of times
464
- (or disable retries altogether), you should pass the `:retry`
465
- value. `:retry` can be either `true`, `false` or an `Integer` to retry
466
- infinite times, disable retries or retry a finite number of times,
467
- respectively. `0` is equivalent to `false`
490
+ By default, InfluxDB::Client will keep trying to connect to the database when it gets connection denied,
491
+ if you want to retry a finite number of times (or disable retries altogether), you should pass the `:retry`
492
+ value.
468
493
 
469
- ```
470
- > require 'influxdb'
471
- => true
494
+ `:retry` can be either `true`, `false` or an `Integer` to retry infinite times, disable retries or retry
495
+ a finite number of times, respectively. `0` is equivalent to `false`
472
496
 
497
+ ```
498
+ $ irb -r influxdb
473
499
  > influxdb = InfluxDB::Client.new 'database', :retry => 4
474
500
  => #<InfluxDB::Client:0x00000002bb5ce0 @database="database", @hosts=["localhost"],
475
501
  @port=8086, @username="root", @password="root", @use_ssl=false,
@@ -490,17 +516,28 @@ E, [2014-06-02T11:04:13.510853 #22825] ERROR -- : [InfluxDB] Failed to
490
516
  contact host localhost: #<SocketError: getaddrinfo: Name or service not known> -
491
517
  retrying in 0.08s.
492
518
  SocketError: Tried 4 times to reconnect but failed.
493
-
494
519
  ```
495
- If you pass `:retry => -1` it will keep trying forever
496
- until it gets the connection.
497
520
 
498
- Testing
499
- -------
521
+ If you pass `:retry => -1` it will keep trying forever until it gets the connection.
522
+
523
+ ## Testing
500
524
 
501
525
  ```
502
526
  git clone git@github.com:influxdata/influxdb-ruby.git
503
527
  cd influxdb-ruby
504
528
  bundle
505
- bundle exec rake
529
+ bundle exec rake spec
530
+ bundle exec rake rubocop
506
531
  ```
532
+
533
+ ## Contributing
534
+
535
+ - Fork this repository on GitHub.
536
+ - Make your changes.
537
+ - Add tests.
538
+ - Add an entry in the `CHANGELOG.md` in the "unreleased" section on top.
539
+ - Run the tests: `bundle exec rake`.
540
+ - Run Rubocop: `bundle exec rubocop`.
541
+ - Send a pull request.
542
+ - Please rebase against the master branch.
543
+ - If your changes look good, we'll merge them.
@@ -10,8 +10,16 @@ module InfluxDB
10
10
  .map { |v| { 'name' => v.first, 'query' => v.last } }
11
11
  end
12
12
 
13
- def create_continuous_query(name, database, query)
14
- clause = ["CREATE CONTINUOUS QUERY #{name} ON #{database} BEGIN", query, "END"].join("\n")
13
+ def create_continuous_query(name, database, query, options = {})
14
+ clause = ["CREATE CONTINUOUS QUERY", name, "ON", database]
15
+
16
+ if options[:resample_every] || options[:resample_for]
17
+ clause << "RESAMPLE"
18
+ clause << "EVERY #{options[:resample_every]}" if options[:resample_every]
19
+ clause << "FOR #{options[:resample_for]}" if options[:resample_for]
20
+ end
21
+
22
+ clause = clause.join(" ") << " BEGIN\n" << query << "\nEND"
15
23
  execute(clause)
16
24
  end
17
25
 
@@ -1,3 +1,3 @@
1
1
  module InfluxDB # :nodoc:
2
- VERSION = "0.3.2".freeze
2
+ VERSION = "0.3.4".freeze
3
3
  end
@@ -45,13 +45,24 @@ describe InfluxDB::Client do
45
45
  end
46
46
 
47
47
  describe "#create_continuous_query" do
48
- let(:name) { "event_counts_per_10m_by_type" }
49
- let(:database) { "testdb" }
50
- let(:query) do
51
- "SELECT COUNT(type) INTO typeCount_10m_byType FROM events GROUP BY time(10m), type"
52
- end
48
+ let(:name) { "event_counts_per_10m_by_type" }
49
+ let(:database) { "testdb" }
50
+ let(:query) { "SELECT COUNT(type) INTO typeCount_10m_byType FROM events GROUP BY time(10m), type" }
51
+ let(:every_interval) { nil }
52
+ let(:for_interval) { nil }
53
+
53
54
  let(:clause) do
54
- ["CREATE CONTINUOUS QUERY #{name} ON #{database} BEGIN", query, "END"].join("\n")
55
+ c = "CREATE CONTINUOUS QUERY #{name} ON #{database}"
56
+
57
+ if every_interval && for_interval
58
+ c << " RESAMPLE EVERY #{every_interval} FOR #{for_interval}"
59
+ elsif every_interval
60
+ c << " RESAMPLE EVERY #{every_interval}"
61
+ elsif for_interval
62
+ c << " RESAMPLE FOR #{for_interval}"
63
+ end
64
+
65
+ c << " BEGIN\n#{query}\nEND"
55
66
  end
56
67
 
57
68
  before do
@@ -60,8 +71,37 @@ describe InfluxDB::Client do
60
71
  )
61
72
  end
62
73
 
63
- it "should GET to create a new continuous query" do
64
- expect(subject.create_continuous_query(name, database, query)).to be_a(Net::HTTPOK)
74
+ context "without resampling" do
75
+ it "should GET to create a new continuous query" do
76
+ expect(subject.create_continuous_query(name, database, query)).to be_a(Net::HTTPOK)
77
+ end
78
+ end
79
+
80
+ context "with resampling" do
81
+ context "EVERY <interval>" do
82
+ let(:every_interval) { "10m" }
83
+
84
+ it "should GET to create a new continuous query" do
85
+ expect(subject.create_continuous_query(name, database, query, resample_every: every_interval)).to be_a(Net::HTTPOK)
86
+ end
87
+ end
88
+
89
+ context "FOR <interval>" do
90
+ let(:for_interval) { "7d" }
91
+
92
+ it "should GET to create a new continuous query" do
93
+ expect(subject.create_continuous_query(name, database, query, resample_for: for_interval)).to be_a(Net::HTTPOK)
94
+ end
95
+ end
96
+
97
+ context "EVERY <interval> FOR <interval>" do
98
+ let(:every_interval) { "5m" }
99
+ let(:for_interval) { "3w" }
100
+
101
+ it "should GET to create a new continuous query" do
102
+ expect(subject.create_continuous_query(name, database, query, resample_for: for_interval, resample_every: every_interval)).to be_a(Net::HTTPOK)
103
+ end
104
+ end
65
105
  end
66
106
  end
67
107
 
@@ -119,13 +119,13 @@ describe InfluxDB::Client do
119
119
 
120
120
  before do
121
121
  stub_request(:post, "http://influxdb.test:9999/write").with(
122
- query: { u: "username", p: "password", precision: 'm', db: database },
122
+ query: { u: "username", p: "password", precision: 'ms', db: database },
123
123
  headers: { "Content-Type" => "application/octet-stream" },
124
124
  body: body
125
125
  ).to_return(status: 204)
126
126
  end
127
127
  it "should POST multiple points" do
128
- expect(subject.write_points(data, 'm')).to be_a(Net::HTTPNoContent)
128
+ expect(subject.write_points(data, 'ms')).to be_a(Net::HTTPNoContent)
129
129
  end
130
130
  end
131
131
 
metadata CHANGED
@@ -1,97 +1,126 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: influxdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Todd Persen
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-06-02 00:00:00.000000000 Z
12
+ date: 2016-06-07 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: json
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - ">="
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - ">="
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: cause
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
25
44
  - !ruby/object:Gem::Version
26
45
  version: '0'
27
46
  - !ruby/object:Gem::Dependency
28
47
  name: rake
29
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
30
50
  requirements:
31
- - - ">="
51
+ - - ! '>='
32
52
  - !ruby/object:Gem::Version
33
53
  version: '0'
34
54
  type: :development
35
55
  prerelease: false
36
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
37
58
  requirements:
38
- - - ">="
59
+ - - ! '>='
39
60
  - !ruby/object:Gem::Version
40
61
  version: '0'
41
62
  - !ruby/object:Gem::Dependency
42
63
  name: bundler
43
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
44
66
  requirements:
45
- - - "~>"
67
+ - - ~>
46
68
  - !ruby/object:Gem::Version
47
69
  version: '1.3'
48
70
  type: :development
49
71
  prerelease: false
50
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
51
74
  requirements:
52
- - - "~>"
75
+ - - ~>
53
76
  - !ruby/object:Gem::Version
54
77
  version: '1.3'
55
78
  - !ruby/object:Gem::Dependency
56
79
  name: rspec
57
80
  requirement: !ruby/object:Gem::Requirement
81
+ none: false
58
82
  requirements:
59
- - - "~>"
83
+ - - ~>
60
84
  - !ruby/object:Gem::Version
61
85
  version: 3.4.0
62
86
  type: :development
63
87
  prerelease: false
64
88
  version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
65
90
  requirements:
66
- - - "~>"
91
+ - - ~>
67
92
  - !ruby/object:Gem::Version
68
93
  version: 3.4.0
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: webmock
71
96
  requirement: !ruby/object:Gem::Requirement
97
+ none: false
72
98
  requirements:
73
- - - "~>"
99
+ - - ~>
74
100
  - !ruby/object:Gem::Version
75
101
  version: 1.24.2
76
102
  type: :development
77
103
  prerelease: false
78
104
  version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
79
106
  requirements:
80
- - - "~>"
107
+ - - ~>
81
108
  - !ruby/object:Gem::Version
82
109
  version: 1.24.2
83
110
  - !ruby/object:Gem::Dependency
84
111
  name: rubocop
85
112
  requirement: !ruby/object:Gem::Requirement
113
+ none: false
86
114
  requirements:
87
- - - "~>"
115
+ - - ~>
88
116
  - !ruby/object:Gem::Version
89
117
  version: 0.39.0
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
93
122
  requirements:
94
- - - "~>"
123
+ - - ~>
95
124
  - !ruby/object:Gem::Version
96
125
  version: 0.39.0
97
126
  description: This is the official Ruby library for InfluxDB.
@@ -101,9 +130,9 @@ executables: []
101
130
  extensions: []
102
131
  extra_rdoc_files: []
103
132
  files:
104
- - ".gitignore"
105
- - ".rubocop.yml"
106
- - ".travis.yml"
133
+ - .gitignore
134
+ - .rubocop.yml
135
+ - .travis.yml
107
136
  - CHANGELOG.md
108
137
  - Gemfile
109
138
  - LICENSE.txt
@@ -151,26 +180,33 @@ files:
151
180
  homepage: http://influxdb.org
152
181
  licenses:
153
182
  - MIT
154
- metadata: {}
155
183
  post_install_message:
156
184
  rdoc_options: []
157
185
  require_paths:
158
186
  - lib
159
187
  required_ruby_version: !ruby/object:Gem::Requirement
188
+ none: false
160
189
  requirements:
161
- - - ">="
190
+ - - ! '>='
162
191
  - !ruby/object:Gem::Version
163
192
  version: '0'
193
+ segments:
194
+ - 0
195
+ hash: 4505690428131411783
164
196
  required_rubygems_version: !ruby/object:Gem::Requirement
197
+ none: false
165
198
  requirements:
166
- - - ">="
199
+ - - ! '>='
167
200
  - !ruby/object:Gem::Version
168
201
  version: '0'
202
+ segments:
203
+ - 0
204
+ hash: 4505690428131411783
169
205
  requirements: []
170
206
  rubyforge_project:
171
- rubygems_version: 2.5.1
207
+ rubygems_version: 1.8.25
172
208
  signing_key:
173
- specification_version: 4
209
+ specification_version: 3
174
210
  summary: Ruby library for InfluxDB.
175
211
  test_files:
176
212
  - spec/influxdb/cases/async_client_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 9175c1e5dc3934144b01c90acf625770219d052b
4
- data.tar.gz: e06c8e8f3fa04429e58c97d4f4b2f30c0dcbc4da
5
- SHA512:
6
- metadata.gz: 0cd3923bcbf70d4aef40062fbec6b8e924403a3b83631861bb0dc71e7eaefdd53ffaa7d38935a289045d20e337b0531a48173e558079da5cadbcc9a52ea088be
7
- data.tar.gz: 9f2cca0b974e8fdb3342356645dbb75963cf03c23c672ed439566160ebbca8fbb76810fa46ceddfc943e0e0b65df62120afa9f12cbb2da9dcb898bba8819bfd1