Exemplo n.º 1
0
  def test_gather_metrics(self):
    name = "metric"
    metric = CountMetric()
    metric.incr(to_add=10)
    self.metrics_collector.register_metric(name, metric, 60)
    self.assertIn(60, self.metrics_collector.time_bucket_in_sec_to_metrics_name)
    self.metrics_collector._gather_metrics(60)

    message = self.metrics_collector.out_metrics.poll()
    self.assertIsNotNone(message)
    self.assertIsInstance(message, metrics_pb2.MetricPublisherPublishMessage)
    self.assertEqual(message.metrics[0].name, name)
    self.assertEqual(message.metrics[0].value, str(10))
    self.assertEqual(metric.get_value_and_reset(), 0)
Exemplo n.º 2
0
    def test_gather_metrics(self):
        name = "metric"
        metric = CountMetric()
        metric.incr(to_add=10)
        self.metrics_collector.register_metric(name, metric, 60)
        self.assertIn(
            60, self.metrics_collector.time_bucket_in_sec_to_metrics_name)
        self.metrics_collector._gather_metrics(60)

        message = self.metrics_collector.out_metrics.poll()
        self.assertIsNotNone(message)
        self.assertIsInstance(message,
                              metrics_pb2.MetricPublisherPublishMessage)
        self.assertEqual(message.metrics[0].name, name)
        self.assertEqual(message.metrics[0].value, str(10))
        self.assertEqual(metric.get_value_and_reset(), 0)
Exemplo n.º 3
0
    def test_count_metric(self):
        metric = CountMetric()
        for _ in range(10):
            metric.incr()
        self.assertEqual(metric.get_value_and_reset(), 10)

        for _ in range(10):
            metric.incr(to_add=10)
        self.assertEqual(metric.get_value_and_reset(), 100)
        self.assertEqual(metric.get_value_and_reset(), 0)
Exemplo n.º 4
0
 def setUp(self):
     self.metrics = {
         "metric1": CountMetric(),
         "metric2": MultiCountMetric(),
         "metric3": MeanReducedMetric(),
         "metric4": MultiMeanReducedMetric()
     }
     self.metrics_helper = BaseMetricsHelper(self.metrics)
     self.metrics_collector = mock_generator.MockMetricsCollector()
Exemplo n.º 5
0
  def test_count_metric(self):
    metric = CountMetric()
    for _ in range(10):
      metric.incr()
    self.assertEqual(metric.get_value_and_reset(), 10)

    for _ in range(10):
      metric.incr(to_add=10)
    self.assertEqual(metric.get_value_and_reset(), 100)
    self.assertEqual(metric.get_value_and_reset(), 0)
Exemplo n.º 6
0
    def test_register_metric(self):
        name1 = "metric1"
        metric1 = CountMetric()
        self.metrics_collector.register_metric(name1, metric1, 60)
        self.assertEqual(self.metrics_collector.metrics_map[name1], metric1)
        self.assertIn(60, self.metrics_collector.registered_timers)

        name2 = "metric2"
        metric2 = MeanReducedMetric()
        self.metrics_collector.register_metric(name2, metric2, 60)
        self.assertEqual(self.metrics_collector.metrics_map[name2], metric2)
        self.assertEqual(
            self.metrics_collector.time_bucket_in_sec_to_metrics_name[60],
            [name1, name2])

        name3 = "metric3"
        metric3 = MultiMeanReducedMetric()
        self.metrics_collector.register_metric(name3, metric3, 30)
        self.assertEqual(self.metrics_collector.metrics_map[name3], metric3)
        self.assertEqual(self.metrics_collector.registered_timers, [60, 30])