From f5bc155e0aecb9a31a17563a778b77fbcbf6ad46 Mon Sep 17 00:00:00 2001 From: Michael Perez Date: Thu, 27 Aug 2015 11:00:59 -0400 Subject: [PATCH 1/6] if value is int, type cast and add 'i' per changes in new influx --- influxdb/line_protocol.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/influxdb/line_protocol.py b/influxdb/line_protocol.py index 20ae74b2..2e21eb18 100644 --- a/influxdb/line_protocol.py +++ b/influxdb/line_protocol.py @@ -116,6 +116,8 @@ def make_lines(data, precision=None): key = _escape_tag(field_key) value = _escape_value(point['fields'][field_key]) if key != '' and value != '': + if isinstance(value, int): + value = str(value) + 'i' field_values.append("{key}={value}".format( key=key, value=value From f02d1a2d6d34af88da8f05d1e320713ab0cdb31d Mon Sep 17 00:00:00 2001 From: Joe Lombrozo Date: Thu, 27 Aug 2015 15:14:52 -0700 Subject: [PATCH 2/6] Moved 'i' flag where it should be added --- influxdb/line_protocol.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/influxdb/line_protocol.py b/influxdb/line_protocol.py index 2e21eb18..027c54da 100644 --- a/influxdb/line_protocol.py +++ b/influxdb/line_protocol.py @@ -59,6 +59,8 @@ def _escape_value(value): "\n", "\\n" ) ) + if isinstance(value, int): + return str(value) + 'i' else: return str(value) @@ -116,8 +118,6 @@ def make_lines(data, precision=None): key = _escape_tag(field_key) value = _escape_value(point['fields'][field_key]) if key != '' and value != '': - if isinstance(value, int): - value = str(value) + 'i' field_values.append("{key}={value}".format( key=key, value=value From f08bc34d5de83fe7e17aed6c2065b2a416798148 Mon Sep 17 00:00:00 2001 From: Joe Lombrozo Date: Thu, 27 Aug 2015 15:14:59 -0700 Subject: [PATCH 3/6] Fixed tests --- influxdb/tests/dataframe_client_test.py | 36 +++++++++---------- .../server_tests/client_test_with_server.py | 19 ++++++---- .../tests/server_tests/influxdb.conf.template | 3 +- .../tests/server_tests/influxdb_instance.py | 1 + influxdb/tests/test_line_protocol.py | 3 +- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/influxdb/tests/dataframe_client_test.py b/influxdb/tests/dataframe_client_test.py index edeb2ed0..0583ffba 100644 --- a/influxdb/tests/dataframe_client_test.py +++ b/influxdb/tests/dataframe_client_test.py @@ -32,8 +32,8 @@ def test_write_points_from_dataframe(self): columns=["column_one", "column_two", "column_three"]) expected = ( - b"foo column_one=\"1\",column_three=1.0,column_two=1 0\n" - b"foo column_one=\"2\",column_three=2.0,column_two=2 " + b"foo column_one=\"1\",column_three=1.0,column_two=1i 0\n" + b"foo column_one=\"2\",column_three=2.0,column_two=2i " b"3600000000000\n" ) @@ -71,8 +71,8 @@ def test_write_points_from_dataframe_with_numeric_column_names(self): index=[now, now + timedelta(hours=1)]) expected = ( - b'foo,hello=there 0=\"1\",1=1,2=1.0 0\n' - b'foo,hello=there 0=\"2\",1=2,2=2.0 3600000000000\n' + b'foo,hello=there 0=\"1\",1=1i,2=1.0 0\n' + b'foo,hello=there 0=\"2\",1=2i,2=2.0 3600000000000\n' ) with requests_mock.Mocker() as m: @@ -92,8 +92,8 @@ def test_write_points_from_dataframe_with_period_index(self): columns=["column_one", "column_two", "column_three"]) expected = ( - b"foo column_one=\"1\",column_three=1.0,column_two=1 0\n" - b"foo column_one=\"2\",column_three=2.0,column_two=2 " + b"foo column_one=\"1\",column_three=1.0,column_two=1i 0\n" + b"foo column_one=\"2\",column_three=2.0,column_two=2i " b"86400000000000\n" ) @@ -125,48 +125,48 @@ def test_write_points_from_dataframe_with_time_precision(self): cli.write_points(dataframe, measurement, time_precision='h') self.assertEqual(m.last_request.qs['precision'], ['h']) self.assertEqual( - b'foo column_one="1",column_three=1.0,column_two=1 0\nfoo ' - b'column_one="2",column_three=2.0,column_two=2 1\n', + b'foo column_one="1",column_three=1.0,column_two=1i 0\nfoo ' + b'column_one="2",column_three=2.0,column_two=2i 1\n', m.last_request.body, ) cli.write_points(dataframe, measurement, time_precision='m') self.assertEqual(m.last_request.qs['precision'], ['m']) self.assertEqual( - b'foo column_one="1",column_three=1.0,column_two=1 0\nfoo ' - b'column_one="2",column_three=2.0,column_two=2 60\n', + b'foo column_one="1",column_three=1.0,column_two=1i 0\nfoo ' + b'column_one="2",column_three=2.0,column_two=2i 60\n', m.last_request.body, ) cli.write_points(dataframe, measurement, time_precision='s') self.assertEqual(m.last_request.qs['precision'], ['s']) self.assertEqual( - b'foo column_one="1",column_three=1.0,column_two=1 0\nfoo ' - b'column_one="2",column_three=2.0,column_two=2 3600\n', + b'foo column_one="1",column_three=1.0,column_two=1i 0\nfoo ' + b'column_one="2",column_three=2.0,column_two=2i 3600\n', m.last_request.body, ) cli.write_points(dataframe, measurement, time_precision='ms') self.assertEqual(m.last_request.qs['precision'], ['ms']) self.assertEqual( - b'foo column_one="1",column_three=1.0,column_two=1 0\nfoo ' - b'column_one="2",column_three=2.0,column_two=2 3600000\n', + b'foo column_one="1",column_three=1.0,column_two=1i 0\nfoo ' + b'column_one="2",column_three=2.0,column_two=2i 3600000\n', m.last_request.body, ) cli.write_points(dataframe, measurement, time_precision='u') self.assertEqual(m.last_request.qs['precision'], ['u']) self.assertEqual( - b'foo column_one="1",column_three=1.0,column_two=1 0\nfoo ' - b'column_one="2",column_three=2.0,column_two=2 3600000000\n', + b'foo column_one="1",column_three=1.0,column_two=1i 0\nfoo ' + b'column_one="2",column_three=2.0,column_two=2i 3600000000\n', m.last_request.body, ) cli.write_points(dataframe, measurement, time_precision='n') self.assertEqual(m.last_request.qs['precision'], ['n']) self.assertEqual( - b'foo column_one="1",column_three=1.0,column_two=1 0\n' - b'foo column_one="2",column_three=2.0,column_two=2 ' + b'foo column_one="1",column_three=1.0,column_two=1i 0\n' + b'foo column_one="2",column_three=2.0,column_two=2i ' b'3600000000000\n', m.last_request.body, ) diff --git a/influxdb/tests/server_tests/client_test_with_server.py b/influxdb/tests/server_tests/client_test_with_server.py index 2cc2d1c3..ee150fa5 100644 --- a/influxdb/tests/server_tests/client_test_with_server.py +++ b/influxdb/tests/server_tests/client_test_with_server.py @@ -303,8 +303,8 @@ def test_write_check_read(self): self.test_write() time.sleep(1) rsp = self.cli.query('SELECT * FROM cpu_load_short', database='db') - self.assertListEqual([{'value': 0.64, - 'time': '2009-11-10T23:00:00Z'}], + self.assertListEqual([{'value': 0.64, 'time': '2009-11-10T23:00:00Z', + "host": "server01", "region": "us-west"}], list(rsp.get_points())) def test_write_points(self): @@ -328,7 +328,8 @@ def test_write_points_check_read(self): self.assertEqual( list(rsp), - [[{'value': 0.64, 'time': '2009-11-10T23:00:00Z'}]] + [[{'value': 0.64, 'time': '2009-11-10T23:00:00Z', + "host": "server01", "region": "us-west"}]] ) rsp2 = list(rsp.get_points()) @@ -337,7 +338,8 @@ def test_write_points_check_read(self): self.assertEqual( pt, - {'time': '2009-11-10T23:00:00Z', 'value': 0.64} + {'time': '2009-11-10T23:00:00Z', 'value': 0.64, + "host": "server01", "region": "us-west"} ) @unittest.skip("Broken as of 0.9.0") @@ -367,7 +369,8 @@ def test_write_multiple_points_different_series(self): lrsp = list(rsp) self.assertEqual( - [[{'value': 0.64, 'time': '2009-11-10T23:00:00Z'}]], + [[{'value': 0.64, 'time': '2009-11-10T23:00:00Z', + "host": "server01", "region": "us-west"}]], lrsp ) @@ -375,7 +378,8 @@ def test_write_multiple_points_different_series(self): self.assertEqual( rsp, - [[{'value': 33, 'time': '2009-11-10T23:01:35Z'}]] + [[{'value': 33, 'time': '2009-11-10T23:01:35Z', + "host": "server01", "region": "us-west"}]] ) @unittest.skip("Broken as of 0.9.0") @@ -678,6 +682,7 @@ def test_write_points_udp(self): self.assertEqual( # this is dummy_points : - [{'value': 0.64, 'time': '2009-11-10T23:00:00Z'}], + [{'value': 0.64, 'time': '2009-11-10T23:00:00Z', + "host": "server01", "region": "us-west"}], list(rsp['cpu_load_short']) ) diff --git a/influxdb/tests/server_tests/influxdb.conf.template b/influxdb/tests/server_tests/influxdb.conf.template index 92e381ee..a55c4190 100644 --- a/influxdb/tests/server_tests/influxdb.conf.template +++ b/influxdb/tests/server_tests/influxdb.conf.template @@ -10,6 +10,7 @@ [data] dir = "{data_dir}" + wal-dir = "{wal_dir}" retention-auto-create = true retention-check-enabled = true retention-check-period = "10m0s" @@ -54,7 +55,7 @@ retention-policy = "" consistency-level = "one" -[udp] +[[udp]] enabled = {udp_enabled} bind-address = ":{udp_port}" database = "db" diff --git a/influxdb/tests/server_tests/influxdb_instance.py b/influxdb/tests/server_tests/influxdb_instance.py index ae32bab6..700f2467 100644 --- a/influxdb/tests/server_tests/influxdb_instance.py +++ b/influxdb/tests/server_tests/influxdb_instance.py @@ -51,6 +51,7 @@ def __init__(self, conf_data = dict( meta_dir=os.path.join(tempdir, 'meta'), data_dir=os.path.join(tempdir, 'data'), + wal_dir=os.path.join(tempdir, 'wal'), cluster_dir=os.path.join(tempdir, 'state'), handoff_dir=os.path.join(tempdir, 'handoff'), logs_file=os.path.join(self.temp_dir_base, 'logs.txt'), diff --git a/influxdb/tests/test_line_protocol.py b/influxdb/tests/test_line_protocol.py index 6596e7b0..b7fba730 100644 --- a/influxdb/tests/test_line_protocol.py +++ b/influxdb/tests/test_line_protocol.py @@ -20,6 +20,7 @@ def test_make_lines(self): "fields": { "string_val": "hello!", "int_val": 1, + "float_val": 1.1, "none_field": None, } } @@ -29,7 +30,7 @@ def test_make_lines(self): self.assertEqual( line_protocol.make_lines(data), 'test,integer_tag=2,string_tag=hello ' - 'int_val=1,string_val="hello!"\n' + 'float_val=1.1,int_val=1i,string_val="hello!"\n' ) def test_string_val_newline(self): From a5b9a79fd5f3339aae230e25b11c6e207ebea600 Mon Sep 17 00:00:00 2001 From: Joe Lombrozo Date: Thu, 27 Aug 2015 16:10:50 -0700 Subject: [PATCH 4/6] Used six for compatibility --- influxdb/line_protocol.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/influxdb/line_protocol.py b/influxdb/line_protocol.py index 027c54da..6097dbe1 100644 --- a/influxdb/line_protocol.py +++ b/influxdb/line_protocol.py @@ -7,7 +7,7 @@ from numbers import Integral from dateutil.parser import parse -from six import binary_type, text_type +from six import binary_type, text_type, integer_types def _convert_timestamp(timestamp, precision=None): @@ -59,7 +59,7 @@ def _escape_value(value): "\n", "\\n" ) ) - if isinstance(value, int): + elif isinstance(value, integer_types): return str(value) + 'i' else: return str(value) From b5f1311efb1722db6c58dab71b939093195190c0 Mon Sep 17 00:00:00 2001 From: aviau Date: Fri, 28 Aug 2015 09:18:16 -0400 Subject: [PATCH 5/6] Test with InfluxDB 0.9.3 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e19ddf22..5de4454d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,10 +13,10 @@ install: - pip install tox - pip install coveralls - mkdir influxdb_install - - wget https://s3.amazonaws.com/influxdb/influxdb_0.9.2_amd64.deb + - wget https://s3.amazonaws.com/influxdb/influxdb_0.9.3_amd64.deb - dpkg -x influxdb_*_amd64.deb influxdb_install script: - - export INFLUXDB_PYTHON_INFLUXD_PATH=$(pwd)/influxdb_install/opt/influxdb/versions/0.9.2/influxd + - export INFLUXDB_PYTHON_INFLUXD_PATH=$(pwd)/influxdb_install/opt/influxdb/versions/0.9.3/influxd - travis_wait 30 tox -e $TOX_ENV after_success: - if [ "$TOX_ENV" == "coverage" ] ; then coveralls; fi From 78e5adad441767361bcc1a85393140a984394f1a Mon Sep 17 00:00:00 2001 From: aviau Date: Fri, 28 Aug 2015 09:49:34 -0400 Subject: [PATCH 6/6] Catch RuntimeError when starting InfluxDB --- influxdb/tests/server_tests/influxdb_instance.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/influxdb/tests/server_tests/influxdb_instance.py b/influxdb/tests/server_tests/influxdb_instance.py index 700f2467..c16e5053 100644 --- a/influxdb/tests/server_tests/influxdb_instance.py +++ b/influxdb/tests/server_tests/influxdb_instance.py @@ -31,6 +31,18 @@ def __init__(self, self.influxd_path = self.find_influxd_path() + errors = 0 + while True: + try: + self._start_server(conf_template, udp_enabled) + break + except RuntimeError: # Happens when the ports are already in use. + errors += 1 + if errors > 2: + raise e + + def _start_server(self, conf_template, udp_enabled): + # create a temporary dir to store all needed files # for the influxdb server instance : self.temp_dir_base = tempfile.mkdtemp() 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