Beispiel #1
0
  def test_find_all_failed(self):
    # all finds failed
    store = Store(
      finders=[TestFinder()]
    )

    message = 'All requests failed for find <FindQuery: a from \* until \*>'
    with patch('graphite.storage.log.info') as log_info:
      with self.assertRaisesRegexp(Exception, message):
        list(store.find('a'))
      self.assertEqual(log_info.call_count, 1)
      self.assertRegexpMatches(
        log_info.call_args[0][0],
        'Exception during find <FindQuery: a from \* until \*> after [-.e0-9]+s: TestFinder.find_nodes'
      )

    store = Store(
      finders=[TestFinder(), TestFinder()]
    )

    with patch('graphite.storage.log.info') as log_info:
      with self.assertRaisesRegexp(Exception, message):
        list(store.find('a'))
      self.assertEqual(log_info.call_count, 2)
      self.assertRegexpMatches(
        log_info.call_args[0][0],
        'Exception during find <FindQuery: a from \* until \*> after [-.e0-9]+s: TestFinder.find_nodes'
      )
Beispiel #2
0
    def test_find_all_failed(self):
        # all finds failed
        store = Store(finders=[TestFinder()])

        with patch('graphite.storage.log.info') as log_info:
            with self.assertRaisesRegexp(
                    Exception,
                    'Find for <FindQuery: a from \* until \*> failed: TestFinder.find_nodes'
            ):
                list(store.find('a'))
            self.assertEqual(log_info.call_count, 1)
            self.assertRegexpMatches(
                log_info.call_args[0][0],
                'Find for <FindQuery: a from \* until \*> failed after [-.e0-9]+s: TestFinder.find_nodes'
            )

        store = Store(finders=[TestFinder(), TestFinder()])

        with patch('graphite.storage.log.info') as log_info:
            with self.assertRaisesRegexp(
                    Exception,
                    'All finds failed for <FindQuery: a from \* until \*>'):
                list(store.find('a'))
            self.assertEqual(log_info.call_count, 2)
            self.assertRegexpMatches(
                log_info.call_args[0][0],
                'Find for <FindQuery: a from \* until \*> failed after [-.e0-9]+s: TestFinder.find_nodes'
            )
Beispiel #3
0
    def test_custom_finder(self):
        store = Store(finders=[get_finder('tests.test_finders.DummyFinder')])
        nodes = list(store.find("foo"))
        self.assertEqual(len(nodes), 1)
        self.assertEqual(nodes[0].path, 'foo')

        nodes = list(store.find('bar.*'))
        self.assertEqual(len(nodes), 10)
        node = nodes[0]
        self.assertEqual(node.path.split('.')[0], 'bar')

        time_info, series = node.fetch(100, 200)
        self.assertEqual(time_info, (100, 200, 10))
        self.assertEqual(len(series), 10)
    def test_custom_finder(self):
        store = Store(finders=[get_finder("tests.test_finders.DummyFinder")])
        nodes = list(store.find("foo"))
        self.assertEqual(len(nodes), 1)
        self.assertEqual(nodes[0].path, "foo")

        nodes = list(store.find("bar.*"))
        self.assertEqual(len(nodes), 10)
        node = nodes[0]
        self.assertEqual(node.path.split(".")[0], "bar")

        time_info, series = node.fetch(100, 200)
        self.assertEqual(time_info, (100, 200, 10))
        self.assertEqual(len(series), 10)
Beispiel #5
0
    def test_find(self):
        disabled_finder = DisabledFinder()
        legacy_finder = LegacyFinder()
        test_finder = TestFinder()
        remote_finder = RemoteFinder()

        store = Store(
            finders=[
                disabled_finder, legacy_finder, test_finder, remote_finder
            ],
            tagdb=get_tagdb('graphite.tags.localdatabase.LocalDatabaseTagDB'))

        # find nodes
        result = list(store.find('a'))
        self.assertEqual(len(result), 5)

        for node in result:
            if node.path in ['a.b.c.d', 'a.b.c.e']:
                self.assertIsInstance(node, LeafNode)
            else:
                self.assertIsInstance(node, BranchNode)
                self.assertTrue(node.path in ['a', 'a.b', 'a.b.c'])

        # find leaves only
        result = list(store.find('a', leaves_only=True))
        self.assertEqual(len(result), 2)

        for node in result:
            self.assertIsInstance(node, LeafNode)
            self.assertTrue(node.path in ['a.b.c.d', 'a.b.c.e'])

        # failure threshold
        with self.settings(METRICS_FIND_FAILURE_THRESHOLD=1):
            with self.assertRaisesRegexp(
                    Exception,
                    'Query a yields too many results and failed \(failure threshold is 1\)'
            ):
                list(store.find('a'))

        # warning threshold
        with self.settings(METRICS_FIND_WARNING_THRESHOLD=1):
            with patch('graphite.storage.log.warning') as log_warning:
                list(store.find('a'))
                self.assertEqual(log_warning.call_count, 1)
                self.assertEqual(
                    log_warning.call_args[0][0],
                    'Query a yields large number of results up to 2 (warning threshold is 1)'
                )
Beispiel #6
0
  def test_find(self):
    disabled_finder = DisabledFinder()
    legacy_finder = LegacyFinder()
    test_finder = TestFinder()
    remote_finder = RemoteFinder()

    store = Store(
      finders=[disabled_finder, legacy_finder, test_finder, remote_finder],
      tagdb=get_tagdb('graphite.tags.localdatabase.LocalDatabaseTagDB')
    )

    # find nodes
    result = list(store.find('a'))
    self.assertEqual(len(result), 5)

    for node in result:
      if node.path in ['a.b.c.d', 'a.b.c.e']:
        self.assertIsInstance(node, LeafNode)
      else:
        self.assertIsInstance(node, BranchNode)
        self.assertTrue(node.path in ['a', 'a.b', 'a.b.c'])

    # find leaves only
    result = list(store.find('a', leaves_only=True))
    self.assertEqual(len(result), 2)

    for node in result:
      self.assertIsInstance(node, LeafNode)
      self.assertTrue(node.path in ['a.b.c.d', 'a.b.c.e'])

    # failure threshold
    with self.settings(METRICS_FIND_FAILURE_THRESHOLD=1):
      with self.assertRaisesRegexp(Exception, 'Query a yields too many results and failed \(failure threshold is 1\)'):
        list(store.find('a'))

    # warning threshold
    with self.settings(METRICS_FIND_WARNING_THRESHOLD=1):
      with patch('graphite.storage.log.warning') as log_warning:
        list(store.find('a'))
        self.assertEqual(log_warning.call_count, 1)
        self.assertEqual(
          log_warning.call_args[0][0],
          'Query a yields large number of results up to 2 (warning threshold is 1)'
        )
    def test_find_pool_timeout(self):
        # pool timeout
        store = Store(finders=[RemoteFinder()])

        def mock_pool_exec(pool, jobs, timeout):
            raise PoolTimeoutError()

        message = r'Timed out after [-.e0-9]+s for find <FindQuery: a from \* until \*>'
        with patch('graphite.storage.pool_exec', mock_pool_exec):
            with patch('graphite.storage.log.info') as log_info:
                with self.assertRaisesRegexp(Exception, message):
                    list(store.find('a'))
                self.assertEqual(log_info.call_count, 1)
                self.assertRegexpMatches(log_info.call_args[0][0], message)
Beispiel #8
0
  def test_find_pool_timeout(self):
    # pool timeout
    store = Store(
      finders=[RemoteFinder()]
    )

    def mock_pool_exec(pool, jobs, timeout):
      raise PoolTimeoutError()

    with patch('graphite.storage.pool_exec', mock_pool_exec):
      with patch('graphite.storage.log.debug') as log_debug:
        with self.assertRaisesRegexp(Exception, 'All finds failed for <FindQuery: a from \* until \*>'):
          list(store.find('a'))
          self.assertEqual(log_debug.call_count, 1)
          self.assertRegexpMatches(log_debug.call_args[0][0], 'Timed out in find after [-.e0-9]+s')
Beispiel #9
0
    def test_multiple_globstars(self):
        self.addCleanup(self.wipe_whisper)
        store  = Store(finders=get_finders('graphite.finders.standard.StandardFinder'))

        query = "x.**.x.**.x"
        hits = ["x.x.x", "x._.x.x", "x.x._.x", "x._.x._.x", "x._._.x.x", "x.x._._.x"]
        misses = ["x.o.x", "o.x.x", "x.x.o", "o.x.x.x", "x.x.x.o", "o._.x._.x", "x._.o._.x", "x._.x._.o"]
        for path in hits + misses:
            file = join(path.replace(".", os.sep)) + ".wsp"
            self.create_whisper(file)

        paths = [node.path for node in store.find(query, local=True)]
        for hit in hits:
            self.assertIn(hit, paths)
        for miss in misses:
            self.assertNotIn(miss, paths)
Beispiel #10
0
    def test_multiple_globstars(self):
        self.addCleanup(self.wipe_whisper)
        store  = Store(finders=get_finders('graphite.finders.standard.StandardFinder'))

        query = "x.**.x.**.x"
        hits = ["x.x.x", "x._.x.x", "x.x._.x", "x._.x._.x", "x._._.x.x", "x.x._._.x"]
        misses = ["x.o.x", "o.x.x", "x.x.o", "o.x.x.x", "x.x.x.o", "o._.x._.x", "x._.o._.x", "x._.x._.o"]
        for path in hits + misses:
            file = join(path.replace(".", os.sep)) + ".wsp"
            self.create_whisper(file)

        paths = [node.path for node in store.find(query, local=True)]
        for hit in hits:
            self.assertIn(hit, paths)
        for miss in misses:
            self.assertNotIn(miss, paths)
Beispiel #11
0
  def test_find_pool_timeout(self):
    # pool timeout
    store = Store(
      finders=[RemoteFinder()]
    )

    def mock_pool_exec(pool, jobs, timeout):
      raise PoolTimeoutError()

    message = 'Timed out after [-.e0-9]+s for find <FindQuery: a from \* until \*>'
    with patch('graphite.storage.pool_exec', mock_pool_exec):
      with patch('graphite.storage.log.info') as log_info:
        with self.assertRaisesRegexp(Exception, message):
          list(store.find('a'))
        self.assertEqual(log_info.call_count, 1)
        self.assertRegexpMatches(log_info.call_args[0][0], message)
Beispiel #12
0
    def test_terminal_globstar(self):
        self.addCleanup(self.wipe_whisper)
        finder = get_finder("graphite.finders.standard.StandardFinder")
        store = Store(finders=[finder])

        query = "x.**"
        hits = ["x._", "x._._", "x._._._"]
        misses = ["x", "o._", "o.x._", "o._.x"]
        for path in hits + misses:
            file = join(path.replace(".", os.sep)) + ".wsp"
            self.create_whisper(file)

        paths = [node.path for node in store.find(query, local=True)]
        for hit in hits:
            self.assertIn(hit, paths)
        for miss in misses:
            self.assertNotIn(miss, paths)
            self.wipe_whisper()