Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions lib/private/OpenMetrics/Exporters/InstanceInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function metrics(): Generator {
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',
],
Expand Down
22 changes: 20 additions & 2 deletions tests/lib/OpenMetrics/Exporters/ExporterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,30 @@ protected function setUp(): void {
$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;
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/OpenMetrics/Exporters/InstanceInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function testMetrics(): void {
$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);
Expand Down
Loading