chore(metrics): harden Cached exporter

Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
This commit is contained in:
Benjamin Gaussorgues 2026-03-11 12:14:38 +01:00 committed by backportbot[bot]
parent acddfae356
commit 01ed0b9e54

View file

@ -13,6 +13,8 @@ use Generator;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\OpenMetrics\IMetricFamily;
use OCP\OpenMetrics\Metric;
use OCP\OpenMetrics\MetricValue;
use Override;
/**
@ -43,7 +45,12 @@ abstract class Cached implements IMetricFamily {
public function metrics(): Generator {
$cacheKey = static::class;
if ($data = $this->cache->get($cacheKey)) {
yield from unserialize($data);
yield from unserialize(
$data,
[
'allowed_classes' => [Metric::class, MetricValue::class],
],
);
return;
}