This repository was archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 524
Support compressed write #792
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -89,6 +90,7 @@ def __init__(self, | |
pool_size=10, | ||
path='', | ||
cert=None, | ||
compression=False | ||
): | ||
"""Construct a new InfluxDBClient object.""" | ||
self.__host = host | ||
|
@@ -98,6 +100,13 @@ def __init__(self, | |
self._database = database | ||
self._timeout = timeout | ||
self._retries = retries | ||
if compression is True: | ||
self._compression = 9 | ||
else: | ||
self._compression = compression | ||
|
||
assert self._compression is False or \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
@@ -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', | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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? Shouldself._compression
be an int, bool, something else?There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.