Skip to content

Commit 6a4746c

Browse files
authored
Merge branch 'main' into lock-free-gauge-set
2 parents b2a0cec + bf674d5 commit 6a4746c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/Prometheus/RenderTextFormat.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private function renderSample(MetricFamilySamples $metric, Sample $sample): stri
4040
{
4141
$labelNames = $metric->getLabelNames();
4242
if ($metric->hasLabelNames() || $sample->hasLabelNames()) {
43-
$escapedLabels = $this->escapeAllLabels($labelNames, $sample);
43+
$escapedLabels = $this->escapeAllLabels($metric, $labelNames, $sample);
4444
return $sample->getName() . '{' . implode(',', $escapedLabels) . '} ' . $sample->getValue();
4545
}
4646
return $sample->getName() . ' ' . $sample->getValue();
@@ -56,19 +56,20 @@ private function escapeLabelValue(string $v): string
5656
}
5757

5858
/**
59+
* @param MetricFamilySamples $metric
5960
* @param string[] $labelNames
6061
* @param Sample $sample
6162
*
6263
* @return string[]
6364
*/
64-
private function escapeAllLabels(array $labelNames, Sample $sample): array
65+
private function escapeAllLabels(MetricFamilySamples $metric, array $labelNames, Sample $sample): array
6566
{
6667
$escapedLabels = [];
6768

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

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

7475
foreach ($labels as $labelName => $labelValue) {

src/Prometheus/Storage/Redis.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,17 @@ private function connectToServer(): void
226226
$connection_successful = $this->redis->connect($this->options['host'], (int) $this->options['port'], (float) $this->options['timeout']);
227227
}
228228
if (!$connection_successful) {
229-
throw new StorageException("Can't connect to Redis server", 0);
229+
throw new StorageException(
230+
sprintf("Can't connect to Redis server. %s", $this->redis->getLastError()),
231+
0
232+
);
230233
}
231234
} catch (\RedisException $e) {
232-
throw new StorageException("Can't connect to Redis server", 0, $e);
235+
throw new StorageException(
236+
sprintf("Can't connect to Redis server. %s", $e->getMessage()),
237+
$e->getCode(),
238+
$e
239+
);
233240
}
234241
}
235242

0 commit comments

Comments
 (0)