PromPHP / prometheus_client_php

Prometheus instrumentation library for PHP applications
https://prometheus.io/docs/concepts/metric_types/
Apache License 2.0
415 stars 91 forks source link

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

Closed ashandi closed 3 months ago

ashandi commented 4 months ago

These changes should fix the following issues: https://github.com/PromPHP/prometheus_client_php/issues/124 https://github.com/PromPHP/prometheus_client_php/issues/126

The main idea of this PL is following: when we use APCng with ttl 0 we have no guaranty that our data will not be removed from the cache. So the case when we can't find some metakey in the cache is common and we shouldn't rise the exception that stops completely the metrics collection process.

The same solution is already implemented in the Redis Storage: https://github.com/PromPHP/prometheus_client_php/blob/a09ea80ec1ec26dd1d4853e9af2a811e898dbfeb/src/Prometheus/Storage/Redis.php#L407-L409 https://github.com/PromPHP/prometheus_client_php/blob/a09ea80ec1ec26dd1d4853e9af2a811e898dbfeb/src/Prometheus/Storage/Redis.php#L503-L507 https://github.com/PromPHP/prometheus_client_php/blob/a09ea80ec1ec26dd1d4853e9af2a811e898dbfeb/src/Prometheus/Storage/Redis.php#L590-L592 https://github.com/PromPHP/prometheus_client_php/blob/a09ea80ec1ec26dd1d4853e9af2a811e898dbfeb/src/Prometheus/Storage/Redis.php#L626-L628

No meta data - no statistics.

Another problem here is that the metadata stored only once for a metric. So if we loose metadata from the cache, the metric will continue collecting but we lost access to it. So I made calling of storeMetadata function always, not only on the first writing of the metric. This function checks inside that metadata is already exists in the cache and will not do anything if it is.

ashandi commented 3 months ago

According to this, this exception shouldn't be caught if the apc.shm_size setting has enough value.