Skip to content

Commit 517c791

Browse files
committed
Add and update test coverage for new storage adapter.
Signed-off-by: Arris Ray <arris.ray@gmail.com>
1 parent 6418159 commit 517c791

18 files changed

+373
-0
lines changed

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ services:
55
- php-fpm
66
ports:
77
- 8080:80
8+
environment:
9+
- REDIS_HOST=redis
810

911
php-fpm:
1012
build: php-fpm/

examples/flush_adapter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
$adapter = new Prometheus\Storage\APCng();
1717
} elseif ($adapterName === 'in-memory') {
1818
$adapter = new Prometheus\Storage\InMemory();
19+
} elseif ($adapterName === 'redistxn') {
20+
$adapter = new Prometheus\Storage\RedisTxn(['host' => $_SERVER['REDIS_HOST'] ?? '127.0.0.1']);
1921
}
2022

2123
$adapter->wipeStorage();

examples/metrics.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
$adapter = new Prometheus\Storage\APCng();
1818
} elseif ($adapter === 'in-memory') {
1919
$adapter = new Prometheus\Storage\InMemory();
20+
} elseif ($adapter === 'redistxn') {
21+
$adapter = new Prometheus\Storage\RedisTxn(['host' => $_SERVER['REDIS_HOST'] ?? '127.0.0.1']);
2022
}
2123
$registry = new CollectorRegistry($adapter);
2224
$renderer = new RenderTextFormat();

examples/some_counter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
$adapter = new Prometheus\Storage\APCng();
1717
} elseif ($adapter === 'in-memory') {
1818
$adapter = new Prometheus\Storage\InMemory();
19+
} elseif ($adapter === 'redistxn') {
20+
$adapter = new Prometheus\Storage\RedisTxn(['host' => $_SERVER['REDIS_HOST'] ?? '127.0.0.1']);
1921
}
2022
$registry = new CollectorRegistry($adapter);
2123

examples/some_gauge.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
$adapter = new Prometheus\Storage\APCng();
2020
} elseif ($adapter === 'in-memory') {
2121
$adapter = new Prometheus\Storage\InMemory();
22+
} elseif ($adapter === 'redistxn') {
23+
$adapter = new Prometheus\Storage\RedisTxn(['host' => $_SERVER['REDIS_HOST'] ?? '127.0.0.1']);
2224
}
2325
$registry = new CollectorRegistry($adapter);
2426

examples/some_histogram.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
$adapter = new Prometheus\Storage\APCng();
1919
} elseif ($adapter === 'in-memory') {
2020
$adapter = new Prometheus\Storage\InMemory();
21+
} elseif ($adapter === 'redistxn') {
22+
$adapter = new Prometheus\Storage\RedisTxn(['host' => $_SERVER['REDIS_HOST'] ?? '127.0.0.1']);
2123
}
2224
$registry = new CollectorRegistry($adapter);
2325

examples/some_summary.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
$adapter = new Prometheus\Storage\APCng();
1919
} elseif ($adapter === 'in-memory') {
2020
$adapter = new Prometheus\Storage\InMemory();
21+
} elseif ($adapter === 'redistxn') {
22+
$adapter = new Prometheus\Storage\RedisTxn(['host' => $_SERVER['REDIS_HOST'] ?? '127.0.0.1']);
2123
}
2224
$registry = new CollectorRegistry($adapter);
2325

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Test\Prometheus\RedisTxn;
6+
7+
use Prometheus\Storage\RedisTxn;
8+
use Test\Prometheus\AbstractCollectorRegistryTest;
9+
10+
/**
11+
* @requires extension redis
12+
*/
13+
class CollectorRegistryTest extends AbstractCollectorRegistryTest
14+
{
15+
public function configureAdapter(): void
16+
{
17+
$this->adapter = new RedixTxn(['host' => REDIS_HOST]);
18+
$this->adapter->wipeStorage();
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Test\Prometheus\RedisTxn;
6+
7+
use Prometheus\Storage\RedisTxn;
8+
use Test\Prometheus\AbstractCounterTest;
9+
10+
/**
11+
* See https://prometheus.io/docs/instrumenting/exposition_formats/
12+
* @requires extension redis
13+
*/
14+
class CounterTest extends AbstractCounterTest
15+
{
16+
public function configureAdapter(): void
17+
{
18+
$this->adapter = new RedixTxn(['host' => REDIS_HOST]);
19+
$this->adapter->wipeStorage();
20+
}
21+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Test\Prometheus\RedisTxn;
6+
7+
use Prometheus\Storage\RedisTxn;
8+
use Test\Prometheus\AbstractCounterTest;
9+
10+
/**
11+
* See https://prometheus.io/docs/instrumenting/exposition_formats/
12+
* @requires extension redis
13+
*/
14+
class CounterWithPrefixTest extends AbstractCounterTest
15+
{
16+
public function configureAdapter(): void
17+
{
18+
$connection = new \Redis();
19+
$connection->connect(REDIS_HOST);
20+
21+
$connection->setOption(\Redis::OPT_PREFIX, 'prefix:');
22+
23+
$this->adapter = RedixTxn::fromExistingConnection($connection);
24+
$this->adapter->wipeStorage();
25+
}
26+
}

0 commit comments

Comments
 (0)