From dd4d6a68d1668fe92a0982b0decff5e3189bbbc3 Mon Sep 17 00:00:00 2001 From: Ron Rothman Date: Fri, 14 Dec 2018 05:59:31 -0500 Subject: [PATCH 1/4] add consistency parameter to write_points [https://github.com/influxdata/influxdb-python/issues/643] --- influxdb/client.py | 18 ++++++++++++++---- influxdb/tests/client_test.py | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/influxdb/client.py b/influxdb/client.py index 8f8b14ae..75a2facb 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -440,7 +440,8 @@ def write_points(self, retention_policy=None, tags=None, batch_size=None, - protocol='json' + protocol='json', + consistency=None ): """Write to multiple time series names. @@ -468,6 +469,8 @@ def write_points(self, :type batch_size: int :param protocol: Protocol for writing data. Either 'line' or 'json'. :type protocol: str + :param consistency: Consistency for the points. One of {'any','one','quorum','all'}. + :type consistency: str :returns: True, if the operation is successful :rtype: bool @@ -480,14 +483,14 @@ def write_points(self, time_precision=time_precision, database=database, retention_policy=retention_policy, - tags=tags, protocol=protocol) + tags=tags, protocol=protocol, consistency=consistency) return True return self._write_points(points=points, time_precision=time_precision, database=database, retention_policy=retention_policy, - tags=tags, protocol=protocol) + tags=tags, protocol=protocol, consistency=consistency) def ping(self): """Check connectivity to InfluxDB. @@ -513,12 +516,16 @@ def _write_points(self, database, retention_policy, tags, - protocol='json'): + protocol='json', + consistency=None): if time_precision not in ['n', 'u', 'ms', 's', 'm', 'h', None]: raise ValueError( "Invalid time precision is given. " "(use 'n', 'u', 'ms', 's', 'm' or 'h')") + if consistency not in ['any', 'one', 'quorum', 'all', None]: + raise ValueError('Invalid consistency: {}'.format(consistency)) + if protocol == 'json': data = { 'points': points @@ -533,6 +540,9 @@ def _write_points(self, 'db': database or self._database } + if consistency is not None: + params['consistency'] = consistency + if time_precision is not None: params['precision'] = time_precision diff --git a/influxdb/tests/client_test.py b/influxdb/tests/client_test.py index e27eef17..405584ff 100644 --- a/influxdb/tests/client_test.py +++ b/influxdb/tests/client_test.py @@ -337,6 +337,23 @@ def test_write_points_with_precision(self): m.last_request.body, ) + def test_write_points_with_consistency(self): + '''Test write points with consistency for TestInfluxDBClient object.''' + with requests_mock.Mocker() as m: + m.register_uri( + requests_mock.POST, + 'http://localhost:8086/write', + status_code=204 + ) + + cli = InfluxDBClient(database='db') + + cli.write_points(self.dummy_points, consistency='any') + self.assertEqual( + m.last_request.qs, + {'db': ['db'], 'consistency': ['any']} + ) + def test_write_points_with_precision_udp(self): """Test write points with precision for TestInfluxDBClient object.""" s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) @@ -409,6 +426,15 @@ def test_write_points_bad_precision(self): time_precision='g' ) + def test_write_points_bad_consistency(self): + """Test write points w/bad consistency value.""" + cli = InfluxDBClient() + with self.assertRaises(ValueError): + cli.write_points( + self.dummy_points, + consistency='boo' + ) + @raises(Exception) def test_write_points_with_precision_fails(self): """Test write points w/precision fail for TestInfluxDBClient object.""" From be8022634fb7ce70cf6e60c4f14a3f12acf4e8b9 Mon Sep 17 00:00:00 2001 From: Ron Rothman Date: Fri, 14 Dec 2018 07:24:17 -0500 Subject: [PATCH 2/4] update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14a9abf4..bd24f2d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added ### Changed +- Add consistency param to InfluxDBClient.write_points (#643) ### Removed From f70f5892bf4745f36a311f139466669487408b27 Mon Sep 17 00:00:00 2001 From: Ron Rothman Date: Mon, 8 Apr 2019 01:34:43 -0400 Subject: [PATCH 3/4] Update client.py satisfy flake8 --- influxdb/client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/influxdb/client.py b/influxdb/client.py index 63d24d9b..45e7391f 100644 --- a/influxdb/client.py +++ b/influxdb/client.py @@ -487,7 +487,8 @@ def write_points(self, :type batch_size: int :param protocol: Protocol for writing data. Either 'line' or 'json'. :type protocol: str - :param consistency: Consistency for the points. One of {'any','one','quorum','all'}. + :param consistency: Consistency for the points. + One of {'any','one','quorum','all'}. :type consistency: str :returns: True, if the operation is successful :rtype: bool @@ -501,14 +502,16 @@ def write_points(self, time_precision=time_precision, database=database, retention_policy=retention_policy, - tags=tags, protocol=protocol, consistency=consistency) + tags=tags, protocol=protocol, + consistency=consistency) return True return self._write_points(points=points, time_precision=time_precision, database=database, retention_policy=retention_policy, - tags=tags, protocol=protocol, consistency=consistency) + tags=tags, protocol=protocol, + consistency=consistency) def ping(self): """Check connectivity to InfluxDB. From db8db3435454d99ff22b6e1688d1827a0f94459c Mon Sep 17 00:00:00 2001 From: Ron Rothman Date: Mon, 8 Apr 2019 01:35:49 -0400 Subject: [PATCH 4/4] Update client_test.py satisfy pep257 --- influxdb/tests/client_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb/tests/client_test.py b/influxdb/tests/client_test.py index b04a68e8..e4cc7e11 100644 --- a/influxdb/tests/client_test.py +++ b/influxdb/tests/client_test.py @@ -338,7 +338,7 @@ def test_write_points_with_precision(self): ) def test_write_points_with_consistency(self): - '''Test write points with consistency for TestInfluxDBClient object.''' + """Test write points with consistency for TestInfluxDBClient object.""" with requests_mock.Mocker() as m: m.register_uri( requests_mock.POST, pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy