Skip to content

Commit 2f4b3fd

Browse files
committed
Allow disabling persistent connections
1 parent 7a29338 commit 2f4b3fd

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ found in `lib/influxdb/config.rb` for the source of truth.
770770
| | `:open_timeout` | 5 | socket timeout
771771
| | `:read_timeout` | 300 | socket timeout
772772
| | `:auth_method` | "params" | "params", "basic_auth" or "none"
773+
| | `:persistent` | true | set to false to disable persistent connections
773774
| Retry | `:retry` | -1 | max. number of retry attempts (reading and writing)
774775
| | `:initial_delay` | 0.01 | initial wait time (doubles every retry attempt)
775776
| | `:max_delay` | 30 | max. wait time when retrying

lib/influxdb/client/http.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ def generate_cert_store
136136
end
137137

138138
def get_http
139+
return build_http config.next_host unless config.persistent
140+
139141
@https ||=
140142
begin
141143
https = config.hosts.map { |host|

lib/influxdb/config.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ module InfluxDB
1818
auth_method: nil,
1919
proxy_addr: nil,
2020
proxy_port: nil,
21+
persistent: true,
2122

2223
# SSL options
2324
use_ssl: false,

spec/influxdb/client_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@
6060
end
6161
end
6262

63+
describe "#get_http" do
64+
it "returns an existing connection with persistence enabled" do
65+
first = subject.send :get_http
66+
second = subject.send :get_http
67+
68+
expect(first).to equal(second)
69+
end
70+
71+
it "returns a new connection with persistence disabled" do
72+
subject.config.persistent = false
73+
74+
first = subject.send :get_http
75+
second = subject.send :get_http
76+
77+
expect(first).to_not equal(second)
78+
end
79+
end
80+
6381
describe "GET #ping" do
6482
it "returns OK" do
6583
stub_request(:get, "http://influxdb.test:9999/ping")

spec/influxdb/config_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
specify { expect(conf.port).to eq 8086 }
1515
specify { expect(conf.username).to eq "root" }
1616
specify { expect(conf.password).to eq "root" }
17+
specify { expect(conf.persistent).to be_truthy }
1718
specify { expect(conf.use_ssl).to be_falsey }
1819
specify { expect(conf.time_precision).to eq "s" }
1920
specify { expect(conf.auth_method).to eq "params" }

0 commit comments

Comments
 (0)