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(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_get_index(self): disabled_finder = DisabledFinder() # use get_finders so legacy_finder is patched with get_index legacy_finder = get_finders('tests.test_storage.LegacyFinder')[0] test_finder = TestFinder() remote_finder = RemoteFinder() store = Store( finders=[disabled_finder, legacy_finder, test_finder, remote_finder], tagdb=get_tagdb('graphite.tags.localdatabase.LocalDatabaseTagDB') ) # get index result = store.get_index() self.assertEqual(result, ['a.b.c.d', 'a.b.c.e']) # get local index result = store.get_index({'localOnly': True}) self.assertEqual(result, ['a.b.c.d'])
def test_get_index(self): disabled_finder = DisabledFinder() # use get_finders so legacy_finder is patched with get_index legacy_finder = get_finders('tests.test_storage.LegacyFinder')[0] test_finder = TestFinder() remote_finder = RemoteFinder() store = Store( finders=[ disabled_finder, legacy_finder, test_finder, remote_finder ], tagdb=get_tagdb('graphite.tags.localdatabase.LocalDatabaseTagDB')) # get index result = store.get_index() self.assertEqual(result, ['a.b.c.d', 'a.b.c.e']) # get local index result = store.get_index({'localOnly': True}) self.assertEqual(result, ['a.b.c.d'])
def test_fetch(self): disabled_finder = get_finders('tests.test_storage.DisabledFinder')[0] legacy_finder = get_finders('tests.test_storage.LegacyFinder')[0] test_finder = get_finders('tests.test_storage.TestFinder')[0] remote_finder = get_finders('tests.test_storage.RemoteFinder')[0] store = Store( finders=[ disabled_finder, legacy_finder, test_finder, remote_finder ], tagdb=get_tagdb('graphite.tags.localdatabase.LocalDatabaseTagDB')) # tagb is properly initialized self.assertIsInstance(store.tagdb, LocalDatabaseTagDB) # get all enabled finders finders = store.get_finders() self.assertEqual(list(finders), [legacy_finder, test_finder, remote_finder]) # get only local finders finders = store.get_finders(local=True) self.assertEqual(list(finders), [legacy_finder, test_finder]) # fetch with empty patterns result = store.fetch([], 1, 2, 3, {}) self.assertEqual(result, []) # fetch result = store.fetch(['a.**'], 1, 2, 3, {}) self.assertEqual(len(result), 3) result.sort(key=lambda node: node['name']) self.assertEqual(result[0]['name'], 'a.b.c.d') self.assertEqual(result[0]['pathExpression'], 'a.**') self.assertEqual(result[1]['name'], 'a.b.c.d') self.assertEqual(result[1]['pathExpression'], 'a.**') self.assertEqual(result[2]['name'], 'a.b.c.e') self.assertEqual(result[2]['pathExpression'], 'a.**')
def test_fetch(self): disabled_finder = get_finders('tests.test_storage.DisabledFinder')[0] legacy_finder = get_finders('tests.test_storage.LegacyFinder')[0] test_finder = get_finders('tests.test_storage.TestFinder')[0] remote_finder = get_finders('tests.test_storage.RemoteFinder')[0] store = Store( finders=[disabled_finder, legacy_finder, test_finder, remote_finder], tagdb=get_tagdb('graphite.tags.localdatabase.LocalDatabaseTagDB') ) # tagb is properly initialized self.assertIsInstance(store.tagdb, LocalDatabaseTagDB) # get all enabled finders finders = store.get_finders() self.assertEqual(list(finders), [legacy_finder, test_finder, remote_finder]) # get only local finders finders = store.get_finders(local=True) self.assertEqual(list(finders), [legacy_finder, test_finder]) # fetch with empty patterns result = store.fetch([], 1, 2, 3, {}) self.assertEqual(result, []) # fetch result = store.fetch(['a.**'], 1, 2, 3, {}) self.assertEqual(len(result), 3) result.sort(key=lambda node: node['name']) self.assertEqual(result[0]['name'], 'a.b.c.d') self.assertEqual(result[0]['pathExpression'], 'a.**') self.assertEqual(result[1]['name'], 'a.b.c.d') self.assertEqual(result[1]['pathExpression'], 'a.**') self.assertEqual(result[2]['name'], 'a.b.c.e') self.assertEqual(result[2]['pathExpression'], 'a.**')