File tree Expand file tree Collapse file tree 3 files changed +24
-6
lines changed
lib/private/OpenMetrics/Exporters
tests/lib/OpenMetrics/Exporters Expand file tree Collapse file tree 3 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -52,8 +52,8 @@ public function metrics(): Generator {
5252 yield new Metric (
5353 1 ,
5454 [
55- 'full version ' => $ this ->serverVersion ->getHumanVersion (),
56- 'major version ' => (string )$ this ->serverVersion ->getVersion ()[0 ],
55+ 'full_version ' => $ this ->serverVersion ->getHumanVersion (),
56+ 'major_version ' => (string )$ this ->serverVersion ->getVersion ()[0 ],
5757 'build ' => $ this ->serverVersion ->getBuild (),
5858 'installed ' => $ this ->systemConfig ->getValue ('installed ' , false ) ? '1 ' : '0 ' ,
5959 ],
Original file line number Diff line number Diff line change @@ -25,12 +25,30 @@ protected function setUp(): void {
2525 $ this ->metrics = iterator_to_array ($ this ->exporter ->metrics ());
2626 }
2727
28- public function testNotEmptyData () {
28+ public function testNotEmptyData (): void {
2929 $ this ->assertNotEmpty ($ this ->exporter ->name ());
3030 $ this ->assertNotEmpty ($ this ->metrics );
3131 }
3232
33- protected function assertLabelsAre (array $ expectedLabels ) {
33+ public function testValidNames (): void {
34+ $ labelNames = [];
35+ foreach ($ this ->metrics as $ metric ) {
36+ foreach ($ metric ->labels as $ label => $ value ) {
37+ $ labelNames [$ label ] = $ label ;
38+ }
39+ }
40+
41+ if (empty ($ labelNames )) {
42+ $ this ->expectNotToPerformAssertions ();
43+ return ;
44+ }
45+ foreach ($ labelNames as $ label ) {
46+ $ this ->assertMatchesRegularExpression ('/^[a-z_][a-z0-9_]*$/i ' , $ label );
47+ }
48+
49+ }
50+
51+ protected function assertLabelsAre (array $ expectedLabels ): void {
3452 $ foundLabels = [];
3553 foreach ($ this ->metrics as $ metric ) {
3654 $ foundLabels [] = $ metric ->labels ;
Original file line number Diff line number Diff line change @@ -33,8 +33,8 @@ public function testMetrics(): void {
3333 $ this ->assertCount (1 , $ this ->metrics );
3434 $ metric = array_pop ($ this ->metrics );
3535 $ this ->assertSame ([
36- 'full version ' => '33.13.17 Gold ' ,
37- 'major version ' => '33 ' ,
36+ 'full_version ' => '33.13.17 Gold ' ,
37+ 'major_version ' => '33 ' ,
3838 'build ' => 'dev ' ,
3939 'installed ' => '0 ' ,
4040 ], $ metric ->labels );
You can’t perform that action at this time.
0 commit comments