Skip to content
Permalink
Browse files

Delete only the metrics data instead of flushing the whole APCu cache

  • Loading branch information...
LeSuisse committed Sep 14, 2019
1 parent 8dbcc49 commit 065e804ef2534b4eb8dbc6df8190eb52fcf82791
@@ -14,7 +14,7 @@
use const JSON_THROW_ON_ERROR;
use function apcu_add;
use function apcu_cas;
use function apcu_clear_cache;
use function apcu_delete;
use function apcu_fetch;
use function apcu_inc;
use function apcu_store;
@@ -126,7 +126,7 @@ public function incrementCounter(MetricName $name, float $value, string $help, M
public function flush() : void
{
apcu_clear_cache();
apcu_delete(new APCuIterator('/^' . self::PROMETHEUS_PREFIX . ':.*/'));
}
private function metaKey(MetricName $name, string $type) : string
@@ -4,14 +4,65 @@
namespace Enalean\PrometheusTest\Storage\APCU;
use APCuIterator;
use Enalean\Prometheus\Registry\CollectorRegistry;
use Enalean\Prometheus\Renderer\RenderTextFormat;
use Enalean\Prometheus\Value\HistogramLabelNames;
use Enalean\Prometheus\Value\MetricLabelNames;
use Enalean\Prometheus\Value\MetricName;
use Enalean\PrometheusTest\Storage\CollectorRegistryBaseTest;
use function apcu_clear_cache;
use function apcu_delete;
use function apcu_fetch;
use function apcu_store;
/**
* @requires extension apcu
* @covers Enalean\Prometheus\Registry\CollectorRegistry
* @covers Enalean\Prometheus\Storage\APCUStore
* @covers \Enalean\Prometheus\Registry\CollectorRegistry
* @covers \Enalean\Prometheus\Storage\APCUStore
*/
final class CollectorRegistryTest extends CollectorRegistryBaseTest
{
use ConfigureAPCUStorage;
/**
* @before
* @after
*/
public function flushAPCu() : void
{
apcu_clear_cache();
}
public function testShouldOnlyFlushMetricData() : void
{
apcu_store('foo', 'bar');
$storage = $this->getStorage();
$registry = new CollectorRegistry($storage);
$counter = $registry->registerCounter(MetricName::fromNamespacedName('test', 'some_counter'), 'it increases', MetricLabelNames::fromNames('type'));
$counter->incBy(6, 'blue');
$gauge = $registry->registerGauge(MetricName::fromNamespacedName('test', 'some_gauge'), 'this is for testing', MetricLabelNames::fromNames('foo'));
$gauge->set(35, 'bar');
$histogram = $registry->registerHistogram(
MetricName::fromNamespacedName('test', 'some_histogram'),
'this is for testing',
HistogramLabelNames::fromNames('foo', 'bar'),
[0.1, 1, 5, 10]
);
$histogram->observe(2, 'cat', 'meow');
$this->assertGreaterThan(1, (new APCuIterator('/.*/'))->getTotalCount());
$storage->flush();
$this->assertEquals(1, (new APCuIterator('/.*/'))->getTotalCount());
$this->assertEquals('bar', apcu_fetch('foo'));
$this->assertEquals("\n", (new RenderTextFormat())->render($registry->getMetricFamilySamples()));
apcu_delete('foo');
}
}
@@ -14,8 +14,8 @@
/**
* @requires extension redis
* @covers Enalean\Prometheus\Registry\CollectorRegistry
* @covers Enalean\Prometheus\Storage\RedisStore
* @covers \Enalean\Prometheus\Registry\CollectorRegistry
* @covers \Enalean\Prometheus\Storage\RedisStore
*/
final class CollectorRegistryTest extends CollectorRegistryBaseTest
{

0 comments on commit 065e804

Please sign in to comment.
You can’t perform that action at this time.