Skip to content

Commit

Permalink
Added measurement in template config sanity check - resolves #25
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan committed Feb 23, 2017
1 parent 5e8b6d0 commit 1c8e965
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion influxgraph/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from collections import deque
from heapq import heappush, heappop


logger = logging.getLogger('influxgraph')


Expand Down Expand Up @@ -135,7 +136,11 @@ def _template_sanity_check(template):
field = tag
if measurement_wildcard and field_wildcard:
raise InvalidTemplateError(
"Either 'field*' or 'measurement*' can be used in each template, not both - %s",
"Either 'field*' or 'measurement*' can be used in each template, "
"not both - %s", template)
if not measurement_wildcard and 'measurement' not in template.values():
raise InvalidTemplateError(
"At least one of 'measurement' or 'measurement*' is required - %s",
template)

def apply_template(metric_path_parts, template, default_tags, separator='.'):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_influxdb_templates_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,10 @@ def test_bad_templates(self):
self.assertRaises(InvalidTemplateError, influxgraph.InfluxDBFinder, self.config)
self.config['influxdb']['templates'] = ['host.field.field']
self.assertRaises(InvalidTemplateError, influxgraph.InfluxDBFinder, self.config)
self.config['influxdb']['templates'] = ['host.field']
self.assertRaises(InvalidTemplateError, influxgraph.InfluxDBFinder, self.config)
self.config['influxdb']['templates'] = ['host.measurements.field']
self.assertRaises(InvalidTemplateError, influxgraph.InfluxDBFinder, self.config)

def test_template_nofilter_extra_tags(self):
self.config['influxdb']['templates'] = ['host.measurement* env=int,region=the_west']
Expand Down

0 comments on commit 1c8e965

Please sign in to comment.