def __init__( self, hosts=DEFAULT_HOSTS, port=DEFAULT_PORT, index=DEFAULT_INDEX, index_suffix=DEFAULT_INDEX_SUFFIX, username=DEFAULT_USERNAME, password=DEFAULT_PASSWORD, timeout=DEFAULT_TIMEOUT, updated_on_ttl_sec=ttls.DEFAULT_UPDATED_ON_TTL_SEC, read_on_ttl_sec=ttls.DEFAULT_READ_ON_TTL_SEC, schema_path=DEFAULT_ES_SCHEMA_PATH, ): """Create a new ElasticSearchAccessor.""" super(_ElasticSearchAccessor, self).__init__("ElasticSearch") self._hosts = list(hosts) self._port = port self._index_prefix = index self._index_suffix = index_suffix self._username = username self._password = password self._timeout = timeout self._known_indices = {} self.__glob_parser = bg_glob.GraphiteGlobParser() self.__updated_on_ttl_sec = updated_on_ttl_sec self.__read_on_ttl_sec = read_on_ttl_sec self.__schema_path = schema_path self.client = None self.schema = None log.debug( "Created Elasticsearch accessor with index prefix: '%s' and index suffix: '%s'" % (self._index_prefix, self._index_suffix))
def test_graphite_glob_parser(self): scenarii = [ # Positive examples ("a.b", [['a'], ['b']], True), ("a.{b}", [['a'], ['b']], True), ("a?b.c", [['a', bg_glob.AnyChar(), 'b'], ['c']], False), ("a.b*c", [['a'], ['b', bg_glob.AnySequence(), 'c']], False), ("a.b**c", [['a'], ['b'], bg_glob.Globstar(), ['c']], False), ("a.**.c", [['a'], bg_glob.Globstar(), ['c']], False), ("a.**", [['a'], bg_glob.Globstar()], False), ("a[xyz].b", [['a', bg_glob.CharIn(['x', 'y', 'z'])], ['b']], False), ("a[!rat].b", [['a', bg_glob.CharNotIn(['r', 'a', 't'])], ['b']], False), ("pl[a-ox]p", [['pl', bg_glob.CharIn(['a-o', 'x']), 'p']], False), ("a[b-dopx-z]b.c", [['a', bg_glob.CharIn(['b-d', 'o', 'p', 'x-z']), 'b'], ['c']], False), ("b[i\\]m", [['b', bg_glob.CharIn(['\\', 'i']), 'm']], False), ("a[x-xy]b", [['a', bg_glob.CharIn(['x-x', 'y']), 'b']], False), ("a[y-xz]b", [['a', bg_glob.CharIn(['y-x', 'z']), 'b']], False), ("a.b.{c,d}", [['a'], ['b'], [bg_glob.SequenceIn(['c', 'd'])]], False), ("a.b.{c,d}-{e,f}", [['a'], ['b'], [ bg_glob.SequenceIn(['c', 'd']), '-', bg_glob.SequenceIn(['e', 'f']) ]], False), ("a.b.oh{c{d,e,}{a,b},f{g,h}i}ah", [['a'], ['b'], [ 'oh', bg_glob.SequenceIn([ 'ca', 'cb', 'cda', 'cdb', 'cea', 'ceb', 'fgi', 'fhi' ]), 'ah' ]], False), ("a.b{some, x{chars[!xyz], plop}}c", [['a'], ['b', bg_glob.AnySequence(), 'c']], False), # Negative examples ("a[.b", [['a['], ['b']], True), ("a{.b", [['a{'], ['b']], True), ("a{.b.c}", [['a{'], ['b'], ['c}']], True), ("a.", [['a']], True), ("a..b", [['a'], ['b']], True), ] parser = bg_glob.GraphiteGlobParser() for i, (glob, expected, fully_defined) in enumerate(scenarii): parsed = parser.parse(glob) self.assertSequenceEqual(expected, parsed) self.assertEqual(fully_defined, parser.is_fully_defined(parsed), parsed)
def test_graphite_glob_parser(self): scenarii = [ # Positive examples ("a.b", [['a'], ['b']]), ("a?b.c", [['a', bg_glob.AnyChar(), 'b'], ['c']]), ("a.b*c", [['a'], ['b', bg_glob.AnySequence(), 'c']]), ("a.b**c", [['a'], ['b'], bg_glob.Globstar(), ['c']]), ("a.**.c", [['a'], bg_glob.Globstar(), ['c']]), ("a.**", [['a'], bg_glob.Globstar()]), ("a[xyz].b", [['a', bg_glob.AnyChar()], ['b']]), ("a[!rat].b", [['a', bg_glob.AnyChar()], ['b']]), ("pl[a-ox]p", [['pl', bg_glob.AnyChar(), 'p']]), ("a[b-dopx-z]b.c", [['a', bg_glob.AnyChar(), 'b'], ['c']]), ("b[i\\]m", [['b', bg_glob.AnyChar(), 'm']]), ("a[x-xy]b", [['a', bg_glob.AnyChar(), 'b']]), ("a[y-xz]b", [['a', bg_glob.AnyChar(), 'b']]), ("a.b.{c,d}", [['a'], ['b'], [bg_glob.SequenceIn(['c', 'd'])]]), ("a.b.{c,d}-{e,f}", [['a'], ['b'], [ bg_glob.SequenceIn(['c', 'd']), '-', bg_glob.SequenceIn(['e', 'f']) ]]), ("a.b.oh{c{d,e,}{a,b},f{g,h}i}ah", [['a'], ['b'], [ 'oh', bg_glob.SequenceIn([ 'ca', 'cb', 'cda', 'cdb', 'cea', 'ceb', 'fgi', 'fhi' ]), 'ah' ]]), ("a.b{some, x{chars[!xyz], plop}}c", [['a'], ['b', bg_glob.AnySequence(), 'c']]), ("a.{b}", [['a'], ['b']]), # Negative examples ("a[.b", [['a['], ['b']]), ("a{.b", [['a{'], ['b']]), ("a{.b.c}", [['a{'], ['b'], ['c}']]), ("a.", [['a']]), ("a..b", [['a'], ['b']]), ] parser = bg_glob.GraphiteGlobParser() for (glob, expected) in scenarii: parsed = parser.parse(glob) self.assertSequenceEqual(expected, parsed)
def __init__( self, hosts=DEFAULT_HOSTS, port=DEFAULT_PORT, index=DEFAULT_METRIC_INDEX, index_suffix=DEFAULT_INDEX_SUFFIX, directory_index=DEFAULT_DIRECTORY_INDEX, username=None, password=None, timeout=DEFAULT_TIMEOUT, updated_on_ttl_sec=ttls.DEFAULT_UPDATED_ON_TTL_SEC, read_on_ttl_sec=ttls.DEFAULT_READ_ON_TTL_SEC, read_on_sampling_rate=DEFAULT_READ_ON_SAMPLING_RATE, schema_path=DEFAULT_ES_SCHEMA_PATH, directory_index_enabled=False, ): """Create a new ElasticSearchAccessor.""" super(_ElasticSearchAccessor, self).__init__("ElasticSearch") self._hosts = list(hosts) self._port = port self._index_prefix = index self._directory_index_enabled = directory_index_enabled self._directory_index = directory_index self._index_suffix = index_suffix self._username = username or DEFAULT_USERNAME self._password = password or DEFAULT_PASSWORD self._timeout = timeout self._known_indices = {} self.__glob_parser = bg_glob.GraphiteGlobParser() self.__updated_on_ttl_sec = updated_on_ttl_sec self.__read_on_ttl_sec = read_on_ttl_sec self.__read_on_counter = 0 self.__read_on_sampling_rate = read_on_sampling_rate self.__schema_path = schema_path self.client = None self.schema = None log.debug( "Created Elasticsearch accessor with index prefix: '%s' and index suffix: '%s'" % (self._index_prefix, self._index_suffix)) # This will be used for low-priority background operations. self._executor = None
def test_graphite_glob_parser(self): scenarii = [ # Positive examples ("a.b", [["a"], ["b"]], True), ("a.{b}", [["a"], ["b"]], True), ("a?b.c", [["a", bg_glob.AnyChar(), "b"], ["c"]], False), ("a.b*c", [["a"], ["b", bg_glob.AnySequence(), "c"]], False), ("a.b**c", [["a"], ["b"], bg_glob.Globstar(), ["c"]], False), ("a.**.c", [["a"], bg_glob.Globstar(), ["c"]], False), ("a.**", [["a"], bg_glob.Globstar()], False), ("a[xyz].b", [["a", bg_glob.CharIn(["x", "y", "z"])], ["b"]], False), ("a[!rat].b", [["a", bg_glob.CharNotIn(["r", "a", "t"])], ["b"]], False), ("pl[a-ox]p", [["pl", bg_glob.CharIn(["a-o", "x"]), "p"]], False), ( "a[b-dopx-z]b.c", [["a", bg_glob.CharIn(["b-d", "o", "p", "x-z"]), "b"], ["c"]], False, ), ("b[i\\]m", [["b", bg_glob.CharIn(["\\", "i"]), "m"]], False), ("a[x-xy]b", [["a", bg_glob.CharIn(["x-x", "y"]), "b"]], False), ("a[y-xz]b", [["a", bg_glob.CharIn(["y-x", "z"]), "b"]], False), ("a.b.{c,d}", [["a"], ["b"], [bg_glob.SequenceIn(["c", "d"])]], False), ( "a.b.{c,d}-{e,f}", [ ["a"], ["b"], [ bg_glob.SequenceIn(["c", "d"]), "-", bg_glob.SequenceIn(["e", "f"]), ], ], False, ), ( "a.b.oh{c{d,e,}{a,b},f{g,h}i}ah", [ ["a"], ["b"], [ "oh", bg_glob.SequenceIn([ "ca", "cb", "cda", "cdb", "cea", "ceb", "fgi", "fhi" ]), "ah", ], ], False, ), ( "a.b{some, x{chars[!xyz], plop}}c", [["a"], ["b", bg_glob.AnySequence(), "c"]], False, ), # Negative examples ("a[.b", [["a["], ["b"]], True), ("a{.b", [["a{"], ["b"]], True), ("a{.b.c}", [["a{"], ["b"], ["c}"]], True), ("a.", [["a"]], True), ("a..b", [["a"], ["b"]], True), ] parser = bg_glob.GraphiteGlobParser() for i, (glob, expected, fully_defined) in enumerate(scenarii): parsed = parser.parse(glob) self.assertSequenceEqual(expected, parsed) self.assertEqual(fully_defined, parser.is_fully_defined(parsed), parsed)