1
|
|
|
from unittest import TestCase |
2
|
|
|
|
3
|
|
|
from prometheus_client.core import GaugeMetricFamily, CounterMetricFamily |
4
|
|
|
|
5
|
|
|
from helpers import TimestampCounterMetricFamily, TimestampGaugeMetricFamily |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class TimestampMixinTestBase(TestCase): |
9
|
|
|
def test_timestamp_metric_family_has_timestamp_if_set(self): |
10
|
|
|
timestamp = 214 |
11
|
|
|
t = TimestampGaugeMetricFamily('some_name', 'some description', timestamp=timestamp) |
12
|
|
|
self.assertEquals(t._timestamp, timestamp) |
13
|
|
|
|
14
|
|
|
def test_timestamp_metric_family_has_none_timestamp_if_unset(self): |
15
|
|
|
t = TimestampGaugeMetricFamily('some_name', 'some description') |
16
|
|
|
self.assertIsNone(t._timestamp) |
17
|
|
|
|
18
|
|
|
def test_timestamp_metric_family_sets_timestamp_on_metrics_implicit_metrics(self): |
19
|
|
|
timestamp = 214 |
20
|
|
|
t = TimestampGaugeMetricFamily('some_name', 'some description', timestamp=timestamp, value=2) |
21
|
|
|
self.assertEqual(t.samples[0].timestamp, timestamp) |
22
|
|
|
|
23
|
|
|
def test_timestamp_metric_family_sets_timestamp_on_metrics_add_metric(self): |
24
|
|
|
timestamp = 214 |
25
|
|
|
t = TimestampGaugeMetricFamily('some_name', 'some description', timestamp=timestamp) |
26
|
|
|
t.add_metric(labels=[], value=123) |
27
|
|
|
self.assertEqual(t.samples[0].timestamp, timestamp) |
28
|
|
|
|
29
|
|
|
def test_timestamp_metric_family_keeps_timestamp_from_add_metric(self): |
30
|
|
|
timestamp = 214 |
31
|
|
|
t = TimestampGaugeMetricFamily('some_name', 'some description', timestamp=timestamp) |
32
|
|
|
t.add_metric(labels=[], value=123, timestamp=234) |
33
|
|
|
self.assertEqual(t.samples[0].timestamp, 234) |
34
|
|
|
|