-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,33 +118,37 @@ protected function collectHistograms(array $histograms): array | |
$data['samples'][] = [ | ||
'name' => $metaData['name'] . '_bucket', | ||
'labelNames' => ['le'], | ||
'labelValues' => array_merge($decodedLabelValues, | ||
[$bucket]), | ||
'labelValues' => array_merge( | ||
$decodedLabelValues, | ||
[$bucket] | ||
), | ||
'value' => $acc, | ||
]; | ||
} else { | ||
$acc += $histogramBuckets[$labelValues][$bucket]; | ||
$data['samples'][] = [ | ||
'name' => $metaData['name'].'_'.'bucket', | ||
'name' => $metaData['name'] . '_' . 'bucket', | ||
'labelNames' => ['le'], | ||
'labelValues' => array_merge($decodedLabelValues, | ||
[$bucket]), | ||
'labelValues' => array_merge( | ||
$decodedLabelValues, | ||
[$bucket] | ||
), | ||
'value' => $acc, | ||
]; | ||
} | ||
} | ||
|
||
// Add the count | ||
$data['samples'][] = [ | ||
'name' => $metaData['name'].'_count', | ||
'name' => $metaData['name'] . '_count', | ||
'labelNames' => [], | ||
'labelValues' => $decodedLabelValues, | ||
'value' => $acc, | ||
]; | ||
|
||
// Add the sum | ||
$data['samples'][] = [ | ||
'name' => $metaData['name'].'_sum', | ||
'name' => $metaData['name'] . '_sum', | ||
'labelNames' => [], | ||
'labelValues' => $decodedLabelValues, | ||
'value' => $histogramBuckets[$labelValues]['sum'], | ||
|
@@ -156,9 +160,11 @@ protected function collectHistograms(array $histograms): array | |
} | ||
|
||
/** | ||
* @param mixed[] $summary | ||
* | ||
* @return MetricFamilySamples[] | ||
*/ | ||
protected function collectSummaries($summaries): array | ||
protected function collectSummaries(array $summaries): array | ||
Check failure on line 167 in src/Prometheus/Storage/LaravelCacheAdapter.php
|
||
{ | ||
$math = new Math(); | ||
$output = []; | ||
|
@@ -174,17 +180,19 @@ protected function collectSummaries($summaries): array | |
'samples' => [], | ||
]; | ||
|
||
foreach ($summary['samples'] as $key => &$values) { | ||
foreach ($summary['samples'] as $key => $values) { | ||
$parts = explode(':', $key); | ||
$labelValues = $parts[2]; | ||
$decodedLabelValues = $this->decodeLabelValues($labelValues); | ||
|
||
// Remove old data | ||
$values = array_filter($values, | ||
$values = array_filter( | ||
$values, | ||
function (array $value) use ($data): bool { | ||
return time() - $value['time'] | ||
<= $data['maxAgeSeconds']; | ||
}); | ||
} | ||
); | ||
if (count($values) === 0) { | ||
unset($summary['samples'][$key]); | ||
continue; | ||
|
@@ -202,24 +210,28 @@ function (array $value) use ($data): bool { | |
$data['samples'][] = [ | ||
'name' => $metaData['name'], | ||
'labelNames' => ['quantile'], | ||
'labelValues' => array_merge($decodedLabelValues, | ||
[$quantile]), | ||
'value' => $math->quantile(array_column($values, | ||
'value'), $quantile), | ||
'labelValues' => array_merge( | ||
$decodedLabelValues, | ||
[$quantile] | ||
), | ||
'value' => $math->quantile(array_column( | ||
$values, | ||
'value' | ||
), $quantile), | ||
]; | ||
} | ||
|
||
// Add the count | ||
$data['samples'][] = [ | ||
'name' => $metaData['name'].'_count', | ||
'name' => $metaData['name'] . '_count', | ||
'labelNames' => [], | ||
'labelValues' => $decodedLabelValues, | ||
'value' => count($values), | ||
]; | ||
|
||
// Add the sum | ||
$data['samples'][] = [ | ||
'name' => $metaData['name'].'_sum', | ||
'name' => $metaData['name'] . '_sum', | ||
'labelNames' => [], | ||
'labelValues' => $decodedLabelValues, | ||
'value' => array_sum(array_column($values, 'value')), | ||
|
@@ -306,7 +318,8 @@ public function updateHistogram(array $data): void | |
} | ||
|
||
$bucketKey = $this->histogramBucketValueKey($data, $bucketToIncrease); | ||
if (array_key_exists($bucketKey, $histograms[$metaKey]['samples']) | ||
if ( | ||
array_key_exists($bucketKey, $histograms[$metaKey]['samples']) | ||
=== false | ||
) { | ||
$histograms[$metaKey]['samples'][$bucketKey] = 0; | ||
|
@@ -334,7 +347,8 @@ public function updateSummary(array $data): void | |
} | ||
|
||
$valueKey = $this->valueKey($data); | ||
if (array_key_exists($valueKey, $summaries[$metaKey]['samples']) | ||
if ( | ||
array_key_exists($valueKey, $summaries[$metaKey]['samples']) | ||
=== false | ||
) { | ||
$summaries[$metaKey]['samples'][$valueKey] = []; | ||
|
@@ -363,7 +377,8 @@ public function updateGauge(array $data): void | |
'samples' => [], | ||
]; | ||
} | ||
if (array_key_exists($valueKey, $gauges[$metaKey]['samples']) | ||
if ( | ||
array_key_exists($valueKey, $gauges[$metaKey]['samples']) | ||
=== false | ||
) { | ||
$gauges[$metaKey]['samples'][$valueKey] = 0; | ||
|
@@ -392,7 +407,8 @@ public function updateCounter(array $data): void | |
'samples' => [], | ||
]; | ||
} | ||
if (array_key_exists($valueKey, $counters[$metaKey]['samples']) | ||
if ( | ||
array_key_exists($valueKey, $counters[$metaKey]['samples']) | ||
=== false | ||
) { | ||
$counters[$metaKey]['samples'][$valueKey] = 0; | ||
|
@@ -469,8 +485,10 @@ protected function metaData(array $data): array | |
protected function sortSamples(array &$samples): void | ||
{ | ||
usort($samples, function ($a, $b): int { | ||
return strcmp(implode("", $a['labelValues']), | ||
implode("", $b['labelValues'])); | ||
return strcmp( | ||
implode("", $a['labelValues']), | ||
implode("", $b['labelValues']) | ||
); | ||
}); | ||
} | ||
|
||
|
@@ -511,7 +529,7 @@ protected function decodeLabelValues(string $values): array | |
/** | ||
* @param string $type | ||
* | ||
* @return array<int,array<string,mixed>> | ||
* @return mixed[] | ||
* @throws InvalidArgumentException | ||
*/ | ||
protected function fetch(string $type): array | ||
|
@@ -521,7 +539,7 @@ protected function fetch(string $type): array | |
|
||
/** | ||
* @param string $type | ||
* @param array<int,array<string,mixed>> $data | ||
* @param mixed[] $data | ||
* | ||
* @return void | ||
*/ | ||
|
@@ -532,6 +550,6 @@ protected function push(string $type, array $data): void | |
|
||
protected function cacheKey(string $type): string | ||
{ | ||
return static::CACHE_KEY_PREFIX.$type.static::CACHE_KEY_SUFFIX; | ||
return static::CACHE_KEY_PREFIX . $type . static::CACHE_KEY_SUFFIX; | ||
} | ||
} |