Passed
Push — master ( f9598b...4c4a55 )
by Vlad
01:28
created

helpers.TimestampMixin.__init__()   A

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nop 3
1
from prometheus_client.core import CounterMetricFamily, GaugeMetricFamily
2
3
4
class TimestampMixin(object):
5
    def __init__(self, *args, **kwargs):
6
        try:
7
            self._timestamp = kwargs.pop('timestamp')
8
        except KeyError:
9
            self._timestamp = None
10
        super(TimestampMixin, self).__init__(*args, **kwargs)
11
12
    def add_metric(self, *args, **kwargs):
13
        if 'timestamp' not in kwargs:
14
            kwargs['timestamp'] = self._timestamp
15
        super(TimestampMixin, self).add_metric(*args, **kwargs)
16
17
18
class TimestampGaugeMetricFamily(TimestampMixin, GaugeMetricFamily):
19
    pass
20
21
22
class TimestampCounterMetricFamily(TimestampMixin, CounterMetricFamily):
23
    pass
24