Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Learned how to wipe the storage adapter from the registry #89

Merged
merged 5 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}