Example #1
0
 def test_defaults_flag_to_now(self, monkeypatch):
     """Tests that the flag is defaulted to the time of instantiation
     if no flag is given."""
     now = 27
     monkeypatch.setattr(time, 'time', lambda: now)
     metrics = [KeyValue("k", 27)]
     assert [("kv.k", 27, now)] == KeyValue.fold(metrics, 0)
Example #2
0
    def test_flushes_collected_metrics(self, metrics_store):
        """
        Tests that the default aggregator properly flushes the
        collected metrics to the metric store.
        """
        now = 17
        agg = DefaultAggregator(metrics_store)
        agg.add_metrics([KeyValue("k", 1, now)])
        agg.add_metrics([KeyValue("k", 2, now)])
        agg.flush()

        assert [("kv.k", 1, now), ("kv.k", 2, now)] == metrics_store.data
Example #3
0
 def test_defaults_flag_to_now(self, monkeypatch):
     """Tests that the flag is defaulted to the time of instantiation
     if no flag is given."""
     now = 27
     monkeypatch.setattr(time, 'time', lambda: now)
     metrics = [KeyValue("k", 27)]
     assert [("k", 27, now)] == KeyValue.fold(metrics, 0)
Example #4
0
    def test_add_metrics(self, aggregator):
        """
        Tests that add_metrics successfully adds an array of metrics to
        the configured aggregator.
        """
        now = 17
        metrics = [KeyValue("k", 1, now), Counter("j", 2)]
        Collector(aggregator)._add_metrics(metrics)

        assert metrics == aggregator.metrics
Example #5
0
    def test_fold_metrics_works(self, monkeypatch):
        """
        Tests that aggregators can fold metrics properly.
        """
        now = 12
        monkeypatch.setattr(time, 'time', lambda: now)
        metrics = [KeyValue("k", 1, now), Counter("j", 2)]
        result = Aggregator(None)._fold_metrics(metrics)

        assert 1 == result.count(("kv.k", 1, now))
        assert 1 == result.count(("counts.j", 2, now))
Example #6
0
 def test_fold_basic(self):
     """Tests folding over a normal metric returns the key/value
     using the flag as the timestamp."""
     metrics = [KeyValue("k", 27, 123456)]
     assert [("k", 27, 123456)] == KeyValue.fold(metrics, 0)
Example #7
0
 def test_fold_basic(self):
     """Tests folding over a normal metric returns the key/value
     using the flag as the timestamp."""
     metrics = [KeyValue("k", 27, 123456)]
     assert [("kv.k", 27, 123456)] == KeyValue.fold(metrics, 0)