influxdb-client 1.7.0.pre.1015 → 1.8.0.pre.1240
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 +2 -5
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +15 -1
- data/README.md +51 -17
- data/bin/influxdb-onboarding.sh +2 -2
- data/bin/influxdb-restart.sh +2 -1
- data/lib/influxdb2/client/client.rb +5 -4
- data/lib/influxdb2/client/default_api.rb +2 -0
- data/lib/influxdb2/client/influx_error.rb +20 -1
- data/lib/influxdb2/client/point.rb +1 -1
- data/lib/influxdb2/client/version.rb +1 -1
- data/lib/influxdb2/client/worker.rb +17 -5
- data/lib/influxdb2/client/write_api.rb +65 -4
- data/test/influxdb/client_test.rb +10 -10
- data/test/influxdb/delete_api_integration_test.rb +5 -1
- data/test/influxdb/delete_api_test.rb +15 -15
- data/test/influxdb/query_api_integration_test.rb +1 -1
- data/test/influxdb/query_api_stream_test.rb +1 -1
- data/test/influxdb/query_api_test.rb +7 -7
- data/test/influxdb/write_api_batching_test.rb +308 -52
- data/test/influxdb/write_api_integration_test.rb +2 -2
- data/test/influxdb/write_api_test.rb +135 -38
- metadata +2 -2
@@ -30,41 +30,41 @@ class ClientTest < Minitest::Test
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_client_new
|
33
|
-
refute_nil InfluxDB2::Client.new('http://localhost:
|
33
|
+
refute_nil InfluxDB2::Client.new('http://localhost:8086', 'my-token')
|
34
34
|
end
|
35
35
|
|
36
36
|
def test_client_hash
|
37
|
-
client1 = InfluxDB2::Client.new('http://localhost:
|
38
|
-
client2 = InfluxDB2::Client.new('http://localhost:
|
37
|
+
client1 = InfluxDB2::Client.new('http://localhost:8086', 'my-token')
|
38
|
+
client2 = InfluxDB2::Client.new('http://localhost:8086', 'my-token-diff')
|
39
39
|
|
40
40
|
refute_equal client1.hash, client2.hash
|
41
41
|
assert_equal client1.hash, client1.hash
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_client_eq
|
45
|
-
client1 = InfluxDB2::Client.new('http://localhost:
|
46
|
-
client2 = InfluxDB2::Client.new('http://localhost:
|
45
|
+
client1 = InfluxDB2::Client.new('http://localhost:8086', 'my-token')
|
46
|
+
client2 = InfluxDB2::Client.new('http://localhost:8086', 'my-token-diff')
|
47
47
|
|
48
48
|
refute_equal client1, client2
|
49
49
|
assert_equal client1, client1
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_client_options
|
53
|
-
client = InfluxDB2::Client.new('http://localhost:
|
53
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token')
|
54
54
|
|
55
|
-
assert_equal 'http://localhost:
|
55
|
+
assert_equal 'http://localhost:8086', client.options[:url]
|
56
56
|
assert_equal 'my-token', client.options[:token]
|
57
57
|
end
|
58
58
|
|
59
59
|
def test_close
|
60
|
-
client = InfluxDB2::Client.new('http://localhost:
|
60
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token')
|
61
61
|
|
62
62
|
assert_equal true, client.close!
|
63
63
|
assert_equal true, client.close!
|
64
64
|
end
|
65
65
|
|
66
66
|
def test_get_write_api
|
67
|
-
client = InfluxDB2::Client.new('http://localhost:
|
67
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token')
|
68
68
|
|
69
69
|
write_api = client.create_write_api
|
70
70
|
|
@@ -73,7 +73,7 @@ class ClientTest < Minitest::Test
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def test_health
|
76
|
-
client = InfluxDB2::Client.new('http://localhost:
|
76
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token', use_ssl: false)
|
77
77
|
|
78
78
|
health = client.health
|
79
79
|
assert_equal 'ready for queries and writes', health.message
|
@@ -24,7 +24,7 @@ class DeleteApiIntegrationTest < MiniTest::Test
|
|
24
24
|
def setup
|
25
25
|
WebMock.allow_net_connect!
|
26
26
|
|
27
|
-
@client = InfluxDB2::Client.new('http://localhost:
|
27
|
+
@client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
28
28
|
bucket: 'my-bucket',
|
29
29
|
org: 'my-org',
|
30
30
|
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
@@ -56,6 +56,8 @@ class DeleteApiIntegrationTest < MiniTest::Test
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def test_delete
|
59
|
+
# TODO: https://github.com/influxdata/influxdb/issues/19545
|
60
|
+
skip
|
59
61
|
@client.create_delete_api.delete(Time.utc(2015, 10, 16, 8, 20, 15), Time.utc(2020, 10, 16, 8, 20, 15),
|
60
62
|
predicate: 'location="europe"')
|
61
63
|
|
@@ -63,6 +65,8 @@ class DeleteApiIntegrationTest < MiniTest::Test
|
|
63
65
|
end
|
64
66
|
|
65
67
|
def test_delete_without_predicate
|
68
|
+
# TODO: https://github.com/influxdata/influxdb/issues/19545
|
69
|
+
skip
|
66
70
|
@client.create_delete_api.delete(Time.utc(2016, 10, 15, 7, 20, 15), Time.utc(2018, 10, 14, 8, 20, 15))
|
67
71
|
|
68
72
|
assert_equal 2, _query_count
|
@@ -26,9 +26,9 @@ class DeleteApiTest < MiniTest::Test
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_delete
|
29
|
-
stub_request(:any, 'http://localhost:
|
29
|
+
stub_request(:any, 'http://localhost:8086/api/v2/delete?bucket=my-bucket&org=my-org')
|
30
30
|
.to_return(status: 204)
|
31
|
-
client = InfluxDB2::Client.new('http://localhost:
|
31
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
32
32
|
bucket: 'my-bucket',
|
33
33
|
org: 'my-org',
|
34
34
|
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
@@ -40,13 +40,13 @@ class DeleteApiTest < MiniTest::Test
|
|
40
40
|
body = '{"start":"2019-10-15T08:20:15+00:00","stop":"2019-11-15T08:20:15+00:00","predicate":"key1=\"value1\" ' \
|
41
41
|
'AND key2=\"value\""}'
|
42
42
|
|
43
|
-
assert_requested(:post, 'http://localhost:
|
43
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/delete?bucket=my-bucket&org=my-org', times: 1, body: body)
|
44
44
|
end
|
45
45
|
|
46
46
|
def test_delete_time_as_date_time
|
47
|
-
stub_request(:any, 'http://localhost:
|
47
|
+
stub_request(:any, 'http://localhost:8086/api/v2/delete?bucket=my-bucket&org=my-org')
|
48
48
|
.to_return(status: 204)
|
49
|
-
client = InfluxDB2::Client.new('http://localhost:
|
49
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
50
50
|
bucket: 'my-bucket',
|
51
51
|
org: 'my-org',
|
52
52
|
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
@@ -59,13 +59,13 @@ class DeleteApiTest < MiniTest::Test
|
|
59
59
|
body = '{"start":"2019-02-03T04:05:06+07:00","stop":"2019-03-03T04:05:06+07:00","predicate":"key1=\"value1\" ' \
|
60
60
|
'AND key2=\"value\""}'
|
61
61
|
|
62
|
-
assert_requested(:post, 'http://localhost:
|
62
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/delete?bucket=my-bucket&org=my-org', times: 1, body: body)
|
63
63
|
end
|
64
64
|
|
65
65
|
def test_delete_time_as_string
|
66
|
-
stub_request(:any, 'http://localhost:
|
66
|
+
stub_request(:any, 'http://localhost:8086/api/v2/delete?bucket=my-bucket&org=my-org')
|
67
67
|
.to_return(status: 204)
|
68
|
-
client = InfluxDB2::Client.new('http://localhost:
|
68
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
69
69
|
bucket: 'my-bucket',
|
70
70
|
org: 'my-org',
|
71
71
|
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
@@ -77,13 +77,13 @@ class DeleteApiTest < MiniTest::Test
|
|
77
77
|
body = '{"start":"2019-02-03T04:05:06+07:00","stop":"2019-04-03T04:05:06+07:00","predicate":"key1=\"value1\" ' \
|
78
78
|
'AND key2=\"value\""}'
|
79
79
|
|
80
|
-
assert_requested(:post, 'http://localhost:
|
80
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/delete?bucket=my-bucket&org=my-org', times: 1, body: body)
|
81
81
|
end
|
82
82
|
|
83
83
|
def test_without_predicate
|
84
|
-
stub_request(:any, 'http://localhost:
|
84
|
+
stub_request(:any, 'http://localhost:8086/api/v2/delete?bucket=my-bucket&org=my-org')
|
85
85
|
.to_return(status: 204)
|
86
|
-
client = InfluxDB2::Client.new('http://localhost:
|
86
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
87
87
|
bucket: 'my-bucket',
|
88
88
|
org: 'my-org',
|
89
89
|
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
@@ -94,13 +94,13 @@ class DeleteApiTest < MiniTest::Test
|
|
94
94
|
|
95
95
|
body = '{"start":"2019-02-03T04:05:06+07:00","stop":"2019-04-03T04:05:06+07:00"}'
|
96
96
|
|
97
|
-
assert_requested(:post, 'http://localhost:
|
97
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/delete?bucket=my-bucket&org=my-org', times: 1, body: body)
|
98
98
|
end
|
99
99
|
|
100
100
|
def test_user_agent_header
|
101
|
-
stub_request(:any, 'http://localhost:
|
101
|
+
stub_request(:any, 'http://localhost:8086/api/v2/delete?bucket=my-bucket&org=my-org')
|
102
102
|
.to_return(status: 204)
|
103
|
-
client = InfluxDB2::Client.new('http://localhost:
|
103
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
104
104
|
bucket: 'my-bucket',
|
105
105
|
org: 'my-org',
|
106
106
|
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
@@ -115,7 +115,7 @@ class DeleteApiTest < MiniTest::Test
|
|
115
115
|
'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}",
|
116
116
|
'Content-Type' => 'application/json'
|
117
117
|
}
|
118
|
-
assert_requested(:post, 'http://localhost:
|
118
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/delete?bucket=my-bucket&org=my-org',
|
119
119
|
times: 1, body: body, headers: headers)
|
120
120
|
end
|
121
121
|
end
|
@@ -24,7 +24,7 @@ class QueryApiIntegrationTest < MiniTest::Test
|
|
24
24
|
def setup
|
25
25
|
WebMock.allow_net_connect!
|
26
26
|
|
27
|
-
@client = InfluxDB2::Client.new('http://localhost:
|
27
|
+
@client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
28
28
|
bucket: 'my-bucket',
|
29
29
|
org: 'my-org',
|
30
30
|
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
@@ -24,7 +24,7 @@ class QueryApiStreamTest < MiniTest::Test
|
|
24
24
|
def setup
|
25
25
|
WebMock.allow_net_connect!
|
26
26
|
|
27
|
-
@client = InfluxDB2::Client.new('http://localhost:
|
27
|
+
@client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
28
28
|
bucket: 'my-bucket',
|
29
29
|
org: 'my-org',
|
30
30
|
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
@@ -35,9 +35,9 @@ class QueryApiTest < MiniTest::Test
|
|
35
35
|
',,0,1970-01-01T00:00:20Z,1970-01-01T00:00:30Z,1970-01-01T00:00:20Z,22,free,mem,B,west'
|
36
36
|
|
37
37
|
def test_query_raw
|
38
|
-
stub_request(:post, 'http://localhost:
|
38
|
+
stub_request(:post, 'http://localhost:8086/api/v2/query?org=my-org')
|
39
39
|
.to_return(body: SUCCESS_DATA)
|
40
|
-
client = InfluxDB2::Client.new('http://localhost:
|
40
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
41
41
|
bucket: 'my-bucket',
|
42
42
|
org: 'my-org',
|
43
43
|
use_ssl: false)
|
@@ -50,10 +50,10 @@ class QueryApiTest < MiniTest::Test
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def test_query
|
53
|
-
stub_request(:post, 'http://localhost:
|
53
|
+
stub_request(:post, 'http://localhost:8086/api/v2/query?org=my-org')
|
54
54
|
.to_return(body: SUCCESS_DATA)
|
55
55
|
|
56
|
-
client = InfluxDB2::Client.new('http://localhost:
|
56
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
57
57
|
bucket: 'my-bucket',
|
58
58
|
org: 'my-org',
|
59
59
|
use_ssl: false)
|
@@ -74,10 +74,10 @@ class QueryApiTest < MiniTest::Test
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_headers
|
77
|
-
stub_request(:post, 'http://localhost:
|
77
|
+
stub_request(:post, 'http://localhost:8086/api/v2/query?org=my-org')
|
78
78
|
.to_return(body: SUCCESS_DATA)
|
79
79
|
|
80
|
-
client = InfluxDB2::Client.new('http://localhost:
|
80
|
+
client = InfluxDB2::Client.new('http://localhost:8086', 'my-token',
|
81
81
|
bucket: 'my-bucket',
|
82
82
|
org: 'my-org',
|
83
83
|
use_ssl: false)
|
@@ -90,7 +90,7 @@ class QueryApiTest < MiniTest::Test
|
|
90
90
|
'User-Agent' => "influxdb-client-ruby/#{InfluxDB2::VERSION}",
|
91
91
|
'Content-Type' => 'application/json'
|
92
92
|
}
|
93
|
-
assert_requested(:post, 'http://localhost:
|
93
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/query?org=my-org',
|
94
94
|
times: 1, headers: headers)
|
95
95
|
end
|
96
96
|
end
|
@@ -26,7 +26,7 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
26
26
|
|
27
27
|
@write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
28
28
|
batch_size: 2, flush_interval: 5_000, retry_interval: 2_000)
|
29
|
-
@client = InfluxDB2::Client.new('http://localhost:
|
29
|
+
@client = InfluxDB2::Client.new('http://localhost:8086',
|
30
30
|
'my-token',
|
31
31
|
bucket: 'my-bucket',
|
32
32
|
org: 'my-org',
|
@@ -68,7 +68,7 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def test_batch_size
|
71
|
-
stub_request(:post, 'http://localhost:
|
71
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
72
72
|
.to_return(status: 204)
|
73
73
|
|
74
74
|
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=1.0 1')
|
@@ -83,20 +83,20 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
83
83
|
request2 = "h2o_feet,location=coyote_creek level\\ water_level=3.0 3\n" \
|
84
84
|
'h2o_feet,location=coyote_creek level\\ water_level=4.0 4'
|
85
85
|
|
86
|
-
assert_requested(:post, 'http://localhost:
|
86
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
87
87
|
times: 1, body: request1)
|
88
|
-
assert_requested(:post, 'http://localhost:
|
88
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
89
89
|
times: 1, body: request2)
|
90
90
|
end
|
91
91
|
|
92
92
|
def test_batch_size_group_by
|
93
|
-
stub_request(:post, 'http://localhost:
|
93
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
94
94
|
.to_return(status: 204)
|
95
|
-
stub_request(:post, 'http://localhost:
|
95
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=s')
|
96
96
|
.to_return(status: 204)
|
97
|
-
stub_request(:post, 'http://localhost:
|
97
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org-a&precision=ns')
|
98
98
|
.to_return(status: 204)
|
99
|
-
stub_request(:post, 'http://localhost:
|
99
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket2&org=my-org-a&precision=ns')
|
100
100
|
.to_return(status: 204)
|
101
101
|
|
102
102
|
bucket = 'my-bucket'
|
@@ -113,21 +113,21 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
113
113
|
|
114
114
|
sleep(1)
|
115
115
|
|
116
|
-
assert_requested(:post, 'http://localhost:
|
116
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
117
117
|
times: 1, body: 'h2o_feet,location=coyote_creek level\\ water_level=1.0 1')
|
118
|
-
assert_requested(:post, 'http://localhost:
|
118
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=s',
|
119
119
|
times: 1, body: 'h2o_feet,location=coyote_creek level\\ water_level=2.0 2')
|
120
|
-
assert_requested(:post, 'http://localhost:
|
120
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org-a&precision=ns',
|
121
121
|
times: 1, body: "h2o_feet,location=coyote_creek level\\ water_level=3.0 3\n" \
|
122
122
|
'h2o_feet,location=coyote_creek level\\ water_level=4.0 4')
|
123
|
-
assert_requested(:post, 'http://localhost:
|
123
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket2&org=my-org-a&precision=ns',
|
124
124
|
times: 1, body: 'h2o_feet,location=coyote_creek level\\ water_level=5.0 5')
|
125
|
-
assert_requested(:post, 'http://localhost:
|
125
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org-a&precision=ns',
|
126
126
|
times: 1, body: 'h2o_feet,location=coyote_creek level\\ water_level=6.0 6')
|
127
127
|
end
|
128
128
|
|
129
129
|
def test_flush_interval
|
130
|
-
stub_request(:post, 'http://localhost:
|
130
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
131
131
|
.to_return(status: 204)
|
132
132
|
|
133
133
|
request1 = "h2o_feet,location=coyote_creek level\\ water_level=1.0 1\n" \
|
@@ -139,31 +139,31 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
139
139
|
|
140
140
|
sleep(1)
|
141
141
|
|
142
|
-
assert_requested(:post, 'http://localhost:
|
142
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
143
143
|
times: 1, body: request1)
|
144
144
|
|
145
145
|
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=3.0 3')
|
146
146
|
|
147
147
|
sleep(2)
|
148
148
|
|
149
|
-
assert_requested(:post, 'http://localhost:
|
149
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
150
150
|
times: 0, body: request2)
|
151
151
|
|
152
152
|
sleep(3)
|
153
153
|
|
154
|
-
assert_requested(:post, 'http://localhost:
|
154
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
155
155
|
times: 1, body: request2)
|
156
156
|
end
|
157
157
|
|
158
158
|
def test_flush_all_by_close_client
|
159
|
-
stub_request(:post, 'http://localhost:
|
159
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
160
160
|
.to_return(status: 204)
|
161
161
|
|
162
162
|
@client.close!
|
163
163
|
|
164
164
|
@write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
165
165
|
batch_size: 10, flush_interval: 5_000)
|
166
|
-
@client = InfluxDB2::Client.new('http://localhost:
|
166
|
+
@client = InfluxDB2::Client.new('http://localhost:8086',
|
167
167
|
'my-token',
|
168
168
|
bucket: 'my-bucket',
|
169
169
|
org: 'my-org',
|
@@ -176,22 +176,81 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
176
176
|
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=2.0 2')
|
177
177
|
@write_client.write(data: 'h2o_feet,location=coyote_creek level\\ water_level=3.0 3')
|
178
178
|
|
179
|
-
assert_requested(:post, 'http://localhost:
|
179
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
180
180
|
times: 0, body: 'h2o_feet,location=coyote_creek level\\ water_level=3.0 3')
|
181
181
|
|
182
182
|
@client.close!
|
183
183
|
|
184
|
-
assert_requested(:post, 'http://localhost:
|
184
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
185
185
|
times: 1, body: "h2o_feet,location=coyote_creek level\\ water_level=1.0 1\n" \
|
186
186
|
"h2o_feet,location=coyote_creek level\\ water_level=2.0 2\n" \
|
187
187
|
'h2o_feet,location=coyote_creek level\\ water_level=3.0 3')
|
188
188
|
end
|
189
189
|
|
190
|
+
def test_jitter_interval
|
191
|
+
@client.close!
|
192
|
+
|
193
|
+
@client = InfluxDB2::Client.new('http://localhost:8086',
|
194
|
+
'my-token',
|
195
|
+
bucket: 'my-bucket',
|
196
|
+
org: 'my-org',
|
197
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
198
|
+
use_ssl: false)
|
199
|
+
|
200
|
+
@write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
201
|
+
batch_size: 2, flush_interval: 5_000, jitter_interval: 2_000)
|
202
|
+
@write_client = @client.create_write_api(write_options: @write_options)
|
203
|
+
|
204
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
205
|
+
.to_return(status: 204)
|
206
|
+
|
207
|
+
request = "h2o_feet,location=coyote_creek water_level=1.0 1\n" \
|
208
|
+
'h2o_feet,location=coyote_creek water_level=2.0 2'
|
209
|
+
|
210
|
+
@write_client.write(data: ['h2o_feet,location=coyote_creek water_level=1.0 1',
|
211
|
+
'h2o_feet,location=coyote_creek water_level=2.0 2'])
|
212
|
+
|
213
|
+
sleep(0.05)
|
214
|
+
|
215
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
216
|
+
times: 0, body: request)
|
217
|
+
|
218
|
+
sleep(2)
|
219
|
+
|
220
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
221
|
+
times: 1, body: request)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
class WriteApiRetryStrategyTest < MiniTest::Test
|
226
|
+
def setup
|
227
|
+
WebMock.disable_net_connect!
|
228
|
+
|
229
|
+
@write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
230
|
+
batch_size: 2, flush_interval: 5_000, retry_interval: 2_000)
|
231
|
+
@client = InfluxDB2::Client.new('http://localhost:8086',
|
232
|
+
'my-token',
|
233
|
+
bucket: 'my-bucket',
|
234
|
+
org: 'my-org',
|
235
|
+
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
236
|
+
use_ssl: false)
|
237
|
+
|
238
|
+
@write_client = @client.create_write_api(write_options: @write_options)
|
239
|
+
end
|
240
|
+
|
241
|
+
def teardown
|
242
|
+
@client.close!
|
243
|
+
|
244
|
+
assert_equal true, @write_client.closed
|
245
|
+
|
246
|
+
WebMock.reset!
|
247
|
+
end
|
248
|
+
|
190
249
|
def test_retry_interval_by_config
|
191
250
|
error_body = '{"code":"temporarily unavailable","message":"Token is temporarily over quota. '\
|
192
251
|
'The Retry-After header describes when to try the write again."}'
|
193
252
|
|
194
|
-
stub_request(:post, 'http://localhost:
|
253
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
195
254
|
.to_return(status: 429, headers: { 'X-Platform-Error-Code' => 'temporarily unavailable' }, body: error_body).then
|
196
255
|
.to_return(status: 204)
|
197
256
|
|
@@ -203,17 +262,17 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
203
262
|
|
204
263
|
sleep(0.5)
|
205
264
|
|
206
|
-
assert_requested(:post, 'http://localhost:
|
265
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
207
266
|
times: 1, body: request)
|
208
267
|
|
209
268
|
sleep(1)
|
210
269
|
|
211
|
-
assert_requested(:post, 'http://localhost:
|
270
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
212
271
|
times: 1, body: request)
|
213
272
|
|
214
|
-
sleep(
|
273
|
+
sleep(5)
|
215
274
|
|
216
|
-
assert_requested(:post, 'http://localhost:
|
275
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
217
276
|
times: 2, body: request)
|
218
277
|
end
|
219
278
|
|
@@ -221,7 +280,7 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
221
280
|
error_body = '{"code":"temporarily unavailable","message":"Server is temporarily unavailable to accept writes. '\
|
222
281
|
'The Retry-After header describes when to try the write again."}'
|
223
282
|
|
224
|
-
stub_request(:post, 'http://localhost:
|
283
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
225
284
|
.to_return(status: 503, headers: { 'X-Platform-Error-Code' => 'temporarily unavailable', 'Retry-After' => '3' },
|
226
285
|
body: error_body).then
|
227
286
|
.to_return(status: 204)
|
@@ -237,56 +296,253 @@ class WriteApiBatchingTest < MiniTest::Test
|
|
237
296
|
|
238
297
|
sleep(0.5)
|
239
298
|
|
240
|
-
assert_requested(:post, 'http://localhost:
|
299
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
241
300
|
times: 1, body: request)
|
242
301
|
|
243
302
|
sleep(1)
|
244
303
|
|
245
|
-
assert_requested(:post, 'http://localhost:
|
304
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
246
305
|
times: 1, body: request)
|
247
306
|
|
248
307
|
sleep(1)
|
249
308
|
|
250
|
-
assert_requested(:post, 'http://localhost:
|
309
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
251
310
|
times: 1, body: request)
|
252
311
|
|
253
312
|
sleep(1)
|
254
313
|
|
255
|
-
assert_requested(:post, 'http://localhost:
|
314
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
256
315
|
times: 2, body: request)
|
257
316
|
end
|
258
317
|
|
259
|
-
def
|
260
|
-
|
318
|
+
def test_max_retries
|
319
|
+
error_body = '{"code":"temporarily unavailable","message":"Server is temporarily unavailable to accept writes. '\
|
320
|
+
'The Retry-After header describes when to try the write again."}'
|
261
321
|
|
262
|
-
|
263
|
-
'my-token',
|
264
|
-
bucket: 'my-bucket',
|
265
|
-
org: 'my-org',
|
266
|
-
precision: InfluxDB2::WritePrecision::NANOSECOND,
|
267
|
-
use_ssl: false)
|
322
|
+
headers = { 'X-Platform-Error-Code' => 'temporarily unavailable' }
|
268
323
|
|
269
|
-
|
270
|
-
|
271
|
-
|
324
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
325
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
326
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
327
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
328
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
329
|
+
.to_return(status: 429, headers: headers, body: error_body) # not called
|
330
|
+
|
331
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
332
|
+
.add_tag('location', 'europe')
|
333
|
+
.add_field('level', 2.0)
|
334
|
+
|
335
|
+
request = 'h2o,location=europe level=2.0'
|
336
|
+
|
337
|
+
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
338
|
+
batch_size: 1, retry_interval: 2_000, max_retries: 3,
|
339
|
+
max_retry_delay: 5_000, exponential_base: 2)
|
340
|
+
|
341
|
+
error = assert_raises InfluxDB2::InfluxError do
|
342
|
+
@client.create_write_api(write_options: write_options).write(data: point)
|
343
|
+
|
344
|
+
sleep(0.5)
|
345
|
+
|
346
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
347
|
+
times: 1, body: request)
|
348
|
+
|
349
|
+
sleep(2)
|
350
|
+
|
351
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
352
|
+
times: 2, body: request)
|
353
|
+
|
354
|
+
sleep(4)
|
355
|
+
|
356
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
357
|
+
times: 3, body: request)
|
272
358
|
|
273
|
-
|
359
|
+
sleep(5)
|
360
|
+
|
361
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
362
|
+
times: 4, body: request)
|
363
|
+
|
364
|
+
sleep(5)
|
365
|
+
|
366
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
367
|
+
times: 4, body: request)
|
368
|
+
|
369
|
+
sleep(5)
|
370
|
+
end
|
371
|
+
|
372
|
+
assert_equal('429', error.code)
|
373
|
+
|
374
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
375
|
+
times: 4, body: request)
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_influx_exception
|
379
|
+
error_body = '{"code":"invalid","message":"unable to parse '\
|
380
|
+
'\'h2o_feet, location=coyote_creek water_level=1.0 1\': missing tag key"}'
|
381
|
+
|
382
|
+
stub_request(:any, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
383
|
+
.to_return(status: 400, headers: { 'X-Platform-Error-Code' => 'invalid' }, body: error_body)
|
384
|
+
|
385
|
+
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
386
|
+
batch_size: 1, retry_interval: 2_000, max_retries: 3,
|
387
|
+
max_retry_delay: 5_000, exponential_base: 2)
|
388
|
+
|
389
|
+
error = assert_raises InfluxDB2::InfluxError do
|
390
|
+
@client.create_write_api(write_options: write_options).write(data: 'h2o,location=west value=33i 15')
|
391
|
+
|
392
|
+
sleep(1)
|
393
|
+
end
|
394
|
+
|
395
|
+
assert_equal '400', error.code
|
396
|
+
assert_equal 'invalid', error.reference
|
397
|
+
assert_equal "unable to parse 'h2o_feet, location=coyote_creek water_level=1.0 1': missing tag key", error.message
|
398
|
+
end
|
399
|
+
|
400
|
+
def test_max_retries_by_header
|
401
|
+
error_body = '{"code":"temporarily unavailable","message":"Server is temporarily unavailable to accept writes. '\
|
402
|
+
'The Retry-After header describes when to try the write again."}'
|
403
|
+
|
404
|
+
headers = { 'X-Platform-Error-Code' => 'temporarily unavailable', 'Retry-After' => '3' }
|
405
|
+
|
406
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
407
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
408
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
409
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
410
|
+
.to_return(status: 429, headers: headers, body: error_body).then # retry
|
411
|
+
.to_return(status: 429, headers: headers, body: error_body) # not called
|
412
|
+
|
413
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
414
|
+
.add_tag('location', 'europe')
|
415
|
+
.add_field('level', 2.0)
|
416
|
+
|
417
|
+
request = 'h2o,location=europe level=2.0'
|
418
|
+
|
419
|
+
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
420
|
+
batch_size: 1, retry_interval: 2_000, max_retries: 3,
|
421
|
+
max_retry_delay: 5_000, exponential_base: 2)
|
422
|
+
|
423
|
+
error = assert_raises InfluxDB2::InfluxError do
|
424
|
+
@client.create_write_api(write_options: write_options).write(data: point)
|
425
|
+
|
426
|
+
sleep(0.5)
|
427
|
+
|
428
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
429
|
+
times: 1, body: request)
|
430
|
+
|
431
|
+
sleep(3)
|
432
|
+
|
433
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
434
|
+
times: 2, body: request)
|
435
|
+
|
436
|
+
sleep(3)
|
437
|
+
|
438
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
439
|
+
times: 3, body: request)
|
440
|
+
|
441
|
+
sleep(3)
|
442
|
+
|
443
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
444
|
+
times: 4, body: request)
|
445
|
+
|
446
|
+
sleep(3)
|
447
|
+
end
|
448
|
+
|
449
|
+
assert_equal('429', error.code)
|
450
|
+
|
451
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
452
|
+
times: 4, body: request)
|
453
|
+
end
|
454
|
+
|
455
|
+
def test_connection_error
|
456
|
+
error_message = 'Failed to open TCP connection to localhost:8086' \
|
457
|
+
'(Connection refused - connect(2) for "localhost" port 8086)'
|
458
|
+
|
459
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
460
|
+
.to_raise(Errno::ECONNREFUSED.new(error_message))
|
461
|
+
.to_raise(Errno::ECONNREFUSED.new(error_message))
|
462
|
+
.to_raise(Errno::ECONNREFUSED.new(error_message))
|
463
|
+
.to_raise(Errno::ECONNREFUSED.new(error_message))
|
464
|
+
.to_raise(Errno::ECONNREFUSED.new(error_message))
|
465
|
+
|
466
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
467
|
+
.add_tag('location', 'europe')
|
468
|
+
.add_field('level', 2.0)
|
469
|
+
|
470
|
+
request = 'h2o,location=europe level=2.0'
|
471
|
+
|
472
|
+
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
473
|
+
batch_size: 1, retry_interval: 2_000, max_retries: 3,
|
474
|
+
max_retry_delay: 5_000, exponential_base: 2)
|
475
|
+
|
476
|
+
error = assert_raises InfluxDB2::InfluxError do
|
477
|
+
@client.create_write_api(write_options: write_options).write(data: point)
|
478
|
+
|
479
|
+
sleep(0.5)
|
480
|
+
|
481
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
482
|
+
times: 1, body: request)
|
483
|
+
|
484
|
+
sleep(2)
|
485
|
+
|
486
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
487
|
+
times: 2, body: request)
|
488
|
+
|
489
|
+
sleep(4)
|
490
|
+
|
491
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
492
|
+
times: 3, body: request)
|
493
|
+
|
494
|
+
sleep(5)
|
495
|
+
|
496
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
497
|
+
times: 4, body: request)
|
498
|
+
|
499
|
+
sleep(5)
|
500
|
+
|
501
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
502
|
+
times: 4, body: request)
|
503
|
+
|
504
|
+
sleep(5)
|
505
|
+
end
|
506
|
+
|
507
|
+
assert_equal('Connection refused - ' + error_message, error.message)
|
508
|
+
end
|
509
|
+
|
510
|
+
def test_write_connection_error
|
511
|
+
stub_request(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns')
|
512
|
+
.to_raise(Errno::ECONNREFUSED.new(''))
|
513
|
+
.to_raise(Errno::ECONNREFUSED.new(''))
|
274
514
|
.to_return(status: 204)
|
275
515
|
|
276
|
-
|
277
|
-
|
516
|
+
point = InfluxDB2::Point.new(name: 'h2o')
|
517
|
+
.add_tag('location', 'europe')
|
518
|
+
.add_field('level', 2.0)
|
278
519
|
|
279
|
-
|
280
|
-
'h2o_feet,location=coyote_creek water_level=2.0 2'])
|
520
|
+
request = 'h2o,location=europe level=2.0'
|
281
521
|
|
282
|
-
|
522
|
+
write_options = InfluxDB2::WriteOptions.new(write_type: InfluxDB2::WriteType::BATCHING,
|
523
|
+
batch_size: 1, retry_interval: 2_000, max_retries: 3,
|
524
|
+
max_retry_delay: 5_000, exponential_base: 2)
|
283
525
|
|
284
|
-
|
285
|
-
times: 0, body: request)
|
526
|
+
@client.create_write_api(write_options: write_options).write(data: point)
|
286
527
|
|
287
|
-
sleep(
|
528
|
+
sleep(0.5)
|
288
529
|
|
289
|
-
assert_requested(:post, 'http://localhost:
|
530
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
290
531
|
times: 1, body: request)
|
532
|
+
|
533
|
+
sleep(2)
|
534
|
+
|
535
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
536
|
+
times: 2, body: request)
|
537
|
+
|
538
|
+
sleep(4)
|
539
|
+
|
540
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
541
|
+
times: 3, body: request)
|
542
|
+
|
543
|
+
sleep(5)
|
544
|
+
|
545
|
+
assert_requested(:post, 'http://localhost:8086/api/v2/write?bucket=my-bucket&org=my-org&precision=ns',
|
546
|
+
times: 3, body: request)
|
291
547
|
end
|
292
548
|
end
|