Skip to content

Commit 735ace7

Browse files
pluk77LKaemmerling
andauthored
Fix PHP notice: Undefined index: samples (#128)
* Fix PHP notice: Undefined index: samples collectHistograms() in the storage adapters does not define ['samples'] as the default array keys and as such a notice is thrown when the MetricFamilySamples::__construct($data) is called when no samples are available. * added space --------- Co-authored-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
1 parent 6f306e9 commit 735ace7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Prometheus/MetricFamilySamples.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@ public function __construct(array $data)
4040
$this->type = $data['type'];
4141
$this->help = $data['help'];
4242
$this->labelNames = $data['labelNames'];
43-
foreach ($data['samples'] as $sampleData) {
44-
$this->samples[] = new Sample($sampleData);
43+
if (isset($data['samples'])) {
44+
foreach ($data['samples'] as $sampleData) {
45+
$this->samples[] = new Sample($sampleData);
46+
}
4547
}
4648
}
4749

0 commit comments

Comments
 (0)