From 2c9bd06004794a4973e7db77f170845269bde0cf Mon Sep 17 00:00:00 2001 From: appunni-dishq <31534711+appunni-dishq@users.noreply.github.com> Date: Tue, 19 Sep 2017 14:01:35 +0530 Subject: [PATCH 1/7] Adding time_precision into Meta of SeriesHelper time_precision option not currently supported in influx-db python --- influxdb/helper.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/influxdb/helper.py b/influxdb/helper.py index c56a636a..56de505c 100644 --- a/influxdb/helper.py +++ b/influxdb/helper.py @@ -41,6 +41,10 @@ class Meta: # Only applicable if autocommit is True. autocommit = True # If True and no bulk_size, then will set bulk_size to 1. + time_precions= "s"|"ns"|"ms"|"u" + #default is ns (nanoseconds) + #Setting time precision while writing point + #you should also make sure time set is in the given precision """ @@ -61,7 +65,7 @@ def __new__(cls, *args, **kwargs): 'Missing Meta class in {0}.'.format( cls.__name__)) - for attr in ['series_name', 'fields', 'tags']: + for attr in ['series_name', 'fields', 'tags','time_precision']: try: setattr(cls, '_' + attr, getattr(_meta, attr)) except AttributeError: @@ -136,7 +140,10 @@ def commit(cls, client=None): """ if not client: client = cls._client - rtn = client.write_points(cls._json_body_()) + rtn = client.write_points( + cls._json_body_(), + time_precision=cls.time_precision) + #will be None if not set and will default to ns cls._reset_() return rtn From 824a1b779c0e9fcff02714fd325b8145d0eb193f Mon Sep 17 00:00:00 2001 From: appunni-dishq <31534711+appunni-dishq@users.noreply.github.com> Date: Tue, 19 Sep 2017 14:15:16 +0530 Subject: [PATCH 2/7] Making Time Precision optional Changed it from required to optional --- influxdb/helper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/influxdb/helper.py b/influxdb/helper.py index 56de505c..a3960a93 100644 --- a/influxdb/helper.py +++ b/influxdb/helper.py @@ -65,7 +65,7 @@ def __new__(cls, *args, **kwargs): 'Missing Meta class in {0}.'.format( cls.__name__)) - for attr in ['series_name', 'fields', 'tags','time_precision']: + for attr in ['series_name', 'fields', 'tags']: try: setattr(cls, '_' + attr, getattr(_meta, attr)) except AttributeError: @@ -75,6 +75,7 @@ def __new__(cls, *args, **kwargs): cls.__name__)) cls._autocommit = getattr(_meta, 'autocommit', False) + cls._time_precision = getattr(_meta,'time_precision',None) cls._client = getattr(_meta, 'client', None) if cls._autocommit and not cls._client: From 9d7c044ee42278afae4bcd6122179dd27dfc1488 Mon Sep 17 00:00:00 2001 From: appunni-dishq <31534711+appunni-dishq@users.noreply.github.com> Date: Tue, 19 Sep 2017 14:23:13 +0530 Subject: [PATCH 3/7] Fixing Typo in _time_precision Attribute --- influxdb/helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb/helper.py b/influxdb/helper.py index a3960a93..0a21a540 100644 --- a/influxdb/helper.py +++ b/influxdb/helper.py @@ -143,7 +143,7 @@ def commit(cls, client=None): client = cls._client rtn = client.write_points( cls._json_body_(), - time_precision=cls.time_precision) + time_precision=cls._time_precision) #will be None if not set and will default to ns cls._reset_() return rtn From 2c058171331dd20007836f0350e6b79e4a512373 Mon Sep 17 00:00:00 2001 From: appunni-dishq <31534711+appunni-dishq@users.noreply.github.com> Date: Tue, 19 Sep 2017 14:33:08 +0530 Subject: [PATCH 4/7] Fixing coding conventions for Travis CI --- influxdb/helper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/influxdb/helper.py b/influxdb/helper.py index 0a21a540..d0897755 100644 --- a/influxdb/helper.py +++ b/influxdb/helper.py @@ -41,7 +41,7 @@ class Meta: # Only applicable if autocommit is True. autocommit = True # If True and no bulk_size, then will set bulk_size to 1. - time_precions= "s"|"ns"|"ms"|"u" + time_precions= "s"|"ns"|"ms"|"u" #default is ns (nanoseconds) #Setting time precision while writing point #you should also make sure time set is in the given precision @@ -75,7 +75,7 @@ def __new__(cls, *args, **kwargs): cls.__name__)) cls._autocommit = getattr(_meta, 'autocommit', False) - cls._time_precision = getattr(_meta,'time_precision',None) + cls._time_precision = getattr(_meta, 'time_precision', None) cls._client = getattr(_meta, 'client', None) if cls._autocommit and not cls._client: @@ -144,7 +144,7 @@ def commit(cls, client=None): rtn = client.write_points( cls._json_body_(), time_precision=cls._time_precision) - #will be None if not set and will default to ns + # will be None if not set and will default to ns cls._reset_() return rtn From 3271273dd36dff59be1c78a6f260338d0f32fa35 Mon Sep 17 00:00:00 2001 From: appunni Date: Sun, 4 Mar 2018 15:00:45 +0530 Subject: [PATCH 5/7] Appunni: Test for invalid time_precision on SeriesHelper --- influxdb/helper.py | 15 +++++++++++++-- influxdb/tests/helper_test.py | 13 ++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/influxdb/helper.py b/influxdb/helper.py index 5ad064d1..645079dd 100644 --- a/influxdb/helper.py +++ b/influxdb/helper.py @@ -41,7 +41,7 @@ class Meta: # Only applicable if autocommit is True. autocommit = True # If True and no bulk_size, then will set bulk_size to 1. - time_precions= "s"|"ns"|"ms"|"u" + time_precision = "h"|"m"|s"|"ms"|"u"|"ns" #default is ns (nanoseconds) #Setting time precision while writing point #you should also make sure time set is in the given precision @@ -77,6 +77,17 @@ def __new__(cls, *args, **kwargs): cls._autocommit = getattr(_meta, 'autocommit', False) cls._time_precision = getattr(_meta, 'time_precision', None) + allowed_time_precisions = ["h", "m", "s", "ms", "u", "ns", None] + if cls._time_precision not in allowed_time_precisions: + raise AttributeError( + 'In {0}, time_precison is set, but invalid. use any of {}.' + .format(cls.__name__, ','.join(allowed_time_precisions))) + + if cls._autocommit and not cls._client: + raise AttributeError( + 'In {0}, autocommit is set to True, but no client is set.' + .format(cls.__name__)) + cls._client = getattr(_meta, 'client', None) if cls._autocommit and not cls._client: raise AttributeError( @@ -150,7 +161,7 @@ def commit(cls, client=None): client = cls._client rtn = client.write_points( cls._json_body_(), - time_precision=cls._time_precision) + time_precision = cls._time_precision) # will be None if not set and will default to ns cls._reset_() return rtn diff --git a/influxdb/tests/helper_test.py b/influxdb/tests/helper_test.py index 6f24e85d..6aa8f15a 100644 --- a/influxdb/tests/helper_test.py +++ b/influxdb/tests/helper_test.py @@ -310,8 +310,19 @@ class Meta: series_name = 'events.stats.{server_name}' + class InvalidTimePrecision(SeriesHelper): + """Define instance of SeriesHelper for invalid time precision.""" + + class Meta: + """Define metadata for InvalidTimePrecision.""" + + series_name = 'events.stats.{server_name}' + time_precision = "ks" + fields = ['time', 'server_name'] + autocommit = True + for cls in [MissingMeta, MissingClient, MissingFields, - MissingSeriesName]: + MissingSeriesName, InvalidTimePrecision]: self.assertRaises( AttributeError, cls, **{'time': 159, 'server_name': 'us.east-1'}) From 4e576a532378c5c3b8eb1c32d5c46ed90344160e Mon Sep 17 00:00:00 2001 From: appunni Date: Tue, 1 May 2018 13:48:14 +0530 Subject: [PATCH 6/7] Appunni: Intendation problem resolution in master --- influxdb/helper.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/influxdb/helper.py b/influxdb/helper.py index 645079dd..d005617f 100644 --- a/influxdb/helper.py +++ b/influxdb/helper.py @@ -86,13 +86,13 @@ def __new__(cls, *args, **kwargs): if cls._autocommit and not cls._client: raise AttributeError( 'In {0}, autocommit is set to True, but no client is set.' - .format(cls.__name__)) + .format(cls.__name__)) cls._client = getattr(_meta, 'client', None) if cls._autocommit and not cls._client: raise AttributeError( 'In {0}, autocommit is set to True, but no client is set.' - .format(cls.__name__)) + .format(cls.__name__)) try: cls._bulk_size = getattr(_meta, 'bulk_size') @@ -132,11 +132,11 @@ def __init__(self, **kw): keys = set(kw.keys()) # all tags should be passed, and keys - tags should be a subset of keys - if not(tags <= keys): + if not (tags <= keys): raise NameError( 'Expected arguments to contain all tags {0}, instead got {1}.' - .format(cls._tags, kw.keys())) - if not(keys - tags <= fields): + .format(cls._tags, kw.keys())) + if not (keys - tags <= fields): raise NameError('Got arguments not in tags or fields: {0}' .format(keys - tags - fields)) @@ -161,7 +161,7 @@ def commit(cls, client=None): client = cls._client rtn = client.write_points( cls._json_body_(), - time_precision = cls._time_precision) + time_precision=cls._time_precision) # will be None if not set and will default to ns cls._reset_() return rtn From e16ace236e9290672edb16c88ae2d01872407a9d Mon Sep 17 00:00:00 2001 From: klDen Date: Sun, 26 May 2019 21:46:12 -0400 Subject: [PATCH 7/7] - Fix flake7 errors : E131 continuation line unaligned for hanging indent - Fix typo - Fix cls._client declaration ordering - Remove duplicate code cls._autocommit ... --- influxdb/helper.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/influxdb/helper.py b/influxdb/helper.py index d005617f..fa79c079 100644 --- a/influxdb/helper.py +++ b/influxdb/helper.py @@ -42,9 +42,9 @@ class Meta: autocommit = True # If True and no bulk_size, then will set bulk_size to 1. time_precision = "h"|"m"|s"|"ms"|"u"|"ns" - #default is ns (nanoseconds) - #Setting time precision while writing point - #you should also make sure time set is in the given precision + # Default is ns (nanoseconds) + # Setting time precision while writing point + # You should also make sure time is set in the given precision """ @@ -77,22 +77,17 @@ def __new__(cls, *args, **kwargs): cls._autocommit = getattr(_meta, 'autocommit', False) cls._time_precision = getattr(_meta, 'time_precision', None) - allowed_time_precisions = ["h", "m", "s", "ms", "u", "ns", None] + allowed_time_precisions = ['h', 'm', 's', 'ms', 'u', 'ns', None] if cls._time_precision not in allowed_time_precisions: raise AttributeError( - 'In {0}, time_precison is set, but invalid. use any of {}.' - .format(cls.__name__, ','.join(allowed_time_precisions))) - - if cls._autocommit and not cls._client: - raise AttributeError( - 'In {0}, autocommit is set to True, but no client is set.' - .format(cls.__name__)) + 'In {0}, time_precision is set, but invalid use any of {}.' + .format(cls.__name__, ','.join(allowed_time_precisions))) cls._client = getattr(_meta, 'client', None) if cls._autocommit and not cls._client: raise AttributeError( 'In {0}, autocommit is set to True, but no client is set.' - .format(cls.__name__)) + .format(cls.__name__)) try: cls._bulk_size = getattr(_meta, 'bulk_size') @@ -135,7 +130,7 @@ def __init__(self, **kw): if not (tags <= keys): raise NameError( 'Expected arguments to contain all tags {0}, instead got {1}.' - .format(cls._tags, kw.keys())) + .format(cls._tags, kw.keys())) if not (keys - tags <= fields): raise NameError('Got arguments not in tags or fields: {0}' .format(keys - tags - fields))