Exemple #1
0
    def test_start_time_set(self):
        c = CounterCell()
        c.inc(2)

        name = MetricName('namespace', 'name1')
        mi = c.to_runner_api_monitoring_info(name, 'transform_id')
        self.assertGreater(mi.start_time.seconds, 0)
  def test_parallel_access(self):
    # We create NUM_THREADS threads that concurrently modify the counter.
    threads = []
    c = CounterCell()
    for _ in range(TestCounterCell.NUM_THREADS):
      t = threading.Thread(target=TestCounterCell._modify_counter,
                           args=(c,))
      threads.append(t)
      t.start()

    for t in threads:
      t.join()

    total = (self.NUM_ITERATIONS * (self.NUM_ITERATIONS-1)/2 * self.NUM_THREADS)
    self.assertEqual(c.get_cumulative(), total)
Exemple #3
0
    def test_parallel_access(self):
        # We create NUM_THREADS threads that concurrently modify the counter.
        threads = []
        c = CounterCell()
        for _ in range(TestCounterCell.NUM_THREADS):
            t = threading.Thread(target=TestCounterCell._modify_counter,
                                 args=(c, ))
            threads.append(t)
            t.start()

        for t in threads:
            t.join()

        total = (self.NUM_ITERATIONS * (self.NUM_ITERATIONS - 1) // 2 *
                 self.NUM_THREADS)
        self.assertEqual(c.get_cumulative(), total)
    def test_int64_user_counter(self):
        expected_labels = {}
        expected_labels[monitoring_infos.NAMESPACE_LABEL] = "counternamespace"
        expected_labels[monitoring_infos.NAME_LABEL] = "countername"

        metric = CounterCell().get_cumulative()
        result = monitoring_infos.int64_user_counter('counternamespace',
                                                     'countername', metric)
        counter_value = monitoring_infos.extract_counter_value(result)

        self.assertEqual(0, counter_value)
        self.assertEqual(result.labels, expected_labels)
    def test_int64_counter(self):
        expected_labels = {}
        expected_labels[monitoring_infos.PCOLLECTION_LABEL] = "collectionname"
        expected_labels[monitoring_infos.PTRANSFORM_LABEL] = "ptransformname"
        expected_labels[monitoring_infos.SERVICE_LABEL] = "BigQuery"

        labels = {
            monitoring_infos.SERVICE_LABEL: "BigQuery",
        }
        metric = CounterCell().get_cumulative()
        result = monitoring_infos.int64_counter(
            monitoring_infos.API_REQUEST_COUNT_URN,
            metric,
            ptransform="ptransformname",
            pcollection="collectionname",
            labels=labels)
        counter_value = monitoring_infos.extract_counter_value(result)

        self.assertEqual(0, counter_value)
        self.assertEqual(result.labels, expected_labels)
Exemple #6
0
 def __init__(self, step_name):
     self.step_name = step_name
     self.counters = defaultdict(lambda: CounterCell())
     self.distributions = defaultdict(lambda: DistributionCell())
     self.gauges = defaultdict(lambda: GaugeCell())
Exemple #7
0
    def test_basic_operations(self):
        c = CounterCell()
        c.inc(2)
        self.assertEqual(c.get_cumulative(), 2)

        c.dec(10)
        self.assertEqual(c.get_cumulative(), -8)

        c.dec()
        self.assertEqual(c.get_cumulative(), -9)

        c.inc()
        self.assertEqual(c.get_cumulative(), -8)
Exemple #8
0
  def test_basic_operations(self):
    c = CounterCell()
    c.inc(2)
    self.assertEqual(c.get_cumulative(), 2)

    c.dec(10)
    self.assertEqual(c.get_cumulative(), -8)

    c.dec()
    self.assertEqual(c.get_cumulative(), -9)

    c.inc()
    self.assertEqual(c.get_cumulative(), -8)