Skip to content
Draft
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
4 changes: 2 additions & 2 deletions src/Prometheus/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

abstract class Collector
{
const RE_METRIC_LABEL_NAME = '/^[a-zA-Z_:][a-zA-Z0-9_:]*$/';
protected const RE_METRIC_LABEL_NAME = '/^[a-zA-Z_:][a-zA-Z0-9_:]*$/';

/**
* @var Adapter
Expand Down Expand Up @@ -58,7 +58,7 @@ public function __construct(Adapter $storageAdapter, $namespace, $name, $help, $
/**
* @return string
*/
abstract public function getType();
abstract public function getType(): string;

/**
* @return string
Expand Down
2 changes: 1 addition & 1 deletion src/Prometheus/Counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Counter extends Collector
{
const TYPE = 'counter';
public const TYPE = 'counter';

/**
* @return string
Expand Down
2 changes: 1 addition & 1 deletion src/Prometheus/Gauge.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Gauge extends Collector
{
const TYPE = 'gauge';
public const TYPE = 'gauge';

/**
* @param double $value e.g. 123
Expand Down
2 changes: 1 addition & 1 deletion src/Prometheus/Histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class Histogram extends Collector
{
const TYPE = 'histogram';
public const TYPE = 'histogram';

/**
* @var array|null
Expand Down
2 changes: 1 addition & 1 deletion src/Prometheus/RenderTextFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class RenderTextFormat
{
const MIME_TYPE = 'text/plain; version=0.0.4';
public const MIME_TYPE = 'text/plain; version=0.0.4';

/**
* @param MetricFamilySamples[] $metrics
Expand Down
4 changes: 2 additions & 2 deletions src/Prometheus/Sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public function getName(): string
*/
public function getLabelNames(): array
{
return (array)$this->labelNames;
return (array) $this->labelNames;
}

/**
* @return array
*/
public function getLabelValues(): array
{
return (array)$this->labelValues;
return (array) $this->labelValues;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Prometheus/Storage/APC.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class APC implements Adapter
{
const PROMETHEUS_PREFIX = 'prom';
private const PROMETHEUS_PREFIX = 'prom';

/**
* @return MetricFamilySamples[]
Expand Down Expand Up @@ -251,7 +251,7 @@ private function collectHistograms(): array
$acc = 0;
$decodedLabelValues = $this->decodeLabelValues($labelValues);
foreach ($data['buckets'] as $bucket) {
$bucket = (string)$bucket;
$bucket = (string) $bucket;
if (!isset($histogramBuckets[$labelValues][$bucket])) {
$data['samples'][] = [
'name' => $metaData['name'] . '_bucket',
Expand Down
8 changes: 4 additions & 4 deletions src/Prometheus/Storage/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

interface Adapter
{
const COMMAND_INCREMENT_INTEGER = 1;
const COMMAND_INCREMENT_FLOAT = 2;
const COMMAND_SET = 3;
public const COMMAND_INCREMENT_INTEGER = 1;
public const COMMAND_INCREMENT_FLOAT = 2;
public const COMMAND_SET = 3;

/**
* @return MetricFamilySamples[]
*/
public function collect();
public function collect(): array;

/**
* @param array $data
Expand Down
2 changes: 1 addition & 1 deletion src/Prometheus/Storage/InMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function collectHistograms(): array
$acc = 0;
$decodedLabelValues = $this->decodeLabelValues($labelValues);
foreach ($data['buckets'] as $bucket) {
$bucket = (string)$bucket;
$bucket = (string) $bucket;
if (!isset($histogramBuckets[$labelValues][$bucket])) {
$data['samples'][] = [
'name' => $metaData['name'] . '_bucket',
Expand Down
2 changes: 1 addition & 1 deletion src/Prometheus/Storage/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Redis implements Adapter
{
const PROMETHEUS_METRIC_KEYS_SUFFIX = '_METRIC_KEYS';
private const PROMETHEUS_METRIC_KEYS_SUFFIX = '_METRIC_KEYS';

/**
* @var array
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/BlackBoxPushGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BlackBoxPushGatewayTest extends TestCase
/**
* @test
*/
public function pushGatewayShouldWork()
public function pushGatewayShouldWork(): void
{
$adapter = new APC();
$registry = new CollectorRegistry($adapter);
Expand Down
16 changes: 8 additions & 8 deletions tests/Test/BlackBoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BlackBoxTest extends TestCase
*/
private $adapter;

public function setUp()
public function setUp(): void
{
$this->adapter = getenv('ADAPTER');
$this->client = new Client(['base_uri' => 'http://nginx:80/']);
Expand All @@ -28,7 +28,7 @@ public function setUp()
/**
* @test
*/
public function gaugesShouldBeOverwritten()
public function gaugesShouldBeOverwritten(): void
{
$start = microtime(true);
$promises = [
Expand All @@ -43,7 +43,7 @@ public function gaugesShouldBeOverwritten()
echo "\ntime: " . ($end - $start) . "\n";

$metricsResult = $this->client->get('/examples/metrics.php?adapter=' . $this->adapter);
$body = (string)$metricsResult->getBody();
$body = (string) $metricsResult->getBody();
echo "\nbody: " . $body . "\n";
$this->assertThat(
$body,
Expand All @@ -58,13 +58,13 @@ public function gaugesShouldBeOverwritten()
/**
* @test
*/
public function countersShouldIncrementAtomically()
public function countersShouldIncrementAtomically(): void
{
$start = microtime(true);
$promises = [];
$sum = 0;
for ($i = 0; $i < 1100; $i++) {
$promises[] = $this->client->getAsync('/examples/some_counter.php?c=' . $i . '&adapter=' . $this->adapter);
$promises[] = $this->client->getAsync('/examples/some_counter.php?c=' . $i . '&adapter=' . $this->adapter);
$sum += $i;
}

Expand All @@ -73,15 +73,15 @@ public function countersShouldIncrementAtomically()
echo "\ntime: " . ($end - $start) . "\n";

$metricsResult = $this->client->get('/examples/metrics.php?adapter=' . $this->adapter);
$body = (string)$metricsResult->getBody();
$body = (string) $metricsResult->getBody();

$this->assertThat($body, $this->stringContains('test_some_counter{type="blue"} ' . $sum));
}

/**
* @test
*/
public function histogramsShouldIncrementAtomically()
public function histogramsShouldIncrementAtomically(): void
{
$start = microtime(true);
$promises = [
Expand All @@ -102,7 +102,7 @@ public function histogramsShouldIncrementAtomically()
echo "\ntime: " . ($end - $start) . "\n";

$metricsResult = $this->client->get('/examples/metrics.php?adapter=' . $this->adapter);
$body = (string)$metricsResult->getBody();
$body = (string) $metricsResult->getBody();

$this->assertThat($body, $this->stringContains(<<<EOF
test_some_histogram_bucket{type="blue",le="0.1"} 1
Expand Down
3 changes: 1 addition & 2 deletions tests/Test/Prometheus/APC/CollectorRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
*/
class CollectorRegistryTest extends AbstractCollectorRegistryTest
{

public function configureAdapter()
public function configureAdapter(): void
{
$this->adapter = new APC();
$this->adapter->flushAPC();
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/Prometheus/APC/CounterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class CounterTest extends AbstractCounterTest
{
public function configureAdapter()
public function configureAdapter(): void
{
$this->adapter = new APC();
$this->adapter->flushAPC();
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/Prometheus/APC/GaugeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class GaugeTest extends AbstractGaugeTest
{
public function configureAdapter()
public function configureAdapter(): void
{
$this->adapter = new APC();
$this->adapter->flushAPC();
Expand Down
2 changes: 1 addition & 1 deletion tests/Test/Prometheus/APC/HistogramTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class HistogramTest extends AbstractHistogramTest
{
public function configureAdapter()
public function configureAdapter(): void
{
$this->adapter = new APC();
$this->adapter->flushAPC();
Expand Down
35 changes: 17 additions & 18 deletions tests/Test/Prometheus/AbstractCollectorRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ abstract class AbstractCollectorRegistryTest extends TestCase
*/
private $renderer;

abstract public function configureAdapter(): void;

public function setUp(): void
{
$this->configureAdapter();
Expand All @@ -32,7 +34,7 @@ public function setUp(): void
/**
* @test
*/
public function itShouldSaveGauges()
public function itShouldSaveGauges(): void
{
$registry = new CollectorRegistry($this->adapter);

Expand Down Expand Up @@ -63,7 +65,7 @@ public function itShouldSaveGauges()
/**
* @test
*/
public function itShouldSaveCounters()
public function itShouldSaveCounters(): void
{
$registry = new CollectorRegistry($this->adapter);
$metric = $registry->registerCounter('test', 'some_metric', 'this is for testing', ['foo', 'bar']);
Expand All @@ -89,7 +91,7 @@ public function itShouldSaveCounters()
/**
* @test
*/
public function itShouldSaveHistograms()
public function itShouldSaveHistograms(): void
{
$registry = new CollectorRegistry($this->adapter);
$metric = $registry->registerHistogram(
Expand Down Expand Up @@ -142,7 +144,7 @@ public function itShouldSaveHistograms()
/**
* @test
*/
public function itShouldSaveHistogramsWithoutLabels()
public function itShouldSaveHistogramsWithoutLabels(): void
{
$registry = new CollectorRegistry($this->adapter);
$metric = $registry->registerHistogram('test', 'some_metric', 'this is for testing');
Expand Down Expand Up @@ -183,7 +185,7 @@ public function itShouldSaveHistogramsWithoutLabels()
/**
* @test
*/
public function itShouldIncreaseACounterWithoutNamespace()
public function itShouldIncreaseACounterWithoutNamespace(): void
{
$registry = new CollectorRegistry($this->adapter);
$registry
Expand All @@ -207,7 +209,7 @@ public function itShouldIncreaseACounterWithoutNamespace()
/**
* @test
*/
public function itShouldForbidRegisteringTheSameCounterTwice()
public function itShouldForbidRegisteringTheSameCounterTwice(): void
{
$registry = new CollectorRegistry($this->adapter);
$registry->registerCounter('foo', 'metric', 'help');
Expand All @@ -219,7 +221,7 @@ public function itShouldForbidRegisteringTheSameCounterTwice()
/**
* @test
*/
public function itShouldForbidRegisteringTheSameCounterWithDifferentLabels()
public function itShouldForbidRegisteringTheSameCounterWithDifferentLabels(): void
{
$registry = new CollectorRegistry($this->adapter);
$registry->registerCounter('foo', 'metric', 'help', ["foo", "bar"]);
Expand All @@ -231,7 +233,7 @@ public function itShouldForbidRegisteringTheSameCounterWithDifferentLabels()
/**
* @test
*/
public function itShouldForbidRegisteringTheSameHistogramTwice()
public function itShouldForbidRegisteringTheSameHistogramTwice(): void
{
$registry = new CollectorRegistry($this->adapter);
$registry->registerHistogram('foo', 'metric', 'help');
Expand All @@ -243,7 +245,7 @@ public function itShouldForbidRegisteringTheSameHistogramTwice()
/**
* @test
*/
public function itShouldForbidRegisteringTheSameHistogramWithDifferentLabels()
public function itShouldForbidRegisteringTheSameHistogramWithDifferentLabels(): void
{
$registry = new CollectorRegistry($this->adapter);
$registry->registerCounter('foo', 'metric', 'help', ["foo", "bar"]);
Expand All @@ -255,7 +257,7 @@ public function itShouldForbidRegisteringTheSameHistogramWithDifferentLabels()
/**
* @test
*/
public function itShouldForbidRegisteringTheSameGaugeTwice()
public function itShouldForbidRegisteringTheSameGaugeTwice(): void
{
$registry = new CollectorRegistry($this->adapter);
$registry->registerGauge('foo', 'metric', 'help');
Expand All @@ -267,7 +269,7 @@ public function itShouldForbidRegisteringTheSameGaugeTwice()
/**
* @test
*/
public function itShouldForbidRegisteringTheSameGaugeWithDifferentLabels()
public function itShouldForbidRegisteringTheSameGaugeWithDifferentLabels(): void
{
$registry = new CollectorRegistry($this->adapter);
$registry->registerGauge('foo', 'metric', 'help', ["foo", "bar"]);
Expand All @@ -279,7 +281,7 @@ public function itShouldForbidRegisteringTheSameGaugeWithDifferentLabels()
/**
* @test
*/
public function itShouldThrowAnExceptionWhenGettingANonExistentMetric()
public function itShouldThrowAnExceptionWhenGettingANonExistentMetric(): void
{
$registry = new CollectorRegistry($this->adapter);

Expand All @@ -290,7 +292,7 @@ public function itShouldThrowAnExceptionWhenGettingANonExistentMetric()
/**
* @test
*/
public function itShouldNotRegisterACounterTwice()
public function itShouldNotRegisterACounterTwice(): void
{
$registry = new CollectorRegistry($this->adapter);
$counterA = $registry->getOrRegisterCounter("foo", "bar", "Help text");
Expand All @@ -302,7 +304,7 @@ public function itShouldNotRegisterACounterTwice()
/**
* @test
*/
public function itShouldNotRegisterAGaugeTwice()
public function itShouldNotRegisterAGaugeTwice(): void
{
$registry = new CollectorRegistry($this->adapter);
$gaugeA = $registry->getOrRegisterGauge("foo", "bar", "Help text");
Expand All @@ -314,15 +316,12 @@ public function itShouldNotRegisterAGaugeTwice()
/**
* @test
*/
public function itShouldNotRegisterAHistogramTwice()
public function itShouldNotRegisterAHistogramTwice(): void
{
$registry = new CollectorRegistry($this->adapter);
$histogramA = $registry->getOrRegisterHistogram("foo", "bar", "Help text");
$histogramB = $registry->getOrRegisterHistogram("foo", "bar", "Help text");

$this->assertSame($histogramA, $histogramB);
}


abstract public function configureAdapter();
}
Loading