Ejemplo n.º 1
0
    def test_fold_sum(self):
        """
        Tests that folding generates a sum of the timers.
        """
        now = 10
        metrics = [Timer("k", 10),
                   Timer("k", 15),
                   Timer("j", 7.4),
                   Timer("j", 8.6)]
        result = Timer.fold(metrics, now)

        assert ("timers.k.sum", 25, now) == self._get_metric("timers.k.sum", result)
        assert ("timers.j.sum", 16.0, now) == self._get_metric("timers.j.sum", result)
Ejemplo n.º 2
0
    def test_fold_count(self):
        """
        Tests the counter of timers is properly computed.
        """
        now = 10
        metrics = [Timer("k", 10),
                   Timer("k", 15),
                   Timer("j", 7.9),
                   Timer("j", 8)]
        result = Timer.fold(metrics, now)

        assert ("timers.k.count", 2, now) == self._get_metric("timers.k.count", result)
        assert ("timers.j.count", 2, now) == self._get_metric("timers.j.count", result)
Ejemplo n.º 3
0
    def test_fold_upper(self):
        """
        Tests that the upper bound for the timers is properly computed.
        """
        now = 10
        metrics = [Timer("k", 10),
                   Timer("k", 15),
                   Timer("j", 7.9),
                   Timer("j", 8)]
        result = Timer.fold(metrics, now)

        assert ("timers.k.upper", 15, now) == self._get_metric("timers.k.upper", result)
        assert ("timers.j.upper", 8, now) == self._get_metric("timers.j.upper", result)
Ejemplo n.º 4
0
    def test_fold_mean(self):
        """
        Tests that the mean is properly generated for the
        timers.
        """
        now = 10
        metrics = [Timer("k", 10),
                   Timer("k", 15),
                   Timer("j", 7),
                   Timer("j", 8)]
        result = Timer.fold(metrics, now)

        assert ("timers.k.mean", 12.5, now) == self._get_metric("timers.k.mean", result)
        assert ("timers.j.mean", 7.5, now) == self._get_metric("timers.j.mean", result)
Ejemplo n.º 5
0
 def test_sum_percentile(self):
     """
     Tests the percentile sum is properly counted.
     """
     now = 10
     result = Timer.fold(self._100_timers, now)
     assert ("timers.k.sum_90", 4545, now) == self._get_metric("timers.k.sum_90", result)
Ejemplo n.º 6
0
    def test_stdev(self):
        """
        Tests that the standard deviation is properly computed.
        """
        numbers = [0.331002, 0.591082, 0.668996, 0.422566, 0.458904,
                   0.868717, 0.30459, 0.513035, 0.900689, 0.655826]
        average = sum(numbers) / len(numbers)

        assert int(0.205767 * 10000) == int(Timer._stdev(numbers, average) * 10000)
Ejemplo n.º 7
0
    def test_parse_metrics_keeps_good_metrics(self, aggregator):
        """
        Tests that parse_metrics will keep the good metrics in the face
        of an error.
        """
        message = "\n".join(["k::1|c",
                             "j:2|nope",
                             "k:2|ms"])
        results = Collector(aggregator)._parse_metrics(message)

        assert [Timer("k", 2)] == results
Ejemplo n.º 8
0
    def test_fold_metrics_passes_metric_settings(self, monkeypatch):
        """
        Tests that aggregators pass the proper metric settings when
        folding over.
        """
        now = 12
        settings = {"ms": {"percentile": 80}}
        metrics = [Timer("k", 20, now)]

        monkeypatch.setattr(time, 'time', lambda: now)
        result = Aggregator(None,
                            metrics_settings=settings)._fold_metrics(metrics)
        print repr(result)
        assert 1 == result.count(("timers.k.sum_80", 20, now))
Ejemplo n.º 9
0
    def test_fold_stdev(self):
        """
        Tests the standard deviations of counters is properly computed.
        """
        now = 10
        metrics = [Timer("k", 10),
                   Timer("k", 15),
                   Timer("j", 7.9),
                   Timer("j", 8)]
        result = Timer.fold(metrics, now)

        assert ("timers.k.stdev", Timer._stdev([10, 15], 12.5), now) == self._get_metric("timers.k.stdev", result)
        assert ("timers.j.stdev", Timer._stdev([7.9, 8], 7.95), now) == self._get_metric("timers.j.stdev", result)
Ejemplo n.º 10
0
 def test_parse_metrics_ignores_blank_lines(self, aggregator):
     """
     Tests that parse_metrics will properly ignore blank lines.
     """
     message = "\n".join(["", "k:2|ms"])
     assert [Timer("k", 2)] == Collector(aggregator)._parse_metrics(message)
Ejemplo n.º 11
0
    def _100_timers(self):
        result = []
        for i in xrange(1, 101):
            result.append(Timer("k", i))

        return result