|
17 | 17 | import sys |
18 | 18 | from collections import namedtuple |
19 | 19 | from platform import python_implementation |
20 | | -from unittest import mock, skipIf |
| 20 | +from tempfile import TemporaryDirectory |
| 21 | +from unittest import mock, skipIf, skipUnless |
21 | 22 |
|
22 | 23 | from opentelemetry.instrumentation.system_metrics import ( |
23 | 24 | _DEFAULT_CONFIG, |
@@ -415,6 +416,38 @@ def test_system_swap_utilization(self, mock_swap_memory): |
415 | 416 | ] |
416 | 417 | self._test_metrics("system.swap.utilization", expected) |
417 | 418 |
|
| 419 | + @skipUnless(sys.platform == "linux", "Linux only") |
| 420 | + def test_system_swap_states_removed_when_vmstat_missing(self): |
| 421 | + with ( |
| 422 | + self.assertLogs(level="WARNING") as logwatcher, |
| 423 | + TemporaryDirectory() as tmpdir, |
| 424 | + mock.patch( |
| 425 | + target="psutil.PROCFS_PATH", |
| 426 | + new=tmpdir, |
| 427 | + create=True, |
| 428 | + ), |
| 429 | + ): |
| 430 | + runtime_config = { |
| 431 | + "system.swap.usage": ["free", "sin", "sout", "used"], |
| 432 | + "system.swap.utilization": ["free", "sin", "sout", "used"], |
| 433 | + } |
| 434 | + |
| 435 | + runtime_metrics = SystemMetricsInstrumentor(config=runtime_config) |
| 436 | + runtime_metrics.instrument() |
| 437 | + |
| 438 | + self.assertEqual( |
| 439 | + first=len(logwatcher.records), |
| 440 | + second=1, |
| 441 | + ) |
| 442 | + self.assertListEqual( |
| 443 | + list1=runtime_metrics._config["system.swap.usage"], |
| 444 | + list2=["free", "used"], |
| 445 | + ) |
| 446 | + self.assertListEqual( |
| 447 | + list1=runtime_metrics._config["system.swap.utilization"], |
| 448 | + list2=["free", "used"], |
| 449 | + ) |
| 450 | + |
418 | 451 | @mock.patch("psutil.disk_io_counters") |
419 | 452 | def test_system_disk_io(self, mock_disk_io_counters): |
420 | 453 | DiskIO = namedtuple( |
|
0 commit comments