Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

APCng collect - do not throw exception if a metakey is missing #151

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/Prometheus/Storage/APCng.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public function updateHistogram(array $data): void
if ($old === false) {
// If sum does not exist, initialize it, store the metadata for the new histogram
apcu_add($sumKey, 0, 0);
$this->storeMetadata($data);
$this->storeLabelKeys($data);
}

$this->storeMetadata($data);
$this->incrementKeyWithValue($sumKey, $data['value']);

// Figure out in which bucket the observation belongs
Expand Down Expand Up @@ -139,9 +139,9 @@ public function updateSummary(array $data): void
$valueKey = $this->valueKey($data);
$new = apcu_add($valueKey, $this->encodeLabelValues($data['labelValues']), 0);
if ($new) {
$this->storeMetadata($data, false);
$this->storeLabelKeys($data);
}
$this->storeMetadata($data, false);
$sampleKeyPrefix = $valueKey . ':' . time();
$sampleCountKey = $sampleKeyPrefix . ':observations';

Expand Down Expand Up @@ -169,12 +169,12 @@ public function updateSummary(array $data): void
public function updateGauge(array $data): void
{
$valueKey = $this->valueKey($data);
$this->storeMetadata($data);
$old = apcu_fetch($valueKey);
if ($data['command'] === Adapter::COMMAND_SET) {
$new = $this->convertToIncrementalInteger($data['value']);
if ($old === false) {
apcu_store($valueKey, $new, 0);
$this->storeMetadata($data);
$this->storeLabelKeys($data);

return;
Expand All @@ -187,7 +187,6 @@ public function updateGauge(array $data): void
$old = apcu_fetch($valueKey);
if ($old === false) {
apcu_store($valueKey, $new, 0);
$this->storeMetadata($data);
$this->storeLabelKeys($data);

return;
Expand All @@ -199,7 +198,6 @@ public function updateGauge(array $data): void

if ($old === false) {
apcu_add($valueKey, 0, 0);
$this->storeMetadata($data);
$this->storeLabelKeys($data);
}

Expand All @@ -221,9 +219,9 @@ public function updateCounter(array $data): void

if ($old === false) {
apcu_add($valueKey, 0, 0);
$this->storeMetadata($data);
$this->storeLabelKeys($data);
}
$this->storeMetadata($data);

$this->incrementKeyWithValue($valueKey, $data['value']);
}
Expand Down Expand Up @@ -327,15 +325,11 @@ private function scanAndBuildMetainfoCache(): array
$metaKey = apcu_fetch($metaCounterKey);

if (!is_string($metaKey)) {
throw new UnexpectedValueException(
sprintf('Invalid meta counter key: %s', $metaCounterKey)
);
continue;
}

if (preg_match('/' . $this->prometheusPrefix . ':([^:]+):.*:meta/', $metaKey, $matches) !== 1) {
throw new UnexpectedValueException(
sprintf('Invalid meta key: %s', $metaKey)
);
continue;
}

$type = $matches[1];
Expand All @@ -348,9 +342,7 @@ private function scanAndBuildMetainfoCache(): array
$metaInfo = apcu_fetch($metaKey);

if ($metaInfo === false) {
throw new UnexpectedValueException(
sprintf('Meta info missing for meta key: %s', $metaKey)
);
continue;
}

$arr[$type][] = ['key' => $metaKey, 'value' => $metaInfo];
Expand Down