当前位置: 首页>>代码示例>>Python>>正文


Python MetricsEnvironment.current_container方法代码示例

本文整理汇总了Python中apache_beam.metrics.execution.MetricsEnvironment.current_container方法的典型用法代码示例。如果您正苦于以下问题:Python MetricsEnvironment.current_container方法的具体用法?Python MetricsEnvironment.current_container怎么用?Python MetricsEnvironment.current_container使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在apache_beam.metrics.execution.MetricsEnvironment的用法示例。


在下文中一共展示了MetricsEnvironment.current_container方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_counter_distribution

# 需要导入模块: from apache_beam.metrics.execution import MetricsEnvironment [as 别名]
# 或者: from apache_beam.metrics.execution.MetricsEnvironment import 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)
开发者ID:aljoscha,项目名称:incubator-beam,代码行数:34,代码来源:metric_test.py

示例2: test_create_counter_distribution

# 需要导入模块: from apache_beam.metrics.execution import MetricsEnvironment [as 别名]
# 或者: from apache_beam.metrics.execution.MetricsEnvironment import current_container [as 别名]
  def test_create_counter_distribution(self):
    sampler = statesampler.StateSampler('', counters.CounterFactory())
    statesampler.set_current_tracker(sampler)
    state1 = sampler.scoped_state('mystep', 'myState',
                                  metrics_container=MetricsContainer('mystep'))
    sampler.start()
    with state1:
      counter_ns = 'aCounterNamespace'
      distro_ns = 'aDistributionNamespace'
      name = 'a_name'
      counter = Metrics.counter(counter_ns, name)
      distro = Metrics.distribution(distro_ns, name)
      counter.inc(10)
      counter.dec(3)
      distro.update(10)
      distro.update(2)
      self.assertTrue(isinstance(counter, Metrics.DelegatingCounter))
      self.assertTrue(isinstance(distro, Metrics.DelegatingDistribution))

      del distro
      del counter

      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))
    sampler.stop()
开发者ID:JavierRoger,项目名称:beam,代码行数:32,代码来源:metric_test.py

示例3: test_scoped_container

# 需要导入模块: from apache_beam.metrics.execution import MetricsEnvironment [as 别名]
# 或者: from apache_beam.metrics.execution.MetricsEnvironment import current_container [as 别名]
  def test_scoped_container(self):
    c1 = MetricsContainer('mystep')
    c2 = MetricsContainer('myinternalstep')
    with ScopedMetricsContainer(c1):
      self.assertEqual(c1, MetricsEnvironment.current_container())
      counter = Metrics.counter('ns', 'name')
      counter.inc(2)

      with ScopedMetricsContainer(c2):
        self.assertEqual(c2, MetricsEnvironment.current_container())
        counter = Metrics.counter('ns', 'name')
        counter.inc(3)
        self.assertEqual(
            c2.get_cumulative().counters.items(),
            [(MetricKey('myinternalstep', MetricName('ns', 'name')), 3)])

      self.assertEqual(c1, MetricsEnvironment.current_container())
      counter = Metrics.counter('ns', 'name')
      counter.inc(4)
      self.assertEqual(
          c1.get_cumulative().counters.items(),
          [(MetricKey('mystep', MetricName('ns', 'name')), 6)])
开发者ID:eljefe6a,项目名称:incubator-beam,代码行数:24,代码来源:execution_test.py

示例4: set

# 需要导入模块: from apache_beam.metrics.execution import MetricsEnvironment [as 别名]
# 或者: from apache_beam.metrics.execution.MetricsEnvironment import current_container [as 别名]
 def set(self, value):
   container = MetricsEnvironment.current_container()
   if container is not None:
     container.get_gauge(self.metric_name).set(value)
开发者ID:charlesccychen,项目名称:incubator-beam,代码行数:6,代码来源:metric.py

示例5: update

# 需要导入模块: from apache_beam.metrics.execution import MetricsEnvironment [as 别名]
# 或者: from apache_beam.metrics.execution.MetricsEnvironment import current_container [as 别名]
 def update(self, value):
   container = MetricsEnvironment.current_container()
   if container is not None:
     container.get_distribution(self.metric_name).update(value)
开发者ID:charlesccychen,项目名称:incubator-beam,代码行数:6,代码来源:metric.py

示例6: inc

# 需要导入模块: from apache_beam.metrics.execution import MetricsEnvironment [as 别名]
# 或者: from apache_beam.metrics.execution.MetricsEnvironment import current_container [as 别名]
 def inc(self, n=1):
   container = MetricsEnvironment.current_container()
   if container is not None:
     container.get_counter(self.metric_name).inc(n)
开发者ID:charlesccychen,项目名称:incubator-beam,代码行数:6,代码来源:metric.py

示例7: test_no_container

# 需要导入模块: from apache_beam.metrics.execution import MetricsEnvironment [as 别名]
# 或者: from apache_beam.metrics.execution.MetricsEnvironment import current_container [as 别名]
 def test_no_container(self):
   self.assertEqual(MetricsEnvironment.current_container(),
                    None)
开发者ID:eljefe6a,项目名称:incubator-beam,代码行数:5,代码来源:execution_test.py


注:本文中的apache_beam.metrics.execution.MetricsEnvironment.current_container方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。