-
Notifications
You must be signed in to change notification settings - Fork 111
Description
Hello.
I use
- Symfony (7.1.9)
- artprima/prometheus-metrics-bundle (1.19.0)
- promphp/prometheus_client_php (2.13.1)
After implementing a custom MetricsCollector (to collect metrics in my services), my CLI commands console commands stopped starting with error: "APCu is not enabled".
class MetricsCollectorService implements MetricsCollectorInterface
{
use MetricsCollectorInitTrait;
public function someFoo(...): void
{
// some implementation
}
When the command is run while symfony dependency container initialization, it is checked whether apc is activated and if not, an exception falls on this line. https://github.com/PromPHP/prometheus_client_php/blob/main/src/Prometheus/Storage/APCng.php#L56
Prometheus\Exception\StorageException
APCu is not enabled
I understand that apc makes no sense in a cli environment, but in this case, console commands will crash.
I see several ways to solve the problem:
- `apc.enable_cli=1' - it will be pointless to collect metrics, but the console commands will work and it will fix my problem;
- Implement method
initin my collector and check in it whether the module (apc) is loaded, if it is not loaded, it quietly exits the method without throwing an exception.
The first option looks like it is more convenient and also consistent from the point of view of the code. I won't have to implement workarounds to check if the module is loaded.
Do you have a recommendation on which way would be preferable?
I think it makes sense to write about this situation in this place so that people don't forget about this problem. https://github.com/PromPHP/prometheus_client_php/blob/main/README.md?plain=1#L49
Thanks!