Skip to content

Commit

Permalink
empty line parser fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Nov 16, 2021
1 parent 23b39d5 commit 267ab03
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Metrics/Importer/PrometheusImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions tests/Metrics/ImporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 267ab03

Please sign in to comment.