Exemple #1
0
 def test_incr(self, caplog):
     caplog.set_level("DEBUG")
     rec = MetricsRecord("incr", key="foo", value=10, tags=["key1:val", "key2:val"])
     lm = LoggingMetrics()
     lm.emit_to_backend(rec)
     assert caplog.record_tuples == [
         ("markus", 20, "METRICS|2017-03-06 16:30:00|incr|foo|10|#key1:val,key2:val")
     ]
Exemple #2
0
    def test_histogram(self, caplog):
        caplog.set_level('DEBUG')
        lm = LoggingMetrics({})

        lm.histogram('foo', value=4321, tags=['key1:val', 'key2:val'])

        assert (caplog.record_tuples == [(
            'markus', 20,
            'METRICS|2017-03-06 16:30:00|histogram|foo|4321|#key1:val,key2:val'
        )])
Exemple #3
0
    def test_timing(self, caplog):
        caplog.set_level('DEBUG')
        lm = LoggingMetrics({})

        lm.timing('foo', value=1234, tags=['key1:val', 'key2:val'])

        assert (caplog.record_tuples == [
            ('markus', 20,
             'METRICS|2017-03-06 16:30:00|timing|foo|1234|#key1:val,key2:val')
        ])
Exemple #4
0
    def test_gauge(self, caplog):
        lm = LoggingMetrics({})

        lm.gauge('foo', value=100, tags=['key1:val', 'key2:val'])

        assert (
            caplog.record_tuples ==
            [
                ('markus', 20, 'METRICS|2017-03-06 16:30:00|gauge|foo|100|#key1:val,key2:val')
            ]
        )
Exemple #5
0
 def test_histogram(self, caplog):
     caplog.set_level("DEBUG")
     rec = MetricsRecord(
         "histogram", key="foo", value=4321, tags=["key1:val", "key2:val"]
     )
     lm = LoggingMetrics()
     lm.emit_to_backend(rec)
     assert caplog.record_tuples == [
         (
             "markus",
             20,
             "METRICS|2017-03-06 16:30:00|histogram|foo|4321|#key1:val,key2:val",
         )
     ]
Exemple #6
0
    def test_filters(self, caplog):
        class BlueFilter(MetricsFilter):
            def filter(self, record):
                if "blue" not in record.key:
                    return
                return record

        caplog.set_level("DEBUG")
        lm = LoggingMetrics(filters=[BlueFilter()])
        lm.emit_to_backend(MetricsRecord("incr", key="foo", value=1, tags=[]))
        lm.emit_to_backend(MetricsRecord("incr", key="foo.blue", value=2, tags=[]))
        assert caplog.record_tuples == [
            ("markus", 20, "METRICS|2017-03-06 16:30:00|incr|foo.blue|2|")
        ]