-
Notifications
You must be signed in to change notification settings - Fork 110
Description
Hello 👋
I was testing this library (through Artprima's SF bundle) and I discovered that during a new k8s deployment, some metrics can disappear (or be back).
According to my investigations, this is due to a race condition in the addItemToKey function:
prometheus_client_php/src/Prometheus/Storage/APCng.php
Lines 267 to 279 in 3e4811f
| private function addItemToKey(string $key, string $item): void | |
| { | |
| // Modify serialized array stored in $key | |
| $arr = apcu_fetch($key); | |
| if (false === $arr) { | |
| $arr = []; | |
| } | |
| $_item = $this->encodeLabelKey($item); | |
| if (!array_key_exists($_item, $arr)) { | |
| $arr[$_item] = 1; | |
| apcu_store($key, $arr, 0); | |
| } | |
| } |
It reads the (array) value stored in APC, modifies it and stores it back to APC. Unfortunately, during a new deployment (in k8s) with an empty APC, several items need to be stored in APC concurrently. Then, when trying to add some new label values from 2 distinct queries, there are some chances to override one of the 2 modifications.
I didn't find any easy workaround...
Anyway, thank you very much for your work on this library 🙇