本文整理汇总了Python中apache_beam.metrics.execution.MetricsEnvironment.set_current_container方法的典型用法代码示例。如果您正苦于以下问题:Python MetricsEnvironment.set_current_container方法的具体用法?Python MetricsEnvironment.set_current_container怎么用?Python MetricsEnvironment.set_current_container使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apache_beam.metrics.execution.MetricsEnvironment
的用法示例。
在下文中一共展示了MetricsEnvironment.set_current_container方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_counter_distribution
# 需要导入模块: from apache_beam.metrics.execution import MetricsEnvironment [as 别名]
# 或者: from apache_beam.metrics.execution.MetricsEnvironment import set_current_container [as 别名]
def test_create_counter_distribution(self):
MetricsEnvironment.set_current_container(MetricsContainer('mystep'))
counter_ns = 'aCounterNamespace'
distro_ns = 'aDistributionNamespace'
gauge_ns = 'aGaugeNamespace'
name = 'a_name'
counter = Metrics.counter(counter_ns, name)
distro = Metrics.distribution(distro_ns, name)
gauge = Metrics.gauge(gauge_ns, name)
counter.inc(10)
counter.dec(3)
distro.update(10)
distro.update(2)
gauge.set(10)
self.assertTrue(isinstance(counter, Metrics.DelegatingCounter))
self.assertTrue(isinstance(distro, Metrics.DelegatingDistribution))
self.assertTrue(isinstance(gauge, Metrics.DelegatingGauge))
del distro
del counter
del gauge
container = MetricsEnvironment.current_container()
self.assertEqual(
container.counters[MetricName(counter_ns, name)].get_cumulative(),
7)
self.assertEqual(
container.distributions[MetricName(distro_ns, name)].get_cumulative(),
DistributionData(12, 2, 2, 10))
self.assertEqual(
container.gauges[MetricName(gauge_ns, name)].get_cumulative().value,
10)
示例2: test_uses_right_container
# 需要导入模块: from apache_beam.metrics.execution import MetricsEnvironment [as 别名]
# 或者: from apache_beam.metrics.execution.MetricsEnvironment import set_current_container [as 别名]
def test_uses_right_container(self):
c1 = MetricsContainer('step1')
c2 = MetricsContainer('step2')
counter = Metrics.counter('ns', 'name')
MetricsEnvironment.set_current_container(c1)
counter.inc()
MetricsEnvironment.set_current_container(c2)
counter.inc(3)
MetricsEnvironment.unset_current_container()
self.assertEqual(
c1.get_cumulative().counters.items(),
[(MetricKey('step1', MetricName('ns', 'name')), 1)])
self.assertEqual(
c2.get_cumulative().counters.items(),
[(MetricKey('step2', MetricName('ns', 'name')), 3)])