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 crashing when rendering with integer labels #154

Open seifane-wise opened 3 months ago

seifane-wise commented 3 months ago

It seems that APCng is not handling integers labels very well.

It registers them correctly when incrementing a counter for example :

$counter = $registry->getOrRegisterCounter(..., ["path", "response_code"]);
$counter->incBy(1, ["a/path/", 200]);

This code was working fine under Redis.

However under APCng when rendering the metrics it seems that it is unable to fetch back the label values if they were all integers and this leads to a crash.

ErrorException: Undefined array key 1 in file /code/vendor/promphp/prometheus_client_php/src/Prometheus/Storage/APCng.php on line 443

#0 /code/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(255): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'Undefined array...', '/code/vendor/pr...', 443)
#1 /code/vendor/promphp/prometheus_client_php/src/Prometheus/Storage/APCng.php(443): Illuminate\Foundation\Bootstrap\HandleExceptions->Illuminate\Foundation\Bootstrap\{closure}(2, 'Undefined array...', '/code/vendor/pr...', 443)
#2 /code/vendor/promphp/prometheus_client_php/src/Prometheus/Storage/APCng.php(563): Prometheus\Storage\APCng->buildPermutationTree(Array, Array)
#3 /code/vendor/promphp/prometheus_client_php/src/Prometheus/Storage/APCng.php(477): Prometheus\Storage\APCng->getValues('counter', Array)
#4 /code/vendor/promphp/prometheus_client_php/src/Prometheus/Storage/APCng.php(80): Prometheus\Storage\APCng->collectCounters(true)
#5 /code/vendor/promphp/prometheus_client_php/src/Prometheus/CollectorRegistry.php(86): Prometheus\Storage\APCng->collect(true)

Happy to give more details to help resolve this if needed.