Merge pull request #57764 from nextcloud/fix/openmetrics_labels

This commit is contained in:
Benjamin Gaussorgues 2026-01-25 22:51:25 +01:00 committed by GitHub
commit 8af5e06b62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 6 deletions

View file

@ -52,8 +52,8 @@ class InstanceInfo implements IMetricFamily {
yield new Metric(
1,
[
'full version' => $this->serverVersion->getHumanVersion(),
'major version' => (string)$this->serverVersion->getVersion()[0],
'full_version' => $this->serverVersion->getHumanVersion(),
'major_version' => (string)$this->serverVersion->getVersion()[0],
'build' => $this->serverVersion->getBuild(),
'installed' => $this->systemConfig->getValue('installed', false) ? '1' : '0',
],

View file

@ -25,12 +25,30 @@ abstract class ExporterTestCase extends TestCase {
$this->metrics = iterator_to_array($this->exporter->metrics());
}
public function testNotEmptyData() {
public function testNotEmptyData(): void {
$this->assertNotEmpty($this->exporter->name());
$this->assertNotEmpty($this->metrics);
}
protected function assertLabelsAre(array $expectedLabels) {
public function testValidNames(): void {
$labelNames = [];
foreach ($this->metrics as $metric) {
foreach ($metric->labels as $label => $value) {
$labelNames[$label] = $label;
}
}
if (empty($labelNames)) {
$this->expectNotToPerformAssertions();
return;
}
foreach ($labelNames as $label) {
$this->assertMatchesRegularExpression('/^[a-z_][a-z0-9_]*$/i', $label);
}
}
protected function assertLabelsAre(array $expectedLabels): void {
$foundLabels = [];
foreach ($this->metrics as $metric) {
$foundLabels[] = $metric->labels;

View file

@ -33,8 +33,8 @@ class InstanceInfoTest extends ExporterTestCase {
$this->assertCount(1, $this->metrics);
$metric = array_pop($this->metrics);
$this->assertSame([
'full version' => '33.13.17 Gold',
'major version' => '33',
'full_version' => '33.13.17 Gold',
'major_version' => '33',
'build' => 'dev',
'installed' => '0',
], $metric->labels);