From 28dee66da92bd94cfcff67d379da34c84b33ccb3 Mon Sep 17 00:00:00 2001 From: aviau Date: Fri, 17 Jul 2015 14:43:08 -0400 Subject: [PATCH] Dont include empty tags in lines (Closes: #215) --- influxdb/line_protocol.py | 8 ++++---- tests/influxdb/test_line_protocol.py | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 tests/influxdb/test_line_protocol.py diff --git a/influxdb/line_protocol.py b/influxdb/line_protocol.py index 266cf59e..403e463c 100644 --- a/influxdb/line_protocol.py +++ b/influxdb/line_protocol.py @@ -79,10 +79,10 @@ def make_lines(data): tags.update(point.get('tags', {})) # tags should be sorted client-side to take load off server for tag_key in sorted(tags.keys()): - lines += "{key}={value},".format( - key=_escape_tag(tag_key), - value=_escape_tag(tags[tag_key]), - ) + key = _escape_tag(tag_key) + value = _escape_tag(tags[tag_key]) + if key != '' and value != '': + lines += "{key}={value},".format(key=key, value=value) lines = lines[:-1] + " " # strip the trailing comma # add fields diff --git a/tests/influxdb/test_line_protocol.py b/tests/influxdb/test_line_protocol.py new file mode 100644 index 00000000..44c397eb --- /dev/null +++ b/tests/influxdb/test_line_protocol.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +import unittest +from influxdb import line_protocol + + +class TestLineProtocol(unittest.TestCase): + + def test_empty_tag(self): + data = { + "tags": { + "my_tag": "" + }, + "points": [ + { + "measurement": "test", + "fields": { + "value": "hello!" + } + } + ] + } + + self.assertEqual( + line_protocol.make_lines(data), + 'test value="hello!"\n' + )