Skip to content

Commit

Permalink
Merge pull request #2307 from tharvik/master
Browse files Browse the repository at this point in the history
Better support for variant in ceres
  • Loading branch information
deniszh committed Jul 1, 2018
2 parents a3667ef + 555453f commit 250742f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
15 changes: 3 additions & 12 deletions webapp/graphite/finders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,15 @@ def fs_to_metric(path):
return os.path.join(dirpath, filename.split('.')[0]).replace(os.sep, '.')


def _deduplicate(entries):
yielded = set()
for entry in entries:
if entry not in yielded:
yielded.add(entry)
yield entry


def extract_variants(pattern):
"""Extract the pattern variants (ie. {foo,bar}baz = foobaz or barbaz)."""
v1, v2 = pattern.find('{'), pattern.find('}')
if v1 > -1 and v2 > v1:
variations = pattern[v1 + 1:v2].split(',')
variants = [pattern[:v1] + v + pattern[v2 + 1:] for v in variations]

return list({r for v in variants for r in extract_variants(v)})
else:
variants = [pattern]
return list(_deduplicate(variants))
return [pattern]


def match_entries(entries, pattern):
Expand All @@ -53,7 +44,7 @@ def match_entries(entries, pattern):
for variant in expand_braces(pattern):
matching.extend(fnmatch.filter(entries, variant))

return list(_deduplicate(matching))
return list(set(matching))


"""
Expand Down
3 changes: 3 additions & 0 deletions webapp/tests/test_finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@ def wipe_ceres():
nodes = finder.find_nodes(FindQuery('*.ba?.{baz,foo}', None, None))
self.assertEqual(len(list(nodes)), 2)

nodes = finder.find_nodes(FindQuery('{bar,foo}.{bar,baz}.{baz,foo}', None, None))
self.assertEqual(len(list(nodes)), 2)

nodes = finder.find_nodes(FindQuery('foo;bar=baz', None, None))
self.assertEqual(len(list(nodes)), 1)

Expand Down

0 comments on commit 250742f

Please sign in to comment.