diff --git a/src/Metrics/Importer/PrometheusImporter.php b/src/Metrics/Importer/PrometheusImporter.php index e3d7982..0062bd4 100644 --- a/src/Metrics/Importer/PrometheusImporter.php +++ b/src/Metrics/Importer/PrometheusImporter.php @@ -49,6 +49,10 @@ private function parseInfoLine(string $line, string $prefix) private function parseDataLine(string $line, string $prefix) { + if (strpos($line, ' ') === false) { + return; + } + [$nick, $value] = explode(' ', $line); if ($prefix && strpos($nick, $prefix) === 0) { diff --git a/tests/Metrics/ImporterTest.php b/tests/Metrics/ImporterTest.php index 06c402a..c62f09f 100644 --- a/tests/Metrics/ImporterTest.php +++ b/tests/Metrics/ImporterTest.php @@ -15,6 +15,15 @@ class ImporterTest extends TestCase { + public function testInvalidLine(): void + { + $registry = new Registry(); + $info = new Info(); + $importer = new PrometheusImporter($registry, $info); + $importer->fromString(""); + $this->assertCount(0, $registry->toArray()); + } + public function testPrometheus(): void { $registry = new Registry();