@@ -33,14 +33,33 @@ func TestMetricsServerServesCustomMetrics(t *testing.T) {
33
33
"total_central_reconcilations" ,
34
34
"total_central_reconcilation_errors" ,
35
35
"active_central_reconcilations" ,
36
- "total_centrals" ,
37
36
}
38
37
39
38
for _ , key := range expectedKeys {
40
39
assert .Containsf (t , metrics , metricsPrefix + key , "expected metrics to contain %s but it did not: %v" , key , metrics )
41
40
}
42
41
}
43
42
43
+ func TestMetricsServerServesTotalCentralsMetric (t * testing.T ) {
44
+ server := NewMetricsServer (":8081" )
45
+
46
+ MetricsInstance ().SetTotalCentrals (1 , "ready" )
47
+
48
+ rec := httptest .NewRecorder ()
49
+ req , err := http .NewRequest (http .MethodGet , "/metrics" , nil )
50
+ require .NoError (t , err , "failed creating metrics requests" )
51
+
52
+ server .Handler .ServeHTTP (rec , req )
53
+ require .Equal (t , http .StatusOK , rec .Code , "status code should be OK" )
54
+
55
+ promParser := expfmt.TextParser {}
56
+ metrics , err := promParser .TextToMetricFamilies (rec .Body )
57
+ require .NoError (t , err , "failed parsing metrics file" )
58
+
59
+ key := metricsPrefix + "total_centrals"
60
+ assert .Containsf (t , metrics , key , "expected metrics to contain %s but it did not: %v" , key , metrics )
61
+ }
62
+
44
63
func serveMetrics (t * testing.T , customMetrics * Metrics ) metricResponse {
45
64
rec := httptest .NewRecorder ()
46
65
req , err := http .NewRequest (http .MethodGet , "/metrics" , nil )
0 commit comments