Skip to content

Commit

Permalink
Learned how to wipe the storage adapter from the registry (#89)
Browse files Browse the repository at this point in the history
* Learned how to wipe the storage adapter from the registry

Signed-off-by: Mariano Benítez Mulet <[email protected]>

* Learned how to wipe the storage adapter from the registry

Signed-off-by: Mariano Benítez Mulet <[email protected]>

* Learned how to wipe the storage adapter from the registry

Signed-off-by: Mariano Benítez Mulet <[email protected]>

Co-authored-by: Mariano Benítez Mulet <[email protected]>
  • Loading branch information
pachico and mariano-benitez-edo authored Apr 12, 2022
1 parent 0f7f022 commit 1088114
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Prometheus/CollectorRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public static function getDefault(): CollectorRegistry
return self::$defaultRegistry ?? (self::$defaultRegistry = new self(new Redis())); /** @phpstan-ignore-line */
}

/**
* Removes all previously stored metrics from underlying storage adapter
*
* @return void
*/
public function wipeStorage(): void
{
$this->storageAdapter->wipeStorage();
}

/**
* @return MetricFamilySamples[]
*/
Expand Down
7 changes: 7 additions & 0 deletions src/Prometheus/RegistryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@

interface RegistryInterface
{
/**
* Removes all previously stored metrics from underlying storage adapter
*
* @return void
*/
public function wipeStorage(): void;

/**
* @return MetricFamilySamples[]
*/
Expand Down
17 changes: 17 additions & 0 deletions tests/Test/Prometheus/AbstractCollectorRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,23 @@ public function itShouldThrowAnExceptionOnInvalidMetricLabelDataProvider(): arra
];
}

/**
* @test
*/
public function itShouldWipeTheUnderlyingStorageAdapterWhenInvokingWipeStorageMethod(): void
{
// Arrange
$registry = new CollectorRegistry($this->adapter);
$registry->registerCounter("foo", "myCounter", "Help text");
$registry->registerGauge("foo", "myGauge", "Help text");
$registry->registerHistogram("foo", "myHistogram", "Help text");

// Act
$registry->wipeStorage();

// Assert
self::assertEmpty($registry->getMetricFamilySamples());
}

abstract public function configureAdapter(): void;
}

0 comments on commit 1088114

Please sign in to comment.