Skip to content

Commit

Permalink
Merge branch 'main' into lock-free-gauge-set
Browse files Browse the repository at this point in the history
  • Loading branch information
LKaemmerling authored Nov 24, 2023
2 parents b2a0cec + bf674d5 commit 6a4746c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/Prometheus/RenderTextFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private function renderSample(MetricFamilySamples $metric, Sample $sample): stri
{
$labelNames = $metric->getLabelNames();
if ($metric->hasLabelNames() || $sample->hasLabelNames()) {
$escapedLabels = $this->escapeAllLabels($labelNames, $sample);
$escapedLabels = $this->escapeAllLabels($metric, $labelNames, $sample);
return $sample->getName() . '{' . implode(',', $escapedLabels) . '} ' . $sample->getValue();
}
return $sample->getName() . ' ' . $sample->getValue();
Expand All @@ -56,19 +56,20 @@ private function escapeLabelValue(string $v): string
}

/**
* @param MetricFamilySamples $metric
* @param string[] $labelNames
* @param Sample $sample
*
* @return string[]
*/
private function escapeAllLabels(array $labelNames, Sample $sample): array
private function escapeAllLabels(MetricFamilySamples $metric, array $labelNames, Sample $sample): array
{
$escapedLabels = [];

$labels = array_combine(array_merge($labelNames, $sample->getLabelNames()), $sample->getLabelValues());

if ($labels === false) {
throw new RuntimeException('Unable to combine labels.');
throw new RuntimeException('Unable to combine labels for metric named ' . $metric->getName());
}

foreach ($labels as $labelName => $labelValue) {
Expand Down
11 changes: 9 additions & 2 deletions src/Prometheus/Storage/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,17 @@ private function connectToServer(): void
$connection_successful = $this->redis->connect($this->options['host'], (int) $this->options['port'], (float) $this->options['timeout']);
}
if (!$connection_successful) {
throw new StorageException("Can't connect to Redis server", 0);
throw new StorageException(
sprintf("Can't connect to Redis server. %s", $this->redis->getLastError()),
0
);
}
} catch (\RedisException $e) {
throw new StorageException("Can't connect to Redis server", 0, $e);
throw new StorageException(
sprintf("Can't connect to Redis server. %s", $e->getMessage()),
$e->getCode(),
$e
);
}
}

Expand Down

0 comments on commit 6a4746c

Please sign in to comment.