influxdb-api 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/.travis.yml +14 -0
- data/README.md +2 -0
- data/influxdb/Dockerfile.0.7.3 +8 -0
- data/influxdb/Dockerfile.0.8.3 +8 -0
- data/influxdb/Dockerfile.0.8.8 +8 -0
- data/lib/influxdb/api.rb +3 -0
- data/lib/influxdb/api/client.rb +5 -1
- data/lib/influxdb/api/database.rb +14 -2
- data/lib/influxdb/api/namespaces/base.rb +7 -0
- data/lib/influxdb/api/namespaces/cluster_admins.rb +4 -0
- data/lib/influxdb/api/namespaces/continuous_queries.rb +28 -4
- data/lib/influxdb/api/namespaces/databases.rb +4 -0
- data/lib/influxdb/api/namespaces/series.rb +3 -0
- data/lib/influxdb/api/namespaces/shards.rb +15 -0
- data/lib/influxdb/api/namespaces/users.rb +7 -0
- data/lib/influxdb/api/server_version.rb +6 -2
- data/lib/influxdb/api/version.rb +1 -1
- data/spec/intergrations/cluster_admins_spec.rb +75 -0
- data/spec/intergrations/continuous_queries_spec.rb +106 -0
- data/spec/intergrations/databases_spec.rb +68 -0
- data/spec/intergrations/series_spec.rb +104 -0
- data/spec/intergrations/servers_spec.rb +35 -0
- data/spec/intergrations/shard_spaces_spec.rb +126 -0
- data/spec/intergrations/shards_spec.rb +85 -0
- data/spec/intergrations/users_0_7_3_spec.rb +104 -0
- data/spec/intergrations/users_spec.rb +124 -0
- data/spec/lib/influxdb/api/database_spec.rb +32 -4
- data/spec/lib/influxdb/api/namespaces/{continuous_queries_spec.rb → continuous_queries/api_spec.rb} +2 -2
- data/spec/lib/influxdb/api/namespaces/continuous_queries/sql_spec.rb +41 -0
- data/spec/lib/influxdb/api/server_version_spec.rb +1 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/support/version_resolver.rb +56 -0
- metadata +30 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57e3e37757669373a7d4fe649bfb8eb505fc3141
|
4
|
+
data.tar.gz: 9bdf91d6fab7e146290bc6b8bbd71924158de63c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db81efe8613a8ed544c3857ce29ae448e94efca422dfbbe90565ecbb6856cd6185c32191e2d872691380324d1ade40b2a2ab59355104e763adceb040fde9a56c
|
7
|
+
data.tar.gz: 77d6bad87f7374fdf7d5f8894972cf0a9aa491f72e4d4941739719d08bc29f10ac2c5154a147c4a3fa5880129008c8ec74744aca466258a2f30bfd62a191a9d2
|
data/.travis.yml
CHANGED
@@ -4,3 +4,17 @@ rvm:
|
|
4
4
|
- 2.0.0
|
5
5
|
- 2.1.1
|
6
6
|
- rbx-2
|
7
|
+
env:
|
8
|
+
- INFLUXDB_VERSION=0.7.3
|
9
|
+
- INFLUXDB_VERSION=0.8.3
|
10
|
+
- INFLUXDB_VERSION=0.8.8
|
11
|
+
- INFLUXDB_VERSION=latest
|
12
|
+
before_install:
|
13
|
+
- wget http://s3.amazonaws.com/influxdb/influxdb_${INFLUXDB_VERSION}_amd64.deb
|
14
|
+
- sudo dpkg -i influxdb_${INFLUXDB_VERSION}_amd64.deb
|
15
|
+
- sudo /etc/init.d/influxdb start
|
16
|
+
- sleep 8
|
17
|
+
matrix:
|
18
|
+
allow_failures:
|
19
|
+
- rvm: rbx-2
|
20
|
+
- env: "INFLUXDB_VERSION=latest"
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/undr/influxdb-api) [](https://codeclimate.com/github/undr/influxdb-api) [](http://badge.fury.io/rb/influxdb-api)
|
4
4
|
|
5
|
+
It tested on influxdb till 0.8.3.
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
data/lib/influxdb/api.rb
CHANGED
data/lib/influxdb/api/client.rb
CHANGED
@@ -18,10 +18,14 @@ module Influxdb
|
|
18
18
|
response = with_retry(path, params) do |connection, url|
|
19
19
|
connection.basic_auth(config.user, config.password)
|
20
20
|
headers = { 'Content-Type' => 'application/json' }
|
21
|
+
body = body ? convert_to_json(body) : nil
|
21
22
|
|
22
|
-
|
23
|
+
logger.debug "=> #{method.upcase} #{url} #{body}" if logger
|
24
|
+
connection.run_request(method, url, body, headers, &block)
|
23
25
|
end
|
24
26
|
|
27
|
+
logger.debug "<= [#{response.status}] #{response.body}" if logger
|
28
|
+
|
25
29
|
raise_transport_error(response) if response.status.to_i >= 300
|
26
30
|
|
27
31
|
json = config.serializer.load(response.body) if response.headers && response.headers["content-type"] =~ /json/
|
@@ -17,11 +17,23 @@ module Influxdb
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def continuous_queries
|
20
|
-
@continuous_queries ||=
|
20
|
+
@continuous_queries ||= if client.version > '0.8.3'
|
21
|
+
Namespaces::ContinuousQueries::Sql.new(client, name)
|
22
|
+
else
|
23
|
+
Namespaces::ContinuousQueries::Api.new(client, name)
|
24
|
+
end
|
21
25
|
end
|
22
26
|
|
23
27
|
def shard_spaces
|
24
|
-
@shard_spaces ||=
|
28
|
+
@shard_spaces ||= begin
|
29
|
+
version = client.version
|
30
|
+
raise(
|
31
|
+
UnsupportedFeature,
|
32
|
+
"Shard space's API is supported only after 0.7.3 version. Current is #{version.to_s(:mini)}"
|
33
|
+
) if version < '0.8.3'
|
34
|
+
|
35
|
+
Namespaces::ShardSpaces.new(client, name)
|
36
|
+
end
|
25
37
|
end
|
26
38
|
end
|
27
39
|
end
|
@@ -34,6 +34,13 @@ module Influxdb
|
|
34
34
|
|
35
35
|
protected
|
36
36
|
|
37
|
+
def return_false_if_doesnt_exist(type)
|
38
|
+
yield
|
39
|
+
rescue Influxdb::Api::Client::Errors::BadRequest => e
|
40
|
+
raise e unless e.message =~ /#{type} (.*) doesn\'t exist/
|
41
|
+
false
|
42
|
+
end
|
43
|
+
|
37
44
|
def resource_path(*args)
|
38
45
|
[path_prefix, self.class._resource_path, path_postfix, args].compact.flatten.join(?/).squeeze(?/)
|
39
46
|
end
|
@@ -1,11 +1,35 @@
|
|
1
1
|
module Influxdb
|
2
2
|
module Api
|
3
3
|
module Namespaces
|
4
|
-
|
5
|
-
|
4
|
+
module ContinuousQueries
|
5
|
+
class Api < WithDatabase
|
6
|
+
resource_path '/continuous_queries'
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
def create(query)
|
9
|
+
super(query: query)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Sql < WithDatabase
|
14
|
+
def create(query)
|
15
|
+
series.execute(query)
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def all
|
20
|
+
series.execute('LIST CONTINUOUS QUERIES')['continuous queries']
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(id)
|
24
|
+
series.execute("DROP CONTINUOUS QUERY #{id}")
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def series
|
31
|
+
client.databases(database_name).series
|
32
|
+
end
|
9
33
|
end
|
10
34
|
end
|
11
35
|
end
|
@@ -35,6 +35,9 @@ module Influxdb
|
|
35
35
|
params = { q: query_string }
|
36
36
|
params[:time_precision] = time_precision if time_precision
|
37
37
|
perform_get(resource_path, params)
|
38
|
+
rescue Influxdb::Api::Client::Errors::BadRequest => e
|
39
|
+
raise e unless e.message =~ /Couldn\'t look up columns/
|
40
|
+
[]
|
38
41
|
end
|
39
42
|
|
40
43
|
private
|
@@ -4,6 +4,21 @@ module Influxdb
|
|
4
4
|
class Shards < Base
|
5
5
|
resource_path '/cluster/shards'
|
6
6
|
|
7
|
+
def create(attributes)
|
8
|
+
attributes['startTime'] = cast_datetime(attributes['startTime']) if attributes['startTime']
|
9
|
+
attributes[:startTime] = cast_datetime(attributes[:startTime]) if attributes[:startTime]
|
10
|
+
attributes['endTime'] = cast_datetime(attributes['endTime']) if attributes['endTime']
|
11
|
+
attributes[:endTime] = cast_datetime(attributes[:endTime]) if attributes[:endTime]
|
12
|
+
|
13
|
+
super(attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def cast_datetime(value)
|
19
|
+
value = value.to_i if value && !value.is_a?(Integer)
|
20
|
+
value
|
21
|
+
end
|
7
22
|
end
|
8
23
|
end
|
9
24
|
end
|
@@ -6,12 +6,19 @@ module Influxdb
|
|
6
6
|
|
7
7
|
def find(name)
|
8
8
|
perform_get(resource_path(name))
|
9
|
+
rescue Influxdb::Api::Client::Errors::BadRequest => e
|
10
|
+
raise e unless e.message =~ /Invalid username/
|
11
|
+
nil
|
9
12
|
end
|
10
13
|
|
11
14
|
def update(name, attributes)
|
12
15
|
perform_post(resource_path(name), {}, attributes)
|
13
16
|
true
|
14
17
|
end
|
18
|
+
|
19
|
+
def delete(*_)
|
20
|
+
return_false_if_doesnt_exist('User'){ super }
|
21
|
+
end
|
15
22
|
end
|
16
23
|
end
|
17
24
|
end
|
@@ -34,8 +34,12 @@ module Influxdb
|
|
34
34
|
[major <=> other_major, minor <=> other_minor, patch <=> other_patch].detect{|c| c != 0 } || 0
|
35
35
|
end
|
36
36
|
|
37
|
-
def to_s
|
38
|
-
|
37
|
+
def to_s(format = :full)
|
38
|
+
if format == :mini
|
39
|
+
"#{major}.#{minor}.#{patch}"
|
40
|
+
else
|
41
|
+
source
|
42
|
+
end
|
39
43
|
end
|
40
44
|
|
41
45
|
def inspect
|
data/lib/influxdb/api/version.rb
CHANGED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'cluster_admins', integration: true do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
|
7
|
+
subject{ client.cluster_admins }
|
8
|
+
|
9
|
+
before{ subject.all.each{|u| subject.delete(u['name']) if u['name'] != 'root' } }
|
10
|
+
after{ subject.all.each{|u| subject.delete(u['name']) if u['name'] != 'root' } }
|
11
|
+
|
12
|
+
describe '.all' do
|
13
|
+
it 'returns list of users' do
|
14
|
+
expect(subject.all).to eq([{ 'name' => 'root' }])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.create' do
|
19
|
+
it 'creates cluster admin' do
|
20
|
+
subject.create(name: 'username', password: 'pass')
|
21
|
+
expect(subject.all).to match_array([{ 'name' => 'root' }, { 'name' => 'username' }])
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'when there is user with same name' do
|
25
|
+
it 'raises error' do
|
26
|
+
expect{ subject.create(name: 'root', password: 'pass') }.to raise_error(
|
27
|
+
Influxdb::Api::Client::Errors::BadRequest, '[400] User root already exists'
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.update' do
|
34
|
+
context 'when user exists' do
|
35
|
+
let(:new_client){ Influxdb::Api::Client.new(new_config) }
|
36
|
+
let(:new_config) do
|
37
|
+
Influxdb::Api::Configuration.new.tap do |c|
|
38
|
+
c.user = 'username'
|
39
|
+
c.password = 'pass1'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
before{ subject.create(name: 'username', password: 'pass') }
|
44
|
+
|
45
|
+
it 'updates user attributes' do
|
46
|
+
expect{ subject.update('username', password: 'pass1') }.not_to raise_error
|
47
|
+
expect{ new_client.version }.not_to raise_error
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when user does not exist' do
|
52
|
+
it 'raises error' do
|
53
|
+
expect{ subject.update('username', password: 'pass') }.to raise_error(
|
54
|
+
Influxdb::Api::Client::Errors::BadRequest, '[400] Invalid user name username'
|
55
|
+
)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '.delete' do
|
61
|
+
context 'when user does not exist' do
|
62
|
+
it 'returns false' do
|
63
|
+
expect(subject.delete('username')).to be_falsy
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'when user exists' do
|
68
|
+
before{ subject.create(name: 'username', password: 'pass') }
|
69
|
+
|
70
|
+
it 'removes user and returns true' do
|
71
|
+
expect(subject.delete('username')).to be_truthy
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'continuous_queries', integration: true do
|
4
|
+
let(:config){ Influxdb::Api::Configuration.new }
|
5
|
+
let(:client){ Influxdb::Api::Client.new(config) }
|
6
|
+
let(:continuous_query1){ 'select MEAN(user) as user_mean from cpu group by time(1m) into cpu.1m.user_mean' }
|
7
|
+
let(:continuous_query2){ 'select MAX(user) as user_max from cpu group by time(1m) into cpu.1m.user_max' }
|
8
|
+
let(:continuous_query1_088){ 'select MEAN(user) as user_mean from "cpu" group by time(1m) into cpu.1m.user_mean' }
|
9
|
+
let(:continuous_query2_088){ 'select MAX(user) as user_max from "cpu" group by time(1m) into cpu.1m.user_max' }
|
10
|
+
|
11
|
+
subject{ client.databases('db_name').continuous_queries }
|
12
|
+
|
13
|
+
before do
|
14
|
+
client.databases.create('db_name')
|
15
|
+
subject.all.each{|q| subject.delete(q['id']) }
|
16
|
+
end
|
17
|
+
|
18
|
+
after{ client.databases.delete('db_name') }
|
19
|
+
|
20
|
+
describe '.all' do
|
21
|
+
context 'when there are no continuous queries' do
|
22
|
+
it 'returns empty array' do
|
23
|
+
expect(subject.all).to eq([])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when there are some continuous queries', version: '<=0.8.3' do
|
28
|
+
before do
|
29
|
+
subject.create(continuous_query1)
|
30
|
+
subject.create(continuous_query2)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns the list of users' do
|
34
|
+
expect(subject.all).to match_array([
|
35
|
+
{ 'id' => 1, 'query' => continuous_query1 }, { 'id' => 2, 'query' => continuous_query2 }
|
36
|
+
])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when there are some continuous queries', version: '>0.8.3' do
|
41
|
+
before do
|
42
|
+
subject.create(continuous_query1)
|
43
|
+
subject.create(continuous_query2)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'returns the list of users' do
|
47
|
+
expect(subject.all).to match_array([
|
48
|
+
{ 'time' => 0, 'id' => 1, 'query' => continuous_query1_088 },
|
49
|
+
{ 'time' => 0, 'id' => 2, 'query' => continuous_query2_088 }
|
50
|
+
])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '.create' do
|
56
|
+
it 'creates a new query', version: '<=0.8.3' do
|
57
|
+
subject.create(continuous_query1)
|
58
|
+
expect(subject.all).to eq([{ 'id' => 1, 'query' => continuous_query1 }])
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'creates a new query', version: '>0.8.3' do
|
62
|
+
subject.create(continuous_query1)
|
63
|
+
expect(subject.all).to eq([{ 'time' => 0, 'id' => 1, 'query' => continuous_query1_088 }])
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when there is the same query', version: '<=0.8.3' do
|
67
|
+
before{ subject.create(continuous_query1) }
|
68
|
+
|
69
|
+
it 'creates one more' do
|
70
|
+
subject.create(continuous_query1)
|
71
|
+
expect(subject.all).to match_array([
|
72
|
+
{ 'id' => 1, 'query' => continuous_query1 }, { 'id' => 2, 'query' => continuous_query1 }
|
73
|
+
])
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when there is the same query', version: '>0.8.3' do
|
78
|
+
before{ subject.create(continuous_query1) }
|
79
|
+
|
80
|
+
it 'creates one more' do
|
81
|
+
subject.create(continuous_query1)
|
82
|
+
expect(subject.all).to match_array([
|
83
|
+
{ 'time' => 0, 'id' => 1, 'query' => continuous_query1_088 },
|
84
|
+
{ 'time' => 0, 'id' => 2, 'query' => continuous_query1_088 }
|
85
|
+
])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe '.delete' do
|
91
|
+
context 'when query does not exist' do
|
92
|
+
it 'returns true' do
|
93
|
+
expect(subject.delete(1)).to be_truthy
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when query exists' do
|
98
|
+
before{ subject.create(continuous_query1) }
|
99
|
+
|
100
|
+
it 'removes db and returns true' do
|
101
|
+
expect(subject.delete(1)).to be_truthy
|
102
|
+
expect(subject.all).to eq([])
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|