Skip to content
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
21 changes: 11 additions & 10 deletions src/Prometheus/Storage/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public static function setPrefix(string $prefix): void
}

/**
* @deprecated use replacement method wipeStorage from Adapter interface
* @throws StorageException
* @deprecated use replacement method wipeStorage from Adapter interface
*/
public function flushRedis(): void
{
Expand Down Expand Up @@ -230,11 +230,11 @@ private function connectToServer(): void
if ($this->options['persistent_connections'] !== false) {
$connection_successful = $this->redis->pconnect(
$this->options['host'],
(int) $this->options['port'],
(float) $this->options['timeout']
(int)$this->options['port'],
(float)$this->options['timeout']
);
} else {
$connection_successful = $this->redis->connect($this->options['host'], (int) $this->options['port'], (float) $this->options['timeout']);
$connection_successful = $this->redis->connect($this->options['host'], (int)$this->options['port'], (float)$this->options['timeout']);
}
if (!$connection_successful) {
throw new StorageException(
Expand Down Expand Up @@ -306,15 +306,16 @@ public function updateSummary(array $data): void
if (false === $json) {
throw new RuntimeException(json_last_error_msg());
}
$this->redis->setNx($metaKey, $json); /** @phpstan-ignore-line */
$this->redis->setNx($metaKey, $json);/** @phpstan-ignore-line */


// store value key
$valueKey = $summaryKey . ':' . $this->valueKey($data);
$json = json_encode($this->encodeLabelValues($data['labelValues']));
if (false === $json) {
throw new RuntimeException(json_last_error_msg());
}
$this->redis->setNx($valueKey, $json); /** @phpstan-ignore-line */
$this->redis->setNx($valueKey, $json);/** @phpstan-ignore-line */

// trick to handle uniqid collision
$done = false;
Expand Down Expand Up @@ -414,7 +415,7 @@ private function collectHistograms(): array
sort($keys);
$histograms = [];
foreach ($keys as $key) {
$raw = $this->redis->hGetAll(str_replace($this->redis->_prefix(''), '', $key));
$raw = $this->redis->hGetAll(ltrim($key, $this->redis->_prefix('')));
if (!isset($raw['__meta'])) {
continue;
}
Expand Down Expand Up @@ -546,7 +547,7 @@ private function collectSummaries(): array
$sampleValues = $this->redis->keys($summaryKey . ':' . $metaData['name'] . ':' . $encodedLabelValues . ':value:*');
foreach ($sampleValues as $sampleValueWithPrefix) {
$sampleValue = $this->removePrefixFromKey($sampleValueWithPrefix);
$samples[] = (float) $this->redis->get($sampleValue);
$samples[] = (float)$this->redis->get($sampleValue);
}

if (count($samples) === 0) {
Expand Down Expand Up @@ -608,7 +609,7 @@ private function collectGauges(bool $sortMetrics = true): array
sort($keys);
$gauges = [];
foreach ($keys as $key) {
$raw = $this->redis->hGetAll(str_replace($this->redis->_prefix(''), '', $key));
$raw = $this->redis->hGetAll(ltrim($key, $this->redis->_prefix('')));
if (!isset($raw['__meta'])) {
continue;
}
Expand Down Expand Up @@ -648,7 +649,7 @@ private function collectCounters(bool $sortMetrics = true): array
sort($keys);
$counters = [];
foreach ($keys as $key) {
$raw = $this->redis->hGetAll(str_replace($this->redis->_prefix(''), '', $key));
$raw = $this->redis->hGetAll(ltrim($key, $this->redis->_prefix('')));
if (!isset($raw['__meta'])) {
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Prometheus/Storage/RedisNg.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ private function collectHistograms(): array
sort($keys);
$histograms = [];
foreach ($keys as $key) {
$raw = $this->redis->hGetAll(str_replace($this->redis->_prefix(''), '', $key));
$raw = $this->redis->hGetAll(ltrim($key, $this->redis->_prefix('')));
if (!isset($raw['__meta'])) {
continue;
}
Expand Down Expand Up @@ -597,7 +597,7 @@ private function collectGauges(bool $sortMetrics = true): array
sort($keys);
$gauges = [];
foreach ($keys as $key) {
$raw = $this->redis->hGetAll(str_replace($this->redis->_prefix(''), '', $key));
$raw = $this->redis->hGetAll(ltrim($key, $this->redis->_prefix('')));
if (!isset($raw['__meta'])) {
continue;
}
Expand Down Expand Up @@ -637,7 +637,7 @@ private function collectCounters(bool $sortMetrics = true): array
sort($keys);
$counters = [];
foreach ($keys as $key) {
$raw = $this->redis->hGetAll(str_replace($this->redis->_prefix(''), '', $key));
$raw = $this->redis->hGetAll(ltrim($key, $this->redis->_prefix('')));
if (!isset($raw['__meta'])) {
continue;
}
Expand Down