|
10 | 10 | from influxdb_client_3.write_client import InfluxDBClient as _InfluxDBClient, WriteOptions, Point |
11 | 11 | from influxdb_client_3.write_client.client.exceptions import InfluxDBError |
12 | 12 | from influxdb_client_3.write_client.client.write_api import WriteApi as _WriteApi, SYNCHRONOUS, ASYNCHRONOUS, \ |
13 | | - PointSettings, WriteType |
| 13 | + PointSettings, WriteType, DefaultWriteOptions |
14 | 14 | from influxdb_client_3.write_client.domain.write_precision import WritePrecision |
15 | 15 |
|
16 | 16 | polars = importlib.util.find_spec("polars") is not None |
@@ -57,6 +57,7 @@ def file_parser_options(**kwargs): |
57 | 57 | INFLUX_ORG = "INFLUX_ORG" |
58 | 58 | INFLUX_PRECISION = "INFLUX_PRECISION" |
59 | 59 | INFLUX_AUTH_SCHEME = "INFLUX_AUTH_SCHEME" |
| 60 | +INFLUX_GZIP_THRESHOLD = "INFLUX_GZIP_THRESHOLD" |
60 | 61 |
|
61 | 62 |
|
62 | 63 | def from_env(**kwargs: Any) -> 'InfluxDBClient3': |
@@ -92,16 +93,20 @@ def from_env(**kwargs: Any) -> 'InfluxDBClient3': |
92 | 93 | if missing_vars: |
93 | 94 | raise ValueError(f"Missing required environment variables: {', '.join(missing_vars)}") |
94 | 95 |
|
95 | | - org = os.getenv(INFLUX_ORG, "default") |
| 96 | + write_options = WriteOptions(write_type=WriteType.synchronous) |
| 97 | + |
| 98 | + if os.getenv(INFLUX_GZIP_THRESHOLD) is not None: |
| 99 | + write_options.gzip_threshold = int(os.getenv(INFLUX_GZIP_THRESHOLD)) |
| 100 | + |
| 101 | + if os.getenv(INFLUX_PRECISION) is not None: |
| 102 | + write_options.write_precision = os.getenv(INFLUX_PRECISION) |
| 103 | + |
| 104 | + write_client_option = {'write_options': write_options} |
96 | 105 |
|
97 | 106 | if os.getenv(INFLUX_AUTH_SCHEME) is not None: |
98 | 107 | kwargs['auth_scheme'] = os.getenv(INFLUX_AUTH_SCHEME) |
99 | | - |
100 | | - write_client_option = None |
101 | | - if os.getenv(INFLUX_PRECISION) is not None: |
102 | | - write_client_option = default_client_options( |
103 | | - write_options=WriteOptions(write_type=WriteType.synchronous, write_precision=os.getenv(INFLUX_PRECISION)) |
104 | | - ) |
| 108 | + |
| 109 | + org = os.getenv(INFLUX_ORG, "default") |
105 | 110 |
|
106 | 111 | return InfluxDBClient3( |
107 | 112 | host=required_vars[INFLUX_HOST], |
@@ -202,8 +207,26 @@ def __init__( |
202 | 207 | self._org = org if org is not None else "default" |
203 | 208 | self._database = database |
204 | 209 | self._token = token |
205 | | - self._write_client_options = write_client_options if write_client_options is not None \ |
206 | | - else default_client_options(write_options=WriteOptions(write_type=WriteType.synchronous, write_precision=WritePrecision.NS)) |
| 210 | + |
| 211 | + write_type = DefaultWriteOptions['write_type'] |
| 212 | + write_precision = DefaultWriteOptions['write_precision'] |
| 213 | + gzip_threshold = DefaultWriteOptions['gzip_threshold'] |
| 214 | + if isinstance(write_client_options, dict) and write_client_options.get('write_options') is not None: |
| 215 | + write_opts = write_client_options['write_options'] |
| 216 | + write_type = getattr(write_opts, 'write_type') |
| 217 | + write_precision = getattr(write_opts, 'write_precision') |
| 218 | + gzip_threshold = getattr(write_opts, 'gzip_threshold') |
| 219 | + |
| 220 | + write_options = WriteOptions( |
| 221 | + write_type=write_type, |
| 222 | + write_precision=write_precision, |
| 223 | + gzip_threshold=gzip_threshold, |
| 224 | + ) |
| 225 | + |
| 226 | + self._write_client_options = { |
| 227 | + "write_options": write_options, |
| 228 | + **(write_client_options or {}) |
| 229 | + } |
207 | 230 |
|
208 | 231 | # Parse the host input |
209 | 232 | parsed_url = urllib.parse.urlparse(host) |
|
0 commit comments