Skip to content

Commit

Permalink
acpng store fix - all data have fixed ttl of 0, so no global apcu set…
Browse files Browse the repository at this point in the history
…ting can make the metrics expire

Signed-off-by: Rastusik <[email protected]>
  • Loading branch information
Rastusik committed Nov 28, 2022
1 parent c475d3b commit d58d937
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/Prometheus/RenderTextFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ private function escapeAllLabels(array $labelNames, Sample $sample): array

$labels = array_combine(array_merge($labelNames, $sample->getLabelNames()), $sample->getLabelValues());

/** @phpstan-ignore-next-line */
if ($labels === false) {
throw new RuntimeException('Unable to combine labels.');
}
Expand Down
20 changes: 10 additions & 10 deletions src/Prometheus/Storage/APCng.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ 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);
apcu_add($sumKey, 0, 0);
$this->storeMetadata($data);
$this->storeLabelKeys($data);
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public function updateSummary(array $data): void
{
// store value key; store metadata & labels if new
$valueKey = $this->valueKey($data);
$new = apcu_add($valueKey, $this->encodeLabelValues($data['labelValues']));
$new = apcu_add($valueKey, $this->encodeLabelValues($data['labelValues']), 0);
if ($new) {
$this->storeMetadata($data, false);
$this->storeLabelKeys($data);
Expand Down Expand Up @@ -167,7 +167,7 @@ public function updateGauge(array $data): void
{
$valueKey = $this->valueKey($data);
if ($data['command'] === Adapter::COMMAND_SET) {
apcu_store($valueKey, $this->convertToIncrementalInteger($data['value']));
apcu_store($valueKey, $this->convertToIncrementalInteger($data['value']), 0);
$this->storeMetadata($data);
$this->storeLabelKeys($data);

Expand All @@ -177,7 +177,7 @@ public function updateGauge(array $data): void
$old = apcu_fetch($valueKey);

if ($old === false) {
apcu_add($valueKey, 0);
apcu_add($valueKey, 0, 0);
$this->storeMetadata($data);
$this->storeLabelKeys($data);
}
Expand All @@ -199,7 +199,7 @@ public function updateCounter(array $data): void
$old = apcu_fetch($valueKey);

if ($old === false) {
apcu_add($valueKey, 0);
apcu_add($valueKey, 0, 0);
$this->storeMetadata($data);
$this->storeLabelKeys($data);
}
Expand Down Expand Up @@ -253,7 +253,7 @@ private function addItemToKey(string $key, string $item): void
$_item = $this->encodeLabelKey($item);
if (!array_key_exists($_item, $arr)) {
$arr[$_item] = 1;
apcu_store($key, $arr);
apcu_store($key, $arr, 0);
}
}

Expand Down Expand Up @@ -335,7 +335,7 @@ private function scanAndBuildMetainfoCache(): array
$arr[$type][] = ['key' => $metaKey, 'value' => $metaInfo];
}

apcu_store($this->metainfoCacheKey, $arr);
apcu_store($this->metainfoCacheKey, $arr, 0);

return $arr;
}
Expand Down Expand Up @@ -892,17 +892,17 @@ private function storeMetadata(array $data, bool $encoded = true): void
$toStore = json_encode($metaData);
}

$stored = apcu_add($metaKey, $toStore);
$stored = apcu_add($metaKey, $toStore, 0);

if (!$stored) {
return;
}

apcu_add($this->metaInfoCounterKey, 0);
apcu_add($this->metaInfoCounterKey, 0, 0);
$counter = apcu_inc($this->metaInfoCounterKey);

$newCountedMetricKey = $this->metaCounterKey($counter);
apcu_store($newCountedMetricKey, $metaKey);
apcu_store($newCountedMetricKey, $metaKey, 0);
}

private function metaCounterKey(int $counter): string
Expand Down

0 comments on commit d58d937

Please sign in to comment.