24 lines
1.3 KiB
Python
24 lines
1.3 KiB
Python
import importlib.util
|
|
from pathlib import Path
|
|
import unittest
|
|
spec = importlib.util.spec_from_file_location("sample", Path(__file__).with_name("sample-capacity-resources.py"))
|
|
sample = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(sample)
|
|
|
|
class ResourceParserTest(unittest.TestCase):
|
|
def test_timestamp_is_not_counter_and_unrelated_series_are_excluded(self):
|
|
text = '\n'.join([
|
|
'container_cpu_usage_seconds_total{namespace="test",pod="api",container="api"} 0.25 1790000123456',
|
|
'container_cpu_cfs_throttled_periods_total{namespace="test",pod="api",container="api"} 3',
|
|
'container_memory_working_set_bytes{namespace="other",pod="api",container="api"} 100',
|
|
'container_memory_working_set_bytes{namespace="test",pod="api",container="POD"} 100',
|
|
'container_memory_working_set_bytes{namespace="test",pod="api",container="api"} NaN',
|
|
])
|
|
rows = sample.parse_metrics(text, "test", {"api"})
|
|
self.assertEqual(len(rows), 1)
|
|
self.assertEqual(rows[0]["container_cpu_usage_seconds_total"], 0.25)
|
|
self.assertEqual(rows[0]["container_cpu_cfs_throttled_periods_total"], 3)
|
|
self.assertNotIn("container_memory_working_set_bytes", rows[0])
|
|
|
|
if __name__ == "__main__": unittest.main()
|