Skip to content

Commit

Permalink
Fix PHP notice: Undefined index: samples (#128)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
pluk77 and LKaemmerling authored Nov 6, 2023
1 parent 6f306e9 commit 735ace7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Prometheus/MetricFamilySamples.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public function __construct(array $data)
$this->type = $data['type'];
$this->help = $data['help'];
$this->labelNames = $data['labelNames'];
foreach ($data['samples'] as $sampleData) {
$this->samples[] = new Sample($sampleData);
if (isset($data['samples'])) {
foreach ($data['samples'] as $sampleData) {
$this->samples[] = new Sample($sampleData);
}
}
}

Expand Down

0 comments on commit 735ace7

Please sign in to comment.