Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions core/Controller/OpenMetricsController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
Expand Down Expand Up @@ -78,7 +79,16 @@ private function isRemoteAddressAllowed(): bool {

private function generate(): \Generator {
foreach ($this->exporterManager->export() as $family) {
yield $this->formatFamily($family);
try {
yield $this->formatFamily($family);
} catch (\Exception $e) {
// Skip family and return a valid result
$this->logger->error('Exception caught when exporting family {family}', [
'app' => 'metrics',
'family' => $family->name(),
'exception' => $e,
]);
}
}

$elapsed = (string)(microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']);
Expand Down Expand Up @@ -129,11 +139,7 @@ private function formatLabels(Metric $metric): string {
}

private function escapeString(string $string): string {
return json_encode(
$string,
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR,
1
);
return json_encode($string, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR, 1);
}

private function formatValue(Metric $metric): string {
Expand Down