From 6c2668019ade07405010b02975336908aefd9fca Mon Sep 17 00:00:00 2001 From: Dan <22e889d8@opayq.com> Date: Wed, 26 Oct 2016 14:25:58 +0100 Subject: [PATCH] Added fill previous to queries so that graphite calculations do not break due to gaps in influxdb data caused by finer group by interval than data sampling rate. Updated tests to reflect this. --- influxgraph/classes/finder.py | 2 +- influxgraph/classes/reader.py | 2 +- tests/test_influxdb_integration.py | 2 +- tests/test_influxdb_templates_integration.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/influxgraph/classes/finder.py b/influxgraph/classes/finder.py index f05f563..dca6695 100644 --- a/influxgraph/classes/finder.py +++ b/influxgraph/classes/finder.py @@ -382,7 +382,7 @@ def _gen_influxdb_query(self, start_time, end_time, paths, interval): aggregation_func, field, field) for field in fields]) query = 'select %s from %s where (time > %ds and time <= %ds) ' % ( query_fields, measurement, start_time, end_time,) - group_by = ' GROUP BY time(%ss)' % (interval,) + group_by = ' GROUP BY time(%ss) fill(previous)' % (interval,) if tags: _queries = [] _query = query diff --git a/influxgraph/classes/reader.py b/influxgraph/classes/reader.py index 0df63cc..8754e2c 100644 --- a/influxgraph/classes/reader.py +++ b/influxgraph/classes/reader.py @@ -81,7 +81,7 @@ def fetch(self, start_time, end_time): 'unit_is_ms', 'what_is_query_individual_duration']) _query = 'select %s(value) as value from "%s" where (time > %ds and ' \ - 'time <= %ds) GROUP BY time(%ss)' % ( + 'time <= %ds) GROUP BY time(%ss) fill(previous)' % ( aggregation_func, self.path, start_time, end_time, interval,) logger.debug("fetch() path=%s querying influxdb query: '%s'", self.path, _query) diff --git a/tests/test_influxdb_integration.py b/tests/test_influxdb_integration.py index ef6c7b8..bb61a3b 100644 --- a/tests/test_influxdb_integration.py +++ b/tests/test_influxdb_integration.py @@ -42,7 +42,7 @@ def setup_db(self): self.assertTrue(self.client.write_points(data)) def setUp(self): - self.step, self.num_datapoints, self.db_name = 60, 2, 'integration_test' + self.step, self.num_datapoints, self.db_name = 60, 31, 'integration_test' self.start_time, self.end_time = (datetime.datetime.utcnow() - datetime.timedelta(hours=1)), \ datetime.datetime.utcnow() self.steps = int(round((int(self.end_time.strftime("%s")) - \ diff --git a/tests/test_influxdb_templates_integration.py b/tests/test_influxdb_templates_integration.py index 20cd3dd..397874f 100644 --- a/tests/test_influxdb_templates_integration.py +++ b/tests/test_influxdb_templates_integration.py @@ -36,7 +36,7 @@ def setUp(self): self.measurements = ['cpu', 'memory', 'load', 'iops'] self.graphite_series = ["%s" % (".".join( [self.tags[p] for p in self.paths] + [m])) for m in self.measurements] - self.step, self.num_datapoints, self.db_name = 60, 2, 'integration_test' + self.step, self.num_datapoints, self.db_name = 60, 31, 'integration_test' self.start_time, self.end_time = (datetime.datetime.utcnow() - datetime.timedelta(hours=1)), \ datetime.datetime.utcnow() self.steps = int(round((int(self.end_time.strftime("%s")) - \