Esempio n. 1
0
 def test_small_scale(self):
     with self.assertRaises(ValueError):
         distribution.GeometricBucketer(growth_factor=-1)
     with self.assertRaises(ValueError):
         distribution.GeometricBucketer(growth_factor=0)
     with self.assertRaises(ValueError):
         distribution.GeometricBucketer(growth_factor=1)
Esempio n. 2
0
  def test_populate_canonical(self):
    pb = metrics_pb2.MetricsData()
    m = metrics.DistributionMetric('test')
    m._populate_value(pb,
        distribution.Distribution(distribution.GeometricBucketer()))
    self.assertEquals(pb.distribution.spec_type,
        metrics_pb2.PrecomputedDistribution.CANONICAL_POWERS_OF_10_P_0_2)

    m._populate_value(pb,
        distribution.Distribution(distribution.GeometricBucketer(2)))
    self.assertEquals(pb.distribution.spec_type,
        metrics_pb2.PrecomputedDistribution.CANONICAL_POWERS_OF_2)

    m._populate_value(pb,
        distribution.Distribution(distribution.GeometricBucketer(10)))
    self.assertEquals(pb.distribution.spec_type,
        metrics_pb2.PrecomputedDistribution.CANONICAL_POWERS_OF_10)
Esempio n. 3
0
    def __init__(self,
                 name,
                 is_cumulative=True,
                 bucketer=None,
                 target=None,
                 fields=None,
                 start_time=None,
                 time_fn=time.time):
        super(DistributionMetric, self).__init__(name, target, fields)
        self._start_time = start_time or int(
            time_fn() * MICROSECONDS_PER_SECOND)

        if bucketer is None:
            bucketer = distribution.GeometricBucketer()

        self.is_cumulative = is_cumulative
        self.bucketer = bucketer
Esempio n. 4
0
  def test_populate_custom(self):
    pb = metrics_pb2.MetricsData()
    m = metrics.DistributionMetric('test')
    m._populate_value(pb,
        distribution.Distribution(distribution.GeometricBucketer(4)))
    self.assertEquals(pb.distribution.spec_type,
        metrics_pb2.PrecomputedDistribution.CUSTOM_PARAMETERIZED)
    self.assertEquals(0, pb.distribution.width)
    self.assertEquals(4, pb.distribution.growth_factor)
    self.assertEquals(100, pb.distribution.num_buckets)

    m._populate_value(pb,
        distribution.Distribution(distribution.FixedWidthBucketer(10)))
    self.assertEquals(pb.distribution.spec_type,
        metrics_pb2.PrecomputedDistribution.CUSTOM_PARAMETERIZED)
    self.assertEquals(10, pb.distribution.width)
    self.assertEquals(0, pb.distribution.growth_factor)
    self.assertEquals(100, pb.distribution.num_buckets)
Esempio n. 5
0
    def test_add(self):
        d = distribution.Distribution(distribution.GeometricBucketer())
        self.assertEqual(0, d.sum)
        self.assertEqual(0, d.count)
        self.assertEqual({}, d.buckets)

        d.add(1)
        d.add(10)
        d.add(100)

        self.assertEqual(111, d.sum)
        self.assertEqual(3, d.count)
        self.assertEqual({2: 1, 6: 1, 11: 1}, d.buckets)

        d.add(50)

        self.assertEqual(161, d.sum)
        self.assertEqual(4, d.count)
        self.assertEqual({2: 1, 6: 1, 10: 1, 11: 1}, d.buckets)
Esempio n. 6
0
    def test_large_size(self):
        b = distribution.GeometricBucketer(growth_factor=4,
                                           num_finite_buckets=4)

        self.assertBucketCounts(b, 6)
        self.assertBoundaries(b, [1, 4, 16, 64])
Esempio n. 7
0
    def test_zero_size(self):
        b = distribution.GeometricBucketer(num_finite_buckets=0)

        self.assertBucketCounts(b, 2)
        self.assertBoundaries(b, [])
Esempio n. 8
0
 def test_negative_size(self):
     with self.assertRaises(ValueError):
         distribution.GeometricBucketer(num_finite_buckets=-1)