influxdb-client 1.0.0.beta → 1.0.0.pre.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/.circleci/config.yml +17 -57
- data/.gitignore +1 -2
- data/{LICENSE → LICENSE.txt} +0 -0
- data/README.md +27 -38
- data/bin/influxdb-restart.sh +16 -10
- data/influxdb-client.gemspec +5 -6
- data/lib/{influxdb2 → influxdb}/client.rb +5 -5
- data/lib/{influxdb2 → influxdb}/client/client.rb +6 -8
- data/lib/{influxdb2 → influxdb}/client/influx_error.rb +1 -1
- data/lib/{influxdb2 → influxdb}/client/point.rb +6 -8
- data/lib/{influxdb2 → influxdb}/client/version.rb +2 -2
- data/lib/{influxdb2 → influxdb}/client/write_api.rb +2 -12
- data/test/influxdb/client_test.rb +12 -12
- data/test/influxdb/point_test.rb +79 -101
- data/test/influxdb/write_api_integration_test.rb +8 -9
- data/test/influxdb/write_api_test.rb +52 -73
- data/test/test_helper.rb +1 -1
- metadata +15 -18
- data/.circleci/setup-rubygems.sh +0 -3
- data/CHANGELOG.md +0 -5
- data/bin/influxdb-onboarding.sh +0 -39
@@ -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 InfluxDB
|
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
|
@@ -117,7 +117,7 @@ module InfluxDB2
|
|
117
117
|
line_protocol << measurement
|
118
118
|
|
119
119
|
tags = _escape_tags
|
120
|
-
line_protocol << ",#{tags}"
|
120
|
+
line_protocol << ",#{tags}" if tags
|
121
121
|
line_protocol << ' '.freeze if line_protocol[-1] == '\\'
|
122
122
|
|
123
123
|
fields = _escape_fields
|
@@ -191,19 +191,17 @@ module InfluxDB2
|
|
191
191
|
nil
|
192
192
|
elsif @time.is_a?(Integer)
|
193
193
|
@time.to_s
|
194
|
-
elsif @time.is_a?(Float)
|
195
|
-
@time.round.to_s
|
196
194
|
elsif @time.is_a?(Time)
|
197
195
|
nano_seconds = @time.to_i * 1e9
|
198
196
|
nano_seconds += @time.tv_nsec
|
199
197
|
case @precision || DEFAULT_WRITE_PRECISION
|
200
|
-
when
|
198
|
+
when InfluxDB::WritePrecision::MILLISECOND then
|
201
199
|
(nano_seconds / 1e6).round
|
202
|
-
when
|
200
|
+
when InfluxDB::WritePrecision::SECOND then
|
203
201
|
(nano_seconds / 1e9).round
|
204
|
-
when
|
202
|
+
when InfluxDB::WritePrecision::MICROSECOND then
|
205
203
|
(nano_seconds / 1e3).round
|
206
|
-
when
|
204
|
+
when InfluxDB::WritePrecision::NANOSECOND then
|
207
205
|
nano_seconds.round
|
208
206
|
end
|
209
207
|
else
|
@@ -18,21 +18,12 @@
|
|
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
|
22
|
-
# Precision constants.
|
23
|
-
#
|
21
|
+
module InfluxDB
|
24
22
|
class WritePrecision
|
25
23
|
SECOND = 's'.freeze
|
26
24
|
MILLISECOND = 'ms'.freeze
|
27
25
|
MICROSECOND = 'us'.freeze
|
28
26
|
NANOSECOND = 'ns'.freeze
|
29
|
-
|
30
|
-
def get_from_value(value)
|
31
|
-
constants = WritePrecision.constants.select { |c| WritePrecision.const_get(c) == value }
|
32
|
-
raise "The time precision #{value} is not supported." if constants.empty?
|
33
|
-
|
34
|
-
value
|
35
|
-
end
|
36
27
|
end
|
37
28
|
|
38
29
|
# Write time series data into InfluxDB.
|
@@ -105,7 +96,6 @@ module InfluxDB2
|
|
105
96
|
http.open_timeout = @options[:open_timeout] || DEFAULT_TIMEOUT
|
106
97
|
http.write_timeout = @options[:write_timeout] || DEFAULT_TIMEOUT if Net::HTTP.method_defined? :write_timeout
|
107
98
|
http.read_timeout = @options[:read_timeout] || DEFAULT_TIMEOUT
|
108
|
-
http.use_ssl = @options[:use_ssl].nil? ? true : @options[:use_ssl]
|
109
99
|
|
110
100
|
request = Net::HTTP::Post.new(uri.request_uri)
|
111
101
|
request['Authorization'] = "Token #{@options[:token]}"
|
@@ -147,7 +137,7 @@ module InfluxDB2
|
|
147
137
|
elsif data.respond_to? :map
|
148
138
|
data.map do |item|
|
149
139
|
_generate_payload(item)
|
150
|
-
end.reject(&:nil?).join(
|
140
|
+
end.reject(&:nil?).join('\n'.freeze)
|
151
141
|
end
|
152
142
|
end
|
153
143
|
end
|
@@ -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 ::InfluxDB::VERSION
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_client_new
|
29
|
-
refute_nil
|
29
|
+
refute_nil InfluxDB::Client.new('http://localhost:9999', 'my-token')
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_client_hash
|
33
|
-
client1 =
|
34
|
-
client2 =
|
33
|
+
client1 = InfluxDB::Client.new('http://localhost:9999', 'my-token')
|
34
|
+
client2 = InfluxDB::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 = InfluxDB::Client.new('http://localhost:9999', 'my-token')
|
42
|
+
client2 = InfluxDB::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 = InfluxDB::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 = InfluxDB::Client.new('http://localhost:9999', 'my-token')
|
57
57
|
|
58
|
-
assert_equal true, client.close
|
59
|
-
assert_equal true, client.close
|
58
|
+
assert_equal true, client.close
|
59
|
+
assert_equal true, client.close
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_get_write_api
|
63
|
-
client =
|
63
|
+
client = InfluxDB::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 InfluxDB::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 = InfluxDB::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 = InfluxDB::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 = InfluxDB::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 = InfluxDB::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 = InfluxDB::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 = InfluxDB::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 = InfluxDB::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 = InfluxDB::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 = InfluxDB::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 = InfluxDB::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 = InfluxDB::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 = InfluxDB::Point.new(name: 'h2o')
|
106
|
+
.add_tag('location', 'europe')
|
107
|
+
.add_field('level', 2)
|
108
|
+
.time(123, InfluxDB::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 = InfluxDB::Point.new(name: 'h2o')
|
117
|
+
.add_tag('location', 'europe')
|
118
|
+
.add_field('level', 2)
|
119
|
+
.time(time, InfluxDB::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 = InfluxDB::Point.new(name: 'h2o')
|
124
|
+
.add_tag('location', 'europe')
|
125
|
+
.add_field('level', 2)
|
126
|
+
.time(time, InfluxDB::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 = InfluxDB::Point.new(name: 'h2o')
|
131
|
+
.add_tag('location', 'europe')
|
132
|
+
.add_field('level', 2)
|
133
|
+
.time(time, InfluxDB::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 = InfluxDB::Point.new(name: 'h2o')
|
138
|
+
.add_tag('location', 'europe')
|
139
|
+
.add_field('level', 2)
|
140
|
+
.time(time, InfluxDB::WritePrecision::NANOSECOND)
|
141
141
|
|
142
142
|
assert_equal 'h2o,location=europe level=2i 1444897215000000000', point.to_line_protocol
|
143
143
|
end
|
@@ -145,77 +145,55 @@ 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 = InfluxDB::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 = InfluxDB::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 = InfluxDB::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
|
-
def test_time_float
|
171
|
-
point_args = InfluxDB2::Point.new(name: 'h2o',
|
172
|
-
tags: { host: 'aws', region: 'us' },
|
173
|
-
fields: { level: 5 }, time: 1.444897215e+18)
|
174
|
-
|
175
|
-
assert_equal 'h2o,host=aws,region=us level=5i 1444897215000000000', point_args.to_line_protocol
|
176
|
-
|
177
|
-
point_args = InfluxDB2::Point.new(name: 'h2o',
|
178
|
-
tags: { host: 'aws', region: 'us' },
|
179
|
-
fields: { level: 5 }, time: 102_030_405_060)
|
180
|
-
|
181
|
-
assert_equal 'h2o,host=aws,region=us level=5i 102030405060', point_args.to_line_protocol
|
182
|
-
end
|
183
|
-
|
184
170
|
def test_utf_8
|
185
|
-
point =
|
186
|
-
|
187
|
-
|
188
|
-
|
171
|
+
point = InfluxDB::Point.new(name: 'h2o')
|
172
|
+
.add_tag('location', 'Přerov')
|
173
|
+
.add_field('level', 2)
|
174
|
+
.time(123, InfluxDB::WritePrecision::NANOSECOND)
|
189
175
|
|
190
176
|
assert_equal 'h2o,location=Přerov level=2i 123', point.to_line_protocol
|
191
177
|
end
|
192
178
|
|
193
179
|
def test_infinity_values
|
194
|
-
point =
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
180
|
+
point = InfluxDB::Point.new(name: 'h2o')
|
181
|
+
.add_tag('location', 'europe')
|
182
|
+
.add_field('infinity_constant', Float::INFINITY)
|
183
|
+
.add_field('infinity_positive', 1 / 0.0)
|
184
|
+
.add_field('infinity_negative', -1 / 0.0)
|
185
|
+
.add_field('level', 2)
|
200
186
|
|
201
187
|
assert_equal 'h2o,location=europe level=2i', point.to_line_protocol
|
202
188
|
end
|
203
189
|
|
204
190
|
def test_only_infinity_values
|
205
|
-
point =
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
191
|
+
point = InfluxDB::Point.new(name: 'h2o')
|
192
|
+
.add_tag('location', 'europe')
|
193
|
+
.add_field('infinity_constant', Float::INFINITY)
|
194
|
+
.add_field('infinity_positive', 1 / 0.0)
|
195
|
+
.add_field('infinity_negative', -1 / 0.0)
|
210
196
|
|
211
197
|
assert_nil point.to_line_protocol
|
212
198
|
end
|
213
|
-
|
214
|
-
def test_without_tags
|
215
|
-
point = InfluxDB2::Point.new(name: 'h2o')
|
216
|
-
.add_field('level', 2)
|
217
|
-
.time(123, InfluxDB2::WritePrecision::NANOSECOND)
|
218
|
-
|
219
|
-
assert_equal 'h2o level=2i 123', point.to_line_protocol
|
220
|
-
end
|
221
199
|
end
|
@@ -27,19 +27,18 @@ class WriteApiIntegrationTest < MiniTest::Test
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_write_into_influx_db
|
30
|
-
client =
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
use_ssl: false)
|
30
|
+
client = InfluxDB::Client.new('http://localhost:9999', 'my-token',
|
31
|
+
bucket: 'my-bucket',
|
32
|
+
org: 'my-org',
|
33
|
+
precision: InfluxDB::WritePrecision::NANOSECOND)
|
35
34
|
|
36
35
|
now = Time.now.utc
|
37
36
|
|
38
37
|
measurement = 'h2o_' + now.to_i.to_s
|
39
|
-
point =
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
point = InfluxDB::Point.new(name: measurement)
|
39
|
+
.add_tag('location', 'europe')
|
40
|
+
.add_field('level', 2)
|
41
|
+
.time(now, InfluxDB::WritePrecision::NANOSECOND)
|
43
42
|
|
44
43
|
client.create_write_api.write(data: point)
|
45
44
|
|