influxdb-client 1.0.0.pre.144 → 1.0.0.pre.159
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -14
- data/influxdb-client.gemspec +2 -2
- data/lib/{influxdb → influxdb2}/client.rb +5 -5
- data/lib/{influxdb → influxdb2}/client/client.rb +2 -1
- data/lib/{influxdb → influxdb2}/client/influx_error.rb +1 -1
- data/lib/{influxdb → influxdb2}/client/point.rb +5 -5
- data/lib/{influxdb → influxdb2}/client/version.rb +1 -1
- data/lib/{influxdb → influxdb2}/client/write_api.rb +1 -1
- data/test/influxdb/client_test.rb +10 -10
- data/test/influxdb/point_test.rb +88 -88
- data/test/influxdb/write_api_integration_test.rb +9 -9
- data/test/influxdb/write_api_test.rb +63 -63
- data/test/test_helper.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ffb84415d36902228797e8a00d2ac07e8c6330bd6020fc313ab14cb4c2217ac
|
4
|
+
data.tar.gz: e9933199fb5be92f37cd26c933047cf630fb493ca246c1266436500686575561
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 110ad7524b27e5d686417f52d847c8e15a9616d3ee5f0da6adbab0eabaf2b847baa85457c987799e35cf861bbc3516830fb0ea6f69f4c1d4bccfade9b9e157f0
|
7
|
+
data.tar.gz: e5d5a833f9b0b9abdddf9f742ace87855032e8f3dfaa5ff109493ba259601fbed3f63d9be5d3afef989f16a8948bb3cb3c529ff5e74f69505c087f32799ac4f5
|
data/README.md
CHANGED
@@ -33,7 +33,7 @@ gem install influxdb-client --pre
|
|
33
33
|
Use **InfluxDB::Client** to create a client connected to a running InfluxDB 2 instance.
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
client =
|
36
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token')
|
37
37
|
```
|
38
38
|
|
39
39
|
#### Client Options
|
@@ -50,19 +50,19 @@ client = InfluxDB::Client.new('https://localhost:9999', 'my-token')
|
|
50
50
|
| use_ssl | Turn on/off SSL for HTTP communication | bool | true |
|
51
51
|
|
52
52
|
```ruby
|
53
|
-
client =
|
53
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
54
54
|
bucket: 'my-bucket',
|
55
55
|
org: 'my-org',
|
56
|
-
precision:
|
56
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
57
57
|
```
|
58
58
|
|
59
59
|
### Writing data
|
60
60
|
|
61
61
|
```ruby
|
62
|
-
client =
|
62
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
63
63
|
bucket: 'my-bucket',
|
64
64
|
org: 'my-org',
|
65
|
-
precision:
|
65
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
66
66
|
|
67
67
|
write_api = client.create_write_api
|
68
68
|
write_api.write(data: 'h2o,location=west value=33i 15')
|
@@ -72,20 +72,20 @@ write_api.write(data: 'h2o,location=west value=33i 15')
|
|
72
72
|
|
73
73
|
Configure default time precision:
|
74
74
|
```ruby
|
75
|
-
client =
|
75
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
76
76
|
bucket: 'my-bucket',
|
77
77
|
org: 'my-org',
|
78
|
-
precision:
|
78
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
79
79
|
```
|
80
80
|
|
81
81
|
Configure precision per write:
|
82
82
|
```ruby
|
83
|
-
client =
|
83
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
84
84
|
bucket: 'my-bucket',
|
85
85
|
org: 'my-org')
|
86
86
|
|
87
87
|
write_api = client.create_write_api
|
88
|
-
write_api.write(data: 'h2o,location=west value=33i 15', precision:
|
88
|
+
write_api.write(data: 'h2o,location=west value=33i 15', precision: InfluxDB2::WritePrecision::SECOND)
|
89
89
|
```
|
90
90
|
|
91
91
|
Allowed values for precision are:
|
@@ -98,7 +98,7 @@ Allowed values for precision are:
|
|
98
98
|
|
99
99
|
Default `bucket` and `organization` destination are configured via `InfluxDB::Client`:
|
100
100
|
```ruby
|
101
|
-
client =
|
101
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
102
102
|
bucket: 'my-bucket',
|
103
103
|
org: 'my-org')
|
104
104
|
```
|
@@ -106,7 +106,7 @@ client = InfluxDB::Client.new('https://localhost:9999', 'my-token',
|
|
106
106
|
but there is also possibility to override configuration per write:
|
107
107
|
|
108
108
|
```ruby
|
109
|
-
client =
|
109
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token')
|
110
110
|
|
111
111
|
write_api = client.create_write_api
|
112
112
|
write_api.write(data: 'h2o,location=west value=33i 15', bucket: 'production-data', org: 'customer-1')
|
@@ -122,12 +122,12 @@ The data could be written as:
|
|
122
122
|
1. `Array` of above items
|
123
123
|
|
124
124
|
```ruby
|
125
|
-
client =
|
125
|
+
client = InfluxDB2::Client.new('https://localhost:9999', 'my-token',
|
126
126
|
bucket: 'my-bucket',
|
127
127
|
org: 'my-org',
|
128
|
-
precision:
|
128
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
129
129
|
|
130
|
-
point =
|
130
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
131
131
|
.add_tag('location', 'europe')
|
132
132
|
.add_field('level', 2)
|
133
133
|
|
data/influxdb-client.gemspec
CHANGED
@@ -20,11 +20,11 @@
|
|
20
20
|
|
21
21
|
lib = File.expand_path('lib', __dir__)
|
22
22
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
23
|
-
require '
|
23
|
+
require 'influxdb2/client/version'
|
24
24
|
|
25
25
|
Gem::Specification.new do |spec|
|
26
26
|
spec.name = 'influxdb-client'
|
27
|
-
spec.version = ENV['CIRCLE_BUILD_NUM'] ? "#{
|
27
|
+
spec.version = ENV['CIRCLE_BUILD_NUM'] ? "#{InfluxDB2::VERSION}-#{ENV['CIRCLE_BUILD_NUM']}" : InfluxDB2::VERSION
|
28
28
|
spec.authors = ['Jakub Bednar']
|
29
29
|
spec.email = ['jakub.bednar@gmail.com']
|
30
30
|
|
@@ -18,8 +18,8 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
-
require '
|
22
|
-
require '
|
23
|
-
require '
|
24
|
-
require '
|
25
|
-
require '
|
21
|
+
require 'influxdb2/client/version'
|
22
|
+
require 'influxdb2/client/client'
|
23
|
+
require 'influxdb2/client/influx_error'
|
24
|
+
require 'influxdb2/client/write_api'
|
25
|
+
require 'influxdb2/client/point'
|
@@ -17,8 +17,9 @@
|
|
17
17
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
|
+
require 'net/http'
|
20
21
|
|
21
|
-
module
|
22
|
+
module InfluxDB2
|
22
23
|
# The client is the entry point to HTTP API defined
|
23
24
|
# in https://github.com/influxdata/influxdb/blob/master/http/swagger.yml.
|
24
25
|
class Client
|
@@ -18,7 +18,7 @@
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
|
-
module
|
21
|
+
module InfluxDB2
|
22
22
|
DEFAULT_WRITE_PRECISION = WritePrecision::NANOSECOND
|
23
23
|
ESCAPE_KEY_LIST = ['\\'.freeze, ','.freeze, ' '.freeze, '='.freeze].freeze
|
24
24
|
ESCAPE_VALUE_LIST = ['\\'.freeze, '"'.freeze].freeze
|
@@ -197,13 +197,13 @@ module InfluxDB
|
|
197
197
|
nano_seconds = @time.to_i * 1e9
|
198
198
|
nano_seconds += @time.tv_nsec
|
199
199
|
case @precision || DEFAULT_WRITE_PRECISION
|
200
|
-
when
|
200
|
+
when InfluxDB2::WritePrecision::MILLISECOND then
|
201
201
|
(nano_seconds / 1e6).round
|
202
|
-
when
|
202
|
+
when InfluxDB2::WritePrecision::SECOND then
|
203
203
|
(nano_seconds / 1e9).round
|
204
|
-
when
|
204
|
+
when InfluxDB2::WritePrecision::MICROSECOND then
|
205
205
|
(nano_seconds / 1e3).round
|
206
|
-
when
|
206
|
+
when InfluxDB2::WritePrecision::NANOSECOND then
|
207
207
|
nano_seconds.round
|
208
208
|
end
|
209
209
|
else
|
@@ -22,49 +22,49 @@ require 'test_helper'
|
|
22
22
|
|
23
23
|
class ClientTest < Minitest::Test
|
24
24
|
def test_defined_version_number
|
25
|
-
refute_nil ::
|
25
|
+
refute_nil ::InfluxDB2::VERSION
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_client_new
|
29
|
-
refute_nil
|
29
|
+
refute_nil InfluxDB2::Client.new('http://localhost:9999', 'my-token')
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_client_hash
|
33
|
-
client1 =
|
34
|
-
client2 =
|
33
|
+
client1 = InfluxDB2::Client.new('http://localhost:9999', 'my-token')
|
34
|
+
client2 = InfluxDB2::Client.new('http://localhost:9999', 'my-token-diff')
|
35
35
|
|
36
36
|
refute_equal client1.hash, client2.hash
|
37
37
|
assert_equal client1.hash, client1.hash
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_client_eq
|
41
|
-
client1 =
|
42
|
-
client2 =
|
41
|
+
client1 = InfluxDB2::Client.new('http://localhost:9999', 'my-token')
|
42
|
+
client2 = InfluxDB2::Client.new('http://localhost:9999', 'my-token-diff')
|
43
43
|
|
44
44
|
refute_equal client1, client2
|
45
45
|
assert_equal client1, client1
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_client_options
|
49
|
-
client =
|
49
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token')
|
50
50
|
|
51
51
|
assert_equal 'http://localhost:9999', client.options[:url]
|
52
52
|
assert_equal 'my-token', client.options[:token]
|
53
53
|
end
|
54
54
|
|
55
55
|
def test_close
|
56
|
-
client =
|
56
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token')
|
57
57
|
|
58
58
|
assert_equal true, client.close!
|
59
59
|
assert_equal true, client.close!
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_get_write_api
|
63
|
-
client =
|
63
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token')
|
64
64
|
|
65
65
|
write_api = client.create_write_api
|
66
66
|
|
67
67
|
refute_nil write_api
|
68
|
-
assert_instance_of
|
68
|
+
assert_instance_of InfluxDB2::WriteApi, write_api
|
69
69
|
end
|
70
70
|
end
|
data/test/influxdb/point_test.rb
CHANGED
@@ -22,90 +22,90 @@ require 'test_helper'
|
|
22
22
|
|
23
23
|
class PointTest < MiniTest::Test
|
24
24
|
def test_to_line_protocol
|
25
|
-
point_args =
|
26
|
-
|
27
|
-
|
25
|
+
point_args = InfluxDB2::Point.new(name: 'h2o',
|
26
|
+
tags: { host: 'aws', region: 'us' },
|
27
|
+
fields: { level: 5, saturation: '99%' }, time: 123)
|
28
28
|
assert_equal 'h2o,host=aws,region=us level=5i,saturation="99%" 123', point_args.to_line_protocol
|
29
29
|
|
30
|
-
point_hash =
|
31
|
-
|
32
|
-
|
30
|
+
point_hash = InfluxDB2::Point.from_hash(name: 'h2o',
|
31
|
+
tags: { host: 'aws', region: 'us' },
|
32
|
+
fields: { level: 5, saturation: '99%' }, time: 123)
|
33
33
|
assert_equal 'h2o,host=aws,region=us level=5i,saturation="99%" 123', point_hash.to_line_protocol
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_measurement_escape
|
37
|
-
point =
|
37
|
+
point = InfluxDB2::Point.new(name: 'h2 o', tags: { location: 'europe' }, fields: { level: 2 })
|
38
38
|
assert_equal 'h2\\ o,location=europe level=2i', point.to_line_protocol
|
39
39
|
|
40
|
-
point =
|
40
|
+
point = InfluxDB2::Point.new(name: 'h2,o', tags: { location: 'europe' }, fields: { level: 2 })
|
41
41
|
assert_equal 'h2\\,o,location=europe level=2i', point.to_line_protocol
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_tag_empty_key
|
45
|
-
point =
|
45
|
+
point = InfluxDB2::Point.new(name: 'h2o', fields: { level: 2 }).add_tag('location', 'europe').add_tag('', 'warn')
|
46
46
|
|
47
47
|
assert_equal 'h2o,location=europe level=2i', point.to_line_protocol
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_tag_empty_value
|
51
|
-
point =
|
51
|
+
point = InfluxDB2::Point.new(name: 'h2o', fields: { level: 2 }).add_tag('location', 'europe').add_tag('log', '')
|
52
52
|
|
53
53
|
assert_equal 'h2o,location=europe level=2i', point.to_line_protocol
|
54
54
|
end
|
55
55
|
|
56
56
|
def test_override_tag_and_field
|
57
|
-
point =
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
point = InfluxDB2::Point.new(name: 'h2o', fields: { level: '1' })
|
58
|
+
.add_tag('location', 'europe')
|
59
|
+
.add_tag('location', 'europe2')
|
60
|
+
.add_field(:level, 2)
|
61
|
+
.add_field(:level, 3)
|
62
62
|
|
63
63
|
assert_equal 'h2o,location=europe2 level=3i', point.to_line_protocol
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_field_types
|
67
|
-
point =
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
67
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
68
|
+
.add_tag('tag_b', 'b')
|
69
|
+
.add_tag('tag_a', 'a')
|
70
|
+
.add_field('n1', -2)
|
71
|
+
.add_field('n2', 10)
|
72
|
+
.add_field('n3', 1_265_437_718_438_866_624_512)
|
73
|
+
.add_field('n4', 5.5)
|
74
|
+
.add_field('bool', true)
|
75
|
+
.add_field('string', 'string value')
|
76
76
|
|
77
77
|
expected = 'h2o,tag_a=a,tag_b=b bool=true,n1=-2i,n2=10i,n3=1265437718438866624512i,n4=5.5,string="string value"'
|
78
78
|
assert_equal expected, point.to_line_protocol
|
79
79
|
end
|
80
80
|
|
81
81
|
def test_field_null_value
|
82
|
-
point =
|
83
|
-
|
84
|
-
|
85
|
-
|
82
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
83
|
+
.add_tag('location', 'europe')
|
84
|
+
.add_field('level', 2)
|
85
|
+
.add_field('warning', nil)
|
86
86
|
|
87
87
|
assert_equal 'h2o,location=europe level=2i', point.to_line_protocol
|
88
88
|
end
|
89
89
|
|
90
90
|
def test_field_escape
|
91
|
-
point =
|
92
|
-
|
93
|
-
|
91
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
92
|
+
.add_tag('location', 'europe')
|
93
|
+
.add_field('level', 'string esc\\ape value')
|
94
94
|
|
95
95
|
assert_equal 'h2o,location=europe level="string esc\\\\ape value"', point.to_line_protocol
|
96
96
|
|
97
|
-
point =
|
98
|
-
|
99
|
-
|
97
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
98
|
+
.add_tag('location', 'europe')
|
99
|
+
.add_field('level', 'string esc"ape value')
|
100
100
|
|
101
101
|
assert_equal 'h2o,location=europe level="string esc\"ape value"', point.to_line_protocol
|
102
102
|
end
|
103
103
|
|
104
104
|
def test_time
|
105
|
-
point =
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
106
|
+
.add_tag('location', 'europe')
|
107
|
+
.add_field('level', 2)
|
108
|
+
.time(123, InfluxDB2::WritePrecision::NANOSECOND)
|
109
109
|
|
110
110
|
assert_equal 'h2o,location=europe level=2i 123', point.to_line_protocol
|
111
111
|
end
|
@@ -113,31 +113,31 @@ class PointTest < MiniTest::Test
|
|
113
113
|
def test_time_formatting
|
114
114
|
time = Time.utc(2015, 10, 15, 8, 20, 15)
|
115
115
|
|
116
|
-
point =
|
117
|
-
|
118
|
-
|
119
|
-
|
116
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
117
|
+
.add_tag('location', 'europe')
|
118
|
+
.add_field('level', 2)
|
119
|
+
.time(time, InfluxDB2::WritePrecision::MILLISECOND)
|
120
120
|
|
121
121
|
assert_equal 'h2o,location=europe level=2i 1444897215000', point.to_line_protocol
|
122
122
|
|
123
|
-
point =
|
124
|
-
|
125
|
-
|
126
|
-
|
123
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
124
|
+
.add_tag('location', 'europe')
|
125
|
+
.add_field('level', 2)
|
126
|
+
.time(time, InfluxDB2::WritePrecision::SECOND)
|
127
127
|
|
128
128
|
assert_equal 'h2o,location=europe level=2i 1444897215', point.to_line_protocol
|
129
129
|
|
130
|
-
point =
|
131
|
-
|
132
|
-
|
133
|
-
|
130
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
131
|
+
.add_tag('location', 'europe')
|
132
|
+
.add_field('level', 2)
|
133
|
+
.time(time, InfluxDB2::WritePrecision::MICROSECOND)
|
134
134
|
|
135
135
|
assert_equal 'h2o,location=europe level=2i 1444897215000000', point.to_line_protocol
|
136
136
|
|
137
|
-
point =
|
138
|
-
|
139
|
-
|
140
|
-
|
137
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
138
|
+
.add_tag('location', 'europe')
|
139
|
+
.add_field('level', 2)
|
140
|
+
.time(time, InfluxDB2::WritePrecision::NANOSECOND)
|
141
141
|
|
142
142
|
assert_equal 'h2o,location=europe level=2i 1444897215000000000', point.to_line_protocol
|
143
143
|
end
|
@@ -145,76 +145,76 @@ class PointTest < MiniTest::Test
|
|
145
145
|
def test_time_formatting_default
|
146
146
|
time = Time.utc(2015, 10, 15, 8, 20, 15)
|
147
147
|
|
148
|
-
point =
|
149
|
-
|
150
|
-
|
148
|
+
point = InfluxDB2::Point.new(name: 'h2o', time: time)
|
149
|
+
.add_tag('location', 'europe')
|
150
|
+
.add_field('level', 2)
|
151
151
|
|
152
152
|
assert_equal 'h2o,location=europe level=2i 1444897215000000000', point.to_line_protocol
|
153
153
|
|
154
|
-
point =
|
155
|
-
|
156
|
-
|
157
|
-
|
154
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
155
|
+
.add_tag('location', 'europe')
|
156
|
+
.add_field('level', 2)
|
157
|
+
.time(time, nil)
|
158
158
|
|
159
159
|
assert_equal 'h2o,location=europe level=2i 1444897215000000000', point.to_line_protocol
|
160
160
|
end
|
161
161
|
|
162
162
|
def test_time_string
|
163
|
-
point_args =
|
164
|
-
|
165
|
-
|
163
|
+
point_args = InfluxDB2::Point.new(name: 'h2o',
|
164
|
+
tags: { host: 'aws', region: 'us' },
|
165
|
+
fields: { level: 5 }, time: '123')
|
166
166
|
|
167
167
|
assert_equal 'h2o,host=aws,region=us level=5i 123', point_args.to_line_protocol
|
168
168
|
end
|
169
169
|
|
170
170
|
def test_time_float
|
171
|
-
point_args =
|
172
|
-
|
173
|
-
|
171
|
+
point_args = InfluxDB2::Point.new(name: 'h2o',
|
172
|
+
tags: { host: 'aws', region: 'us' },
|
173
|
+
fields: { level: 5 }, time: 1.444897215e+18)
|
174
174
|
|
175
175
|
assert_equal 'h2o,host=aws,region=us level=5i 1444897215000000000', point_args.to_line_protocol
|
176
176
|
|
177
|
-
point_args =
|
178
|
-
|
179
|
-
|
177
|
+
point_args = InfluxDB2::Point.new(name: 'h2o',
|
178
|
+
tags: { host: 'aws', region: 'us' },
|
179
|
+
fields: { level: 5 }, time: 102_030_405_060)
|
180
180
|
|
181
181
|
assert_equal 'h2o,host=aws,region=us level=5i 102030405060', point_args.to_line_protocol
|
182
182
|
end
|
183
183
|
|
184
184
|
def test_utf_8
|
185
|
-
point =
|
186
|
-
|
187
|
-
|
188
|
-
|
185
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
186
|
+
.add_tag('location', 'Přerov')
|
187
|
+
.add_field('level', 2)
|
188
|
+
.time(123, InfluxDB2::WritePrecision::NANOSECOND)
|
189
189
|
|
190
190
|
assert_equal 'h2o,location=Přerov level=2i 123', point.to_line_protocol
|
191
191
|
end
|
192
192
|
|
193
193
|
def test_infinity_values
|
194
|
-
point =
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
194
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
195
|
+
.add_tag('location', 'europe')
|
196
|
+
.add_field('infinity_constant', Float::INFINITY)
|
197
|
+
.add_field('infinity_positive', 1 / 0.0)
|
198
|
+
.add_field('infinity_negative', -1 / 0.0)
|
199
|
+
.add_field('level', 2)
|
200
200
|
|
201
201
|
assert_equal 'h2o,location=europe level=2i', point.to_line_protocol
|
202
202
|
end
|
203
203
|
|
204
204
|
def test_only_infinity_values
|
205
|
-
point =
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
205
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
206
|
+
.add_tag('location', 'europe')
|
207
|
+
.add_field('infinity_constant', Float::INFINITY)
|
208
|
+
.add_field('infinity_positive', 1 / 0.0)
|
209
|
+
.add_field('infinity_negative', -1 / 0.0)
|
210
210
|
|
211
211
|
assert_nil point.to_line_protocol
|
212
212
|
end
|
213
213
|
|
214
214
|
def test_without_tags
|
215
|
-
point =
|
216
|
-
|
217
|
-
|
215
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
216
|
+
.add_field('level', 2)
|
217
|
+
.time(123, InfluxDB2::WritePrecision::NANOSECOND)
|
218
218
|
|
219
219
|
assert_equal 'h2o level=2i 123', point.to_line_protocol
|
220
220
|
end
|
@@ -27,19 +27,19 @@ class WriteApiIntegrationTest < MiniTest::Test
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_write_into_influx_db
|
30
|
-
client =
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
31
|
+
bucket: 'my-bucket',
|
32
|
+
org: 'my-org',
|
33
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
34
|
+
use_ssl: false)
|
35
35
|
|
36
36
|
now = Time.now.utc
|
37
37
|
|
38
38
|
measurement = 'h2o_' + now.to_i.to_s
|
39
|
-
point =
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
point = InfluxDB2::Point.new(name: measurement)
|
40
|
+
.add_tag('location', 'europe')
|
41
|
+
.add_field('level', 2)
|
42
|
+
.time(now, InfluxDB2::WritePrecision::NANOSECOND)
|
43
43
|
|
44
44
|
client.create_write_api.write(data: point)
|
45
45
|
|
@@ -26,7 +26,7 @@ class WriteApiTest < MiniTest::Test
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_required_arguments
|
29
|
-
client =
|
29
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token')
|
30
30
|
write_api = client.create_write_api
|
31
31
|
|
32
32
|
# precision
|
@@ -35,19 +35,19 @@ class WriteApiTest < MiniTest::Test
|
|
35
35
|
end
|
36
36
|
# bucket
|
37
37
|
assert_raises ArgumentError do
|
38
|
-
write_api.write(data: {}, org: 'my-org', precision:
|
38
|
+
write_api.write(data: {}, org: 'my-org', precision: InfluxDB2::WritePrecision::NANOSECOND)
|
39
39
|
end
|
40
40
|
# org
|
41
41
|
assert_raises ArgumentError do
|
42
|
-
write_api.write(data: {}, bucket: 'my-bucket', precision:
|
42
|
+
write_api.write(data: {}, bucket: 'my-bucket', precision: InfluxDB2::WritePrecision::NANOSECOND)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_default_arguments_
|
47
|
-
client =
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
48
|
+
bucket: 'my-bucket',
|
49
|
+
org: 'my-org',
|
50
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
51
51
|
write_api = client.create_write_api
|
52
52
|
|
53
53
|
# without argument errors
|
@@ -57,11 +57,11 @@ class WriteApiTest < MiniTest::Test
|
|
57
57
|
def test_write_line_protocol
|
58
58
|
stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
59
59
|
.to_return(status: 204)
|
60
|
-
client =
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
60
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
61
|
+
bucket: 'my-bucket',
|
62
|
+
org: 'my-org',
|
63
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
64
|
+
use_ssl: false)
|
65
65
|
|
66
66
|
client.create_write_api.write(data: 'h2o,location=west value=33i 15')
|
67
67
|
|
@@ -72,13 +72,13 @@ class WriteApiTest < MiniTest::Test
|
|
72
72
|
def test_write_point
|
73
73
|
stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
74
74
|
.to_return(status: 204)
|
75
|
-
client =
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
75
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
76
|
+
bucket: 'my-bucket',
|
77
|
+
org: 'my-org',
|
78
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
79
|
+
use_ssl: false)
|
80
80
|
|
81
|
-
client.create_write_api.write(data:
|
81
|
+
client.create_write_api.write(data: InfluxDB2::Point.new(name: 'h2o')
|
82
82
|
.add_tag('location', 'europe')
|
83
83
|
.add_field('level', 2))
|
84
84
|
|
@@ -89,11 +89,11 @@ class WriteApiTest < MiniTest::Test
|
|
89
89
|
def test_write_hash
|
90
90
|
stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
91
91
|
.to_return(status: 204)
|
92
|
-
client =
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
92
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
93
|
+
bucket: 'my-bucket',
|
94
|
+
org: 'my-org',
|
95
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
96
|
+
use_ssl: false)
|
97
97
|
|
98
98
|
client.create_write_api.write(data: { name: 'h2o',
|
99
99
|
tags: { host: 'aws', region: 'us' },
|
@@ -107,15 +107,15 @@ class WriteApiTest < MiniTest::Test
|
|
107
107
|
def test_write_collection
|
108
108
|
stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
109
109
|
.to_return(status: 204)
|
110
|
-
client =
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
110
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
111
|
+
bucket: 'my-bucket',
|
112
|
+
org: 'my-org',
|
113
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
114
|
+
use_ssl: false)
|
115
115
|
|
116
|
-
point =
|
117
|
-
|
118
|
-
|
116
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
117
|
+
.add_tag('location', 'europe')
|
118
|
+
.add_field('level', 2)
|
119
119
|
|
120
120
|
hash = { name: 'h2o',
|
121
121
|
tags: { host: 'aws', region: 'us' },
|
@@ -132,11 +132,11 @@ class WriteApiTest < MiniTest::Test
|
|
132
132
|
def test_authorization_header
|
133
133
|
stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
134
134
|
.to_return(status: 204)
|
135
|
-
client =
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
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
140
|
|
141
141
|
client.create_write_api.write(data: 'h2o,location=west value=33i 15')
|
142
142
|
|
@@ -147,10 +147,10 @@ class WriteApiTest < MiniTest::Test
|
|
147
147
|
def test_without_data
|
148
148
|
stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
149
149
|
.to_return(status: 204)
|
150
|
-
client =
|
151
|
-
|
152
|
-
|
153
|
-
|
150
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
151
|
+
bucket: 'my-bucket',
|
152
|
+
org: 'my-org',
|
153
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND)
|
154
154
|
|
155
155
|
client.create_write_api.write(data: '')
|
156
156
|
|
@@ -164,13 +164,13 @@ class WriteApiTest < MiniTest::Test
|
|
164
164
|
stub_request(:any, 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
165
165
|
.to_return(status: 400, headers: { 'X-Platform-Error-Code' => 'invalid' }, body: error_body)
|
166
166
|
|
167
|
-
client =
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
167
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
168
|
+
bucket: 'my-bucket',
|
169
|
+
org: 'my-org',
|
170
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
171
|
+
use_ssl: false)
|
172
172
|
|
173
|
-
error = assert_raises
|
173
|
+
error = assert_raises InfluxDB2::InfluxError do
|
174
174
|
client.create_write_api.write(data: 'h2o,location=west value=33i 15')
|
175
175
|
end
|
176
176
|
|
@@ -187,11 +187,11 @@ class WriteApiTest < MiniTest::Test
|
|
187
187
|
stub_request(:any, 'http://localhost:9090/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
188
188
|
.to_return(status: 204)
|
189
189
|
|
190
|
-
client =
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
190
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
191
|
+
bucket: 'my-bucket',
|
192
|
+
org: 'my-org',
|
193
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
194
|
+
use_ssl: false)
|
195
195
|
|
196
196
|
client.create_write_api.write(data: 'h2o,location=west value=33i 15')
|
197
197
|
|
@@ -206,14 +206,14 @@ class WriteApiTest < MiniTest::Test
|
|
206
206
|
.to_return(status: 307, headers:
|
207
207
|
{ 'location' => 'http://localhost:9999/api/v2/write?bucket=my-bucket&org=my-org&precision=ns' })
|
208
208
|
|
209
|
-
client =
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
209
|
+
client = InfluxDB2::Client.new('http://localhost:9999', 'my-token',
|
210
|
+
bucket: 'my-bucket',
|
211
|
+
org: 'my-org',
|
212
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
213
|
+
max_redirect_count: 5,
|
214
|
+
use_ssl: false)
|
215
215
|
|
216
|
-
error = assert_raises
|
216
|
+
error = assert_raises InfluxDB2::InfluxError do
|
217
217
|
client.create_write_api.write(data: 'h2o,location=west value=33i 15')
|
218
218
|
end
|
219
219
|
|
@@ -221,13 +221,13 @@ class WriteApiTest < MiniTest::Test
|
|
221
221
|
end
|
222
222
|
|
223
223
|
def test_write_precision_constant
|
224
|
-
assert_equal
|
225
|
-
assert_equal
|
226
|
-
assert_equal
|
227
|
-
assert_equal
|
224
|
+
assert_equal InfluxDB2::WritePrecision::SECOND, InfluxDB2::WritePrecision.new.get_from_value('s')
|
225
|
+
assert_equal InfluxDB2::WritePrecision::MILLISECOND, InfluxDB2::WritePrecision.new.get_from_value('ms')
|
226
|
+
assert_equal InfluxDB2::WritePrecision::MICROSECOND, InfluxDB2::WritePrecision.new.get_from_value('us')
|
227
|
+
assert_equal InfluxDB2::WritePrecision::NANOSECOND, InfluxDB2::WritePrecision.new.get_from_value('ns')
|
228
228
|
|
229
229
|
error = assert_raises RuntimeError do
|
230
|
-
|
230
|
+
InfluxDB2::WritePrecision.new.get_from_value('not_supported')
|
231
231
|
end
|
232
232
|
|
233
233
|
assert_equal 'The time precision not_supported is not supported.', error.message
|
data/test/test_helper.rb
CHANGED
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.0.0.pre.
|
4
|
+
version: 1.0.0.pre.159
|
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-01-
|
11
|
+
date: 2020-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -142,12 +142,12 @@ files:
|
|
142
142
|
- bin/influxdb-onboarding.sh
|
143
143
|
- bin/influxdb-restart.sh
|
144
144
|
- influxdb-client.gemspec
|
145
|
-
- lib/
|
146
|
-
- lib/
|
147
|
-
- lib/
|
148
|
-
- lib/
|
149
|
-
- lib/
|
150
|
-
- lib/
|
145
|
+
- lib/influxdb2/client.rb
|
146
|
+
- lib/influxdb2/client/client.rb
|
147
|
+
- lib/influxdb2/client/influx_error.rb
|
148
|
+
- lib/influxdb2/client/point.rb
|
149
|
+
- lib/influxdb2/client/version.rb
|
150
|
+
- lib/influxdb2/client/write_api.rb
|
151
151
|
- test/influxdb/client_test.rb
|
152
152
|
- test/influxdb/point_test.rb
|
153
153
|
- test/influxdb/write_api_integration_test.rb
|