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