Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Support compressed write #792

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import requests.exceptions
from six.moves import xrange
from six.moves.urllib.parse import urlparse
import gzip

from influxdb.line_protocol import make_lines, quote_ident, quote_literal
from influxdb.resultset import ResultSet
Expand Down Expand Up @@ -89,6 +90,7 @@ def __init__(self,
pool_size=10,
path='',
cert=None,
compression=False
):
"""Construct a new InfluxDBClient object."""
self.__host = host
Expand All @@ -98,6 +100,13 @@ def __init__(self,
self._database = database
self._timeout = timeout
self._retries = retries
if compression is True:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing as we don't know what type the compression parameter should be. Can you please update the function to include comments on what to expect from this paramater? Should self._compression be an int, bool, something else?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, actually it might be int or bool at that point. If it just True the code will choose a default int value. Seemed sensible to me back when I implemented it. Now I am not so sure anymore ... Suggestion?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if anything you should define two vars, one for the switch on/off of compression and another for the level.

self._compression = 9
else:
self._compression = compression

assert self._compression is False or \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should we blow up here if we don't match one of the values? This should be set to a proper default and move along without any issue for the user.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, ok, will do. Usualy I prefer my code to blow up instead of hiding bugs ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you flip this to be two parameters as outline above then this should give you enough assurance that things are working as expected.

(self._compression >= 0 and self._compression <= 9)

self._verify_ssl = verify_ssl

Expand Down Expand Up @@ -354,6 +363,10 @@ def write(self, data, params=None, expected_response_code=204,
data = [data]
data = ('\n'.join(data) + '\n').encode('utf-8')

if self._compression is not False:
data = gzip.compress(data, self._compression)
headers['Content-Encoding'] = 'gzip'

self.request(
url="write",
method='POST',
Expand Down