本文整理汇总了Python中tests.test_utils.make_metric函数的典型用法代码示例。如果您正苦于以下问题:Python make_metric函数的具体用法?Python make_metric怎么用?Python make_metric使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_metric函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_repair_shard
def test_repair_shard(self):
# Add a normal metric.
metric_name = "a.b.test"
metric = bg_test_utils.make_metric(metric_name)
self.metadata_cache.create_metric(metric)
self.metadata_cache.repair(shard=0, nshards=2)
self.metadata_cache.repair(shard=1, nshards=2)
self.metadata_cache.get_metric(metric_name)
# Should be only one entry, and it was a hit.
self.assertEqual(self.metadata_cache.hit_count, 1)
self.assertEqual(self.metadata_cache.miss_count, 0)
# Add a spurious metric.
metric_name = "a.b.fake"
metric = bg_test_utils.make_metric(metric_name)
self.metadata_cache._cache_set(metric_name, metric)
# Will not fix.
self.metadata_cache.repair(start_key="b")
self.metadata_cache.get_metric(metric_name)
self.assertEqual(self.metadata_cache.hit_count, 2)
# Will fix.
self.metadata_cache.repair(start_key="a", shard=0, nshards=2)
self.metadata_cache.repair(start_key="a", shard=1, nshards=2)
self.metadata_cache.get_metric(metric_name)
# repair() will remove it, and the get will produce a miss.
self.assertEqual(self.metadata_cache.hit_count, 2)
self.assertEqual(self.metadata_cache.miss_count, 1)
示例2: test_get_metric_doubledots
def test_get_metric_doubledots(self):
metric = bg_test_utils.make_metric("a.b..c")
metric_1 = bg_test_utils.make_metric("a.b.c")
self.accessor.create_metric(metric)
self.accessor.create_metric(metric_1)
self.flush()
self.assertEqual(["a.b.c"], list(self.accessor.glob_metric_names("a.b.*")))
self.assertEqual(True, self.accessor.has_metric("a.b..c"))
self.assertNotEqual(None, self.accessor.get_metric("a.b..c"))
示例3: test_cache_clean
def test_cache_clean(self):
"""Check that the cache is cleared out of metrics older than the TTL."""
with freeze_time("2014-01-01 00:00:00"):
old_metric = bg_test_utils.make_metric("i.am.old")
self.metadata_cache.create_metric(old_metric)
with freeze_time("2015-01-01 00:00:00"):
new_metric = bg_test_utils.make_metric("i.am.new")
self.metadata_cache.create_metric(new_metric)
with freeze_time("2015-01-01 20:00:00"):
self.metadata_cache.clean()
self.assertEqual(self.metadata_cache._cache_has(new_metric.name), True)
self.assertEqual(self.metadata_cache._cache_has(old_metric.name), False)
示例4: test_update_metric_should_update_metric_metadata
def test_update_metric_should_update_metric_metadata(self):
metric_name = "test_update_metric_should_update_metric_metadata.a.b.c"
initial_metadata = MetricMetadata(
aggregator=Aggregator.total,
retention=Retention.from_string("42*1s"),
carbon_xfilesfactor=0.5,
)
create_date = datetime.datetime(2014, 1, 1)
update_date = datetime.datetime(2018, 1, 1)
new_metadata = MetricMetadata(
aggregator=Aggregator.average,
retention=Retention.from_string("43*100s"),
carbon_xfilesfactor=0.25,
)
with freezegun.freeze_time(create_date):
metric = bg_test_utils.make_metric(metric_name, initial_metadata)
self.accessor.create_metric(metric)
self.accessor.flush()
with freezegun.freeze_time(update_date):
self.accessor.update_metric(metric_name, new_metadata)
self.accessor.flush()
metric = self.accessor.get_metric(metric_name)
self.assertEqual(update_date, metric.updated_on)
self.assertEqual(new_metadata, metric.metadata)
示例5: test_delete_directory_should_delete_all_metrics_in_the_given_directory
def test_delete_directory_should_delete_all_metrics_in_the_given_directory(self):
prefix = (
"test_delete_directory_should_delete_all_metrics_in_the_given_directory"
)
to_delete_prefix = "%s.should_not_be_found" % prefix
not_to_delete_prefix = "%s.should_be_found" % prefix
short_names = ["a", "b", "c"]
unexpected_metrics = [
"%s.%s" % (to_delete_prefix, short_name) for short_name in short_names
]
expected_metrics = [
"%s.%s" % (not_to_delete_prefix, short_name) for short_name in short_names
]
for metric_name in expected_metrics + unexpected_metrics:
self.accessor.create_metric(bg_test_utils.make_metric(metric_name))
self.accessor.flush()
self.accessor.delete_directory(to_delete_prefix)
self.accessor.flush()
for expected_metric in expected_metrics:
self.assertIsNotNone(self.accessor.get_metric(expected_metric))
for unexpected_metric in unexpected_metrics:
self.assertIsNone(self.accessor.get_metric(unexpected_metric))
示例6: test_carbon_protocol_read
def test_carbon_protocol_read(self):
metric_name = "fake.name"
# Custom aggregator to make sure all goes right.
metric = bg_test_utils.make_metric(_METRIC_NAME, aggregator=bg_metric.Aggregator.minimum)
self.accessor.create_metric(metric)
self.accessor.flush()
self.reader = bg_graphite.Reader(
self.accessor, self.metadata_cache, self.carbonlink, metric_name
)
with mock.patch(
"graphite.carbonlink.CarbonLinkPool.query"
) as carbonlink_query_mock:
carbonlink_query_mock.return_value = [
(864005.0, 100.0),
(864065.0, 101.0),
(864125.0, 102.0),
]
(start, end, step), points = self.fetch(
start_time=self._POINTS_START + 3,
end_time=self._POINTS_END - 3,
now=self._POINTS_END + 10,
)
# Check that we really have a 1sec resolution
self.assertEqual(start, self._POINTS_START + 3)
self.assertEqual(end, self._POINTS_END - 3)
self.assertEqual(step, 1)
# Check that this returns at least one value different from None.
self.assertEqual(len(points), end - start)
# Check that at least one point is at the correct place.
self.assertEqual(points[864005 - start], 100.0)
示例7: test_glob_directories
def test_glob_directories(self):
IS_ELASTICSEARCH = self.ACCESSOR_SETTINGS.get("driver", "") == "elasticsearch"
for name in "a", "a.b", "x.y.z":
metric = bg_test_utils.make_metric(name)
self.accessor.create_metric(metric)
self.flush()
def assert_find(glob, expected_matches):
# Check we can find the matches of a glob
self.assertEqual(
expected_matches, list(self.accessor.glob_directory_names(glob))
)
assert_find("x.y", ["x.y"]) # Test exact match
assert_find("A", []) # Test case mismatch
# Test various depths
assert_find("*", ["a", "x"])
if IS_ELASTICSEARCH:
assert_find("*.*", ["*.y"])
else:
assert_find("*.*", ["x.y"])
assert_find("*.*.*", [])
self.accessor.drop_all_metrics()
assert_find("*", [])
示例8: test_fetch_empty
def test_fetch_empty(self):
no_such_metric = bg_test_utils.make_metric("no.such.metric")
self.accessor.insert_points(_METRIC, _POINTS)
self.flush()
self.accessor.drop_all_metrics()
self.assertEqual(len(self.fetch(no_such_metric, _POINTS_START, _POINTS_END)), 0)
self.assertFalse(len(self.fetch(_METRIC, _POINTS_START, _POINTS_END)), 0)
示例9: test_graphite_glob
def test_graphite_glob(self):
for name in self._metric_names:
metric = bg_test_utils.make_metric(name)
self.accessor.create_metric(metric)
scenarii = [
# Single character wildcard
("a?", ["aa"], []),
# Component wildcard
("*", self._metrics_by_length[1], ["a", "x"]),
("*.*.c", ["a.b.c", "x.y.c"], []),
("a.*.*", ["a.a.a", "a.b.c", "a.b.d"], []),
("*.*.*", self._metrics_by_length[3], []),
# Multi-character wildcard
("a*", ["a", "aa", "aaa"], ["a"]),
# Choices
("*.{b,c,d,5}.?", ["a.b.c", "a.b.d"], []),
# Globstar wildcard
("a.**", ["a.a.a", "a.b.c", "a.b.d"], ["a.a", "a.b"]),
]
for (glob, metrics, directories) in scenarii:
(found_metrics, found_directories) = bg_glob.graphite_glob(self.accessor, glob)
found_metric_names = [found_metric.name for found_metric in found_metrics]
found_directory_names = [found_directory.name for found_directory in found_directories]
self.assertEqual((metrics, directories), (found_metric_names, found_directory_names))
示例10: test_delete_metric_should_remove_metric_from_index
def test_delete_metric_should_remove_metric_from_index(self):
prefix = "test_delete_metric_should_remove_metric_from_index"
to_delete_metric_name = "%s.to_delete" % prefix
not_to_delete_metric_name = "%s.not_to_delete" % prefix
self.accessor.create_metric(bg_test_utils.make_metric(to_delete_metric_name))
self.accessor.create_metric(
bg_test_utils.make_metric(not_to_delete_metric_name)
)
self.accessor.flush()
self.accessor.delete_metric(to_delete_metric_name)
self.accessor.flush()
self.assertIsNone(self.accessor.get_metric(to_delete_metric_name))
self.assertIsNotNone(self.accessor.get_metric(not_to_delete_metric_name))
示例11: test_create_async
def test_create_async(self):
metric_name = "a.b.c"
metric = bg_test_utils.make_metric(metric_name)
self._plugin._createAsyncOrig(metric, metric_name)
self.assertFalse(self._plugin.exists(metric_name))
self._plugin._createOneMetric()
self.assertTrue(self._plugin.exists(metric_name))
# See if we can update.
metric = bg_test_utils.make_metric(metric_name)
metric.metadata.retention = bg_metric.Retention([bg_metric.Stage(1, 1)])
self._plugin._createAsyncOrig(metric, metric_name)
self._plugin._createOneMetric()
retention = self._plugin.getMetadata(metric_name, "retention")
self.assertEqual(retention, metric.metadata.retention)
示例12: test_has_metric
def test_has_metric(self):
metric = bg_test_utils.make_metric("a.b.c.d.e.f")
self.assertEqual(self.accessor.has_metric(metric.name), False)
self.accessor.create_metric(metric)
self.flush()
self.assertEqual(self.accessor.has_metric(metric.name), True)
示例13: test_map
def test_map(self):
metric1 = bg_test_utils.make_metric("a.b.c.d.e.f")
self.accessor.create_metric(metric1)
metric2 = bg_test_utils.make_metric("g.h.i.j.k.l")
self.accessor.create_metric(metric2)
self.flush()
def _callback(metric, done, total):
self.assertIsNotNone(metric)
self.assertTrue(done <= total)
def _errback(name):
self.assertIsNotNone(name)
self.accessor.map(_callback, errback=_errback)
示例14: setUp
def setUp(self):
super(TestFinder, self).setUp()
for metric_name in "a", "a.a", "a.b.c", "x.y":
metric = bg_test_utils.make_metric(metric_name)
self.accessor.create_metric(metric)
self.finder = bg_graphite.Finder(
accessor=self.accessor, metadata_cache=self.metadata_cache
)
示例15: test_run
def test_run(self, mock_stdout):
self.accessor.drop_all_metrics()
for metric in self.metrics:
self.accessor.create_metric(bg_test_utils.make_metric(metric))
bgutil.main(["--driver=memory", "read", "**"], self.accessor)
output = mock_stdout.getvalue()
for metric in self.metrics:
self.assertIn(metric, output)