From 6be99dcf6fc52b71d675ab17588afbf6f28a4946 Mon Sep 17 00:00:00 2001 From: Thai Pham Date: Wed, 24 Oct 2018 15:19:55 +1100 Subject: [PATCH] Initialize data samples to empty arrays --- src/Prometheus/Storage/APC.php | 5 ++++- src/Prometheus/Storage/InMemory.php | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Prometheus/Storage/APC.php b/src/Prometheus/Storage/APC.php index b608e49..3340566 100644 --- a/src/Prometheus/Storage/APC.php +++ b/src/Prometheus/Storage/APC.php @@ -155,6 +155,7 @@ private function collectCounters() 'help' => $metaData['help'], 'type' => $metaData['type'], 'labelNames' => $metaData['labelNames'], + 'samples' => array(), ); foreach (new \APCUIterator('/^prom:counter:' . $metaData['name'] . ':.*:value/') as $value) { $parts = explode(':', $value['key']); @@ -185,6 +186,7 @@ private function collectGauges() 'help' => $metaData['help'], 'type' => $metaData['type'], 'labelNames' => $metaData['labelNames'], + 'samples' => array(), ); foreach (new \APCUIterator('/^prom:gauge:' . $metaData['name'] . ':.*:value/') as $value) { $parts = explode(':', $value['key']); @@ -216,7 +218,8 @@ private function collectHistograms() 'help' => $metaData['help'], 'type' => $metaData['type'], 'labelNames' => $metaData['labelNames'], - 'buckets' => $metaData['buckets'] + 'buckets' => $metaData['buckets'], + 'samples' => array(), ); // Add the Inf bucket so we can compute it later on diff --git a/src/Prometheus/Storage/InMemory.php b/src/Prometheus/Storage/InMemory.php index 313dbf4..7d5ac42 100644 --- a/src/Prometheus/Storage/InMemory.php +++ b/src/Prometheus/Storage/InMemory.php @@ -41,7 +41,8 @@ private function collectHistograms() 'help' => $metaData['help'], 'type' => $metaData['type'], 'labelNames' => $metaData['labelNames'], - 'buckets' => $metaData['buckets'] + 'buckets' => $metaData['buckets'], + 'samples' => array(), ]; // Add the Inf bucket so we can compute it later on @@ -114,6 +115,7 @@ private function internalCollect(array $metrics) 'help' => $metaData['help'], 'type' => $metaData['type'], 'labelNames' => $metaData['labelNames'], + 'samples' => array(), ]; foreach ($metric['samples'] as $key => $value) { $parts = explode(':', $key);