prometheus_client_php icon indicating copy to clipboard operation
prometheus_client_php copied to clipboard

array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements

Open FractalizeR opened this issue 1 year ago • 3 comments

If you first send a metric with two labels and later remove one of the labels, you get an exception in \Prometheus\RenderTextFormat::escapeAllLabels because two label arrays cannot be array_combine()'ed. You have to flush metric storage to make it working again.

FractalizeR avatar Mar 05 '24 15:03 FractalizeR

Yes I just got hit by the same problem. In my case redis storage, removing the keys of the modified metrics fixed the issue, but a pain to deal with.

stevenbrookes avatar Sep 05 '24 08:09 stevenbrookes

I think this cannot be fixed with the actual solution: The library does not store a relation between label and its value. Instead, it stores 2 separate (json) arrays for the labels and values.

I would suggest storing the labels on the actual value as label-key/label-value pair on the data value entry, as this would allow ignoring no-longer present label values.

bylexus avatar Nov 02 '25 16:11 bylexus

I managed to find a workaround for this by clearing metrics storage each time I change list of labels for any metric. Here is an example of Laravel command to clear this storage:

use Illuminate\Console\Command;
use Prometheus\CollectorRegistry;

class ClearStoredMetricsCommand extends Command
{
    protected $signature = 'prometheus:clear_stored_metrics';

    protected $description = 'Clears stored metrics from the storage (redis)';

    public function handle(CollectorRegistry $metricsCollectorRegistry): void
    {
        $metricsCollectorRegistry->wipeStorage();
        $this->info('Metrics cleared from storage');
    }
}

freezer278 avatar Nov 10 '25 13:11 freezer278