array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements
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.
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.
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.
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');
}
}