@@ -35,6 +35,8 @@ def __init__(self, url, token, debug=None, timeout=10000, enable_gzip=False, org
35
35
:key bool verify_ssl: Set this to false to skip verifying SSL certificate when calling API from https server.
36
36
:key str ssl_ca_cert: Set this to customize the certificate file to verify the peer.
37
37
:key str proxy: Set this to configure the http proxy to be used (ex. http://localhost:3128)
38
+ :key int connection_pool_maxsize: Number of connections to save that can be reused by urllib3.
39
+ Defaults to "multiprocessing.cpu_count() * 5".
38
40
:key urllib3.util.retry.Retry retries: Set the default retry strategy that is used for all HTTP requests
39
41
except batching writes. As a default there is no one retry strategy.
40
42
@@ -56,6 +58,7 @@ def __init__(self, url, token, debug=None, timeout=10000, enable_gzip=False, org
56
58
conf .verify_ssl = kwargs .get ('verify_ssl' , True )
57
59
conf .ssl_ca_cert = kwargs .get ('ssl_ca_cert' , None )
58
60
conf .proxy = kwargs .get ('proxy' , None )
61
+ conf .connection_pool_maxsize = kwargs .get ('connection_pool_maxsize' , conf .connection_pool_maxsize )
59
62
60
63
auth_token = self .token
61
64
auth_header_name = "Authorization"
@@ -82,6 +85,7 @@ def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gz
82
85
- timeout,
83
86
- verify_ssl
84
87
- ssl_ca_cert
88
+ - connection_pool_maxsize
85
89
86
90
config.ini example::
87
91
@@ -90,6 +94,7 @@ def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gz
90
94
org=my-org
91
95
token=my-token
92
96
timeout=6000
97
+ connection_pool_maxsize=25
93
98
94
99
[tags]
95
100
id = 132-987-655
@@ -103,6 +108,7 @@ def from_config_file(cls, config_file: str = "config.ini", debug=None, enable_gz
103
108
token = "my-token"
104
109
org = "my-org"
105
110
timeout = 6000
111
+ connection_pool_maxsize = 25
106
112
107
113
[tags]
108
114
id = "132-987-655"
@@ -137,18 +143,19 @@ def config_value(key: str):
137
143
if config .has_option ('influx2' , 'ssl_ca_cert' ):
138
144
ssl_ca_cert = config_value ('ssl_ca_cert' )
139
145
146
+ connection_pool_maxsize = None
147
+ if config .has_option ('influx2' , 'connection_pool_maxsize' ):
148
+ connection_pool_maxsize = config_value ('connection_pool_maxsize' )
149
+
140
150
default_tags = None
141
151
142
152
if config .has_section ('tags' ):
143
153
tags = {k : v .strip ('"' ) for k , v in config .items ('tags' )}
144
154
default_tags = dict (tags )
145
155
146
- if timeout :
147
- return cls (url , token , debug = debug , timeout = int (timeout ), org = org , default_tags = default_tags ,
148
- enable_gzip = enable_gzip , verify_ssl = _to_bool (verify_ssl ), ssl_ca_cert = ssl_ca_cert )
149
-
150
- return cls (url , token , debug = debug , org = org , default_tags = default_tags , enable_gzip = enable_gzip ,
151
- verify_ssl = _to_bool (verify_ssl ), ssl_ca_cert = ssl_ca_cert )
156
+ return cls (url , token , debug = debug , timeout = _to_int (timeout ), org = org , default_tags = default_tags ,
157
+ enable_gzip = enable_gzip , verify_ssl = _to_bool (verify_ssl ), ssl_ca_cert = ssl_ca_cert ,
158
+ connection_pool_maxsize = _to_int (connection_pool_maxsize ))
152
159
153
160
@classmethod
154
161
def from_env_properties (cls , debug = None , enable_gzip = False ):
@@ -162,22 +169,25 @@ def from_env_properties(cls, debug=None, enable_gzip=False):
162
169
- INFLUXDB_V2_TIMEOUT
163
170
- INFLUXDB_V2_VERIFY_SSL
164
171
- INFLUXDB_V2_SSL_CA_CERT
172
+ - INFLUXDB_V2_CONNECTION_POOL_MAXSIZE
165
173
"""
166
174
url = os .getenv ('INFLUXDB_V2_URL' , "http://localhost:8086" )
167
175
token = os .getenv ('INFLUXDB_V2_TOKEN' , "my-token" )
168
176
timeout = os .getenv ('INFLUXDB_V2_TIMEOUT' , "10000" )
169
177
org = os .getenv ('INFLUXDB_V2_ORG' , "my-org" )
170
178
verify_ssl = os .getenv ('INFLUXDB_V2_VERIFY_SSL' , "True" )
171
179
ssl_ca_cert = os .getenv ('INFLUXDB_V2_SSL_CA_CERT' , None )
180
+ connection_pool_maxsize = os .getenv ('INFLUXDB_V2_CONNECTION_POOL_MAXSIZE' , None )
172
181
173
182
default_tags = dict ()
174
183
175
184
for key , value in os .environ .items ():
176
185
if key .startswith ("INFLUXDB_V2_TAG_" ):
177
186
default_tags [key [16 :].lower ()] = value
178
187
179
- return cls (url , token , debug = debug , timeout = int (timeout ), org = org , default_tags = default_tags ,
180
- enable_gzip = enable_gzip , verify_ssl = _to_bool (verify_ssl ), ssl_ca_cert = ssl_ca_cert )
188
+ return cls (url , token , debug = debug , timeout = _to_int (timeout ), org = org , default_tags = default_tags ,
189
+ enable_gzip = enable_gzip , verify_ssl = _to_bool (verify_ssl ), ssl_ca_cert = ssl_ca_cert ,
190
+ connection_pool_maxsize = _to_int (connection_pool_maxsize ))
181
191
182
192
def write_api (self , write_options = WriteOptions (), point_settings = PointSettings ()) -> WriteApi :
183
193
"""
@@ -322,5 +332,9 @@ def update_request_body(self, path: str, body):
322
332
return _body
323
333
324
334
325
- def _to_bool (verify_ssl ):
326
- return str (verify_ssl ).lower () in ("yes" , "true" )
335
+ def _to_bool (bool_value ):
336
+ return str (bool_value ).lower () in ("yes" , "true" )
337
+
338
+
339
+ def _to_int (int_value ):
340
+ return int (int_value ) if int_value is not None else None
0 commit comments