Skip to content

Commit 175864c

Browse files
committed
fix: add missing gzip support for v3 api
1 parent c88f80a commit 175864c

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

influxdb_client_3/write_client/client/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def update_request_header_params(self, path: str, params: dict, should_gzip: boo
282282
super().update_request_header_params(path, params, should_gzip)
283283
if should_gzip:
284284
# GZIP Request
285-
if path == '/api/v2/write':
285+
if path == '/api/v2/write' or path == '/api/v3/write_lp':
286286
params["Content-Encoding"] = "gzip"
287287
params["Accept-Encoding"] = "identity"
288288
pass
@@ -298,7 +298,7 @@ def update_request_body(self, path: str, body, should_gzip: bool = False):
298298
_body = super().update_request_body(path, body, should_gzip)
299299
if should_gzip:
300300
# GZIP Request
301-
if path == '/api/v2/write':
301+
if path == '/api/v2/write' or path == '/api/v3/write_lp':
302302
import gzip
303303
if isinstance(_body, bytes):
304304
return gzip.compress(data=_body)

influxdb_client_3/write_client/client/write_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def _body_reduce(batch_items):
209209

210210
class WriteApi(_BaseWriteApi):
211211
"""
212-
Implementation for '/api/v2/write' endpoint.
212+
Implementation for '/api/v2/write' and '/api/v3/write_lp' endpoint.
213213
214214
Example:
215215
.. code-block:: python

tests/test_write_integration.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_write_with_write_options(self, httpserver: HTTPServer):
4545
write_precision=WritePrecision.US,
4646
no_sync=False
4747
)
48-
)
48+
),
4949
).write(self.SAMPLE_RECORD)
5050

5151
self.assert_request_made(httpserver, RequestMatcher(
@@ -87,3 +87,43 @@ def test_write_with_no_sync_true_on_v2_server(self, httpserver: HTTPServer):
8787
self.assert_request_made(httpserver, RequestMatcher(
8888
method="POST", uri="/api/v3/write_lp",
8989
query_string={"org": "ORG", "db": "DB", "precision": "nanosecond", "no_sync": "true"}))
90+
91+
def test_write_with_no_sync_false_and_gzip(self, httpserver: HTTPServer):
92+
self.set_response_status(httpserver, 200)
93+
94+
InfluxDBClient3(
95+
host=(httpserver.url_for("/")), org="ORG", database="DB", token="TOKEN",
96+
write_client_options=write_client_options(
97+
write_options=WriteOptions(
98+
write_type=WriteType.synchronous,
99+
write_precision=WritePrecision.US,
100+
no_sync=False
101+
)
102+
),
103+
enable_gzip=True
104+
).write(self.SAMPLE_RECORD)
105+
106+
self.assert_request_made(httpserver, RequestMatcher(
107+
method="POST", uri="/api/v2/write",
108+
query_string={"org": "ORG", "bucket": "DB", "precision": "us"},
109+
headers={"Content-Encoding": "gzip"}, ))
110+
111+
def test_write_with_no_sync_true_and_gzip(self, httpserver: HTTPServer):
112+
self.set_response_status(httpserver, 200)
113+
114+
InfluxDBClient3(
115+
host=(httpserver.url_for("/")), org="ORG", database="DB", token="TOKEN",
116+
write_client_options=write_client_options(
117+
write_options=WriteOptions(
118+
write_type=WriteType.synchronous,
119+
write_precision=WritePrecision.US,
120+
no_sync=True
121+
)
122+
),
123+
enable_gzip=True
124+
).write(self.SAMPLE_RECORD)
125+
126+
self.assert_request_made(httpserver, RequestMatcher(
127+
method="POST", uri="/api/v3/write_lp",
128+
query_string={"org": "ORG", "db": "DB", "precision": "microsecond", "no_sync": "true"},
129+
headers={"Content-Encoding": "gzip"}, ))

0 commit comments

Comments
 (0)