Skip to content

Commit

Permalink
Fix a few mixed types
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSuisse committed Jun 7, 2019
1 parent 7a0775b commit f29a4c2
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions examples/flush_adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

require __DIR__ . '/../vendor/autoload.php';

$adapter = $_GET['adapter'] ?? '';
$adapter = (string) $_GET['adapter'] ?? '';

$storage = null;

if ($adapter === 'redis') {
$redis_client = new Redis();
$redis_client->connect($_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$redis_client->connect((string) $_SERVER['REDIS_HOST'] ?? '127.0.0.1');

$storage = new Prometheus\Storage\RedisStore($redis_client);
}
Expand Down
6 changes: 4 additions & 2 deletions examples/metrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
use Prometheus\Registry\CollectorRegistry;
use Prometheus\Renderer\RenderTextFormat;

$adapter = $_GET['adapter'] ?? '';
$adapter = (string) $_GET['adapter'] ?? '';

if ($adapter === 'redis') {
$redis_client = new Redis();
$redis_client->connect($_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$redis_client->connect((string) $_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$adapter = new Prometheus\Storage\RedisStore($redis_client);
} elseif ($adapter === 'apcu') {
$adapter = new Prometheus\Storage\APCUStore();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemoryStore();
} else {
$adapter = new Prometheus\Storage\NullStore();
}
$registry = new CollectorRegistry($adapter);
$renderer = new RenderTextFormat();
Expand Down
6 changes: 4 additions & 2 deletions examples/pushgateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
use Prometheus\Value\MetricLabelNames;
use Prometheus\Value\MetricName;

$adapter = $_GET['adapter'] ?? '';
$adapter = (string) $_GET['adapter'] ?? '';

if ($adapter === 'redis') {
$redis_client = new Redis();
$redis_client->connect($_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$redis_client->connect((string) $_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$adapter = new RedisStore($redis_client);
} elseif ($adapter === 'apcu') {
$adapter = new Prometheus\Storage\APCUStore();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemoryStore();
} else {
$adapter = new Prometheus\Storage\NullStore();
}

$registry = new CollectorRegistry($adapter);
Expand Down
8 changes: 5 additions & 3 deletions examples/some_counter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
use Prometheus\Value\MetricLabelNames;
use Prometheus\Value\MetricName;

$adapter = $_GET['adapter'];
$adapter = (string) $_GET['adapter'];

if ($adapter === 'redis') {
$redis_client = new Redis();
$redis_client->connect($_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$redis_client->connect((string) $_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$adapter = new Prometheus\Storage\RedisStore($redis_client);
} elseif ($adapter === 'apcu') {
$adapter = new Prometheus\Storage\APCUStore();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemoryStore();
} else {
$adapter = new Prometheus\Storage\NullStore();
}
$registry = new CollectorRegistry($adapter);

Expand All @@ -26,6 +28,6 @@
'it increases',
MetricLabelNames::fromNames('type')
);
$counter->incBy((int) $_GET['c'], 'blue');
$counter->incBy((float) $_GET['c'], 'blue');

echo "OK\n";
8 changes: 4 additions & 4 deletions examples/some_gauge.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
use Prometheus\Value\MetricLabelNames;
use Prometheus\Value\MetricName;

error_log('c=' . $_GET['c']);

$adapter = $_GET['adapter'] ?? '';
$adapter = (string) $_GET['adapter'] ?? '';

if ($adapter === 'redis') {
$redis_client = new Redis();
$redis_client->connect($_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$redis_client->connect((string) $_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$adapter = new Prometheus\Storage\RedisStore($redis_client);
} elseif ($adapter === 'apcu') {
$adapter = new Prometheus\Storage\APCUStore();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemoryStore();
} else {
$adapter = new Prometheus\Storage\NullStore();
}
$registry = new CollectorRegistry($adapter);

Expand Down
8 changes: 4 additions & 4 deletions examples/some_histogram.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
use Prometheus\Value\HistogramLabelNames;
use Prometheus\Value\MetricName;

error_log('c=' . $_GET['c']);

$adapter = $_GET['adapter'] ?? '';
$adapter = (string) $_GET['adapter'] ?? '';

if ($adapter === 'redis') {
$redis_client = new Redis();
$redis_client->connect($_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$redis_client->connect((string) $_SERVER['REDIS_HOST'] ?? '127.0.0.1');
$adapter = new Prometheus\Storage\RedisStore($redis_client);
} elseif ($adapter === 'apcu') {
$adapter = new Prometheus\Storage\APCUStore();
} elseif ($adapter === 'in-memory') {
$adapter = new Prometheus\Storage\InMemoryStore();
} else {
$adapter = new Prometheus\Storage\NullStore();
}
$registry = new CollectorRegistry($adapter);

Expand Down
6 changes: 3 additions & 3 deletions src/Prometheus/Storage/APCUStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function updateHistogram(MetricName $name, float $value, array $buckets,
// Taken from https://github.com/prometheus/client_golang/blob/66058aac3a83021948e5fb12f1f408ff556b9037/prometheus/value.go#L91
$done = false;
while (! $done) {
$old = apcu_fetch($sumKey);
$old = (int) apcu_fetch($sumKey);
$done = apcu_cas($sumKey, $old, $this->toInteger($this->fromInteger($old) + $value));
}

Expand Down Expand Up @@ -104,7 +104,7 @@ public function addToGauge(MetricName $name, float $value, string $help, MetricL
// Taken from https://github.com/prometheus/client_golang/blob/66058aac3a83021948e5fb12f1f408ff556b9037/prometheus/value.go#L91
$done = false;
while (! $done) {
$old = apcu_fetch($valueKey);
$old = (int) apcu_fetch($valueKey);
$done = apcu_cas($valueKey, $old, $this->toInteger($this->fromInteger($old) + $value));
}
}
Expand All @@ -120,7 +120,7 @@ public function incrementCounter(MetricName $name, float $value, string $help, M
// Taken from https://github.com/prometheus/client_golang/blob/66058aac3a83021948e5fb12f1f408ff556b9037/prometheus/value.go#L91
$done = false;
while (! $done) {
$old = apcu_fetch($valueKey);
$old = (int) apcu_fetch($valueKey);
$done = apcu_cas($valueKey, $old, $this->toInteger($this->fromInteger($old) + $value));
}
}
Expand Down

0 comments on commit f29a4c2

Please sign in to comment.