@@ -68,15 +68,28 @@ var _ = ginkgo.Describe("NPD should export Prometheus metrics.", func() {
68
68
69
69
ginkgo .Context ("On a clean node" , func () {
70
70
71
- ginkgo .It ("NPD should export host_uptime metric" , func () {
71
+ ginkgo .It ("NPD should export cpu/disk/host/memory metric" , func () {
72
72
err := npd .WaitForNPD (instance , []string {"host_uptime" }, 120 )
73
73
Expect (err ).NotTo (HaveOccurred (), fmt .Sprintf ("Expect NPD to become ready in 120s, but hit error: %v" , err ))
74
74
75
75
gotMetrics , err := npd .FetchNPDMetrics (instance )
76
76
Expect (err ).NotTo (HaveOccurred (), fmt .Sprintf ("Error fetching NPD metrics: %v" , err ))
77
77
78
- _ , err = metrics .GetFloat64Metric (gotMetrics , "host_uptime" , map [string ]string {}, false )
79
- Expect (err ).NotTo (HaveOccurred (), fmt .Sprintf ("Failed to find uptime metric: %v.\n Here is all NPD exported metrics: %v" , err , gotMetrics ))
78
+ assertMetricExist (gotMetrics , "cpu_runnable_task_count" , map [string ]string {}, true )
79
+ assertMetricExist (gotMetrics , "cpu_usage_time" , map [string ]string {}, false )
80
+ assertMetricExist (gotMetrics , "disk_operation_count" , map [string ]string {}, false )
81
+ assertMetricExist (gotMetrics , "disk_merged_operation_count" , map [string ]string {}, false )
82
+ assertMetricExist (gotMetrics , "disk_operation_bytes_count" , map [string ]string {}, false )
83
+ assertMetricExist (gotMetrics , "disk_operation_time" , map [string ]string {}, false )
84
+ assertMetricExist (gotMetrics , "disk_bytes_used" , map [string ]string {}, false )
85
+ assertMetricExist (gotMetrics , "disk_io_time" , map [string ]string {}, false )
86
+ assertMetricExist (gotMetrics , "disk_weighted_io" , map [string ]string {}, false )
87
+ assertMetricExist (gotMetrics , "memory_bytes_used" , map [string ]string {}, false )
88
+ assertMetricExist (gotMetrics , "memory_anonymous_used" , map [string ]string {}, false )
89
+ assertMetricExist (gotMetrics , "memory_page_cache_used" , map [string ]string {}, false )
90
+ assertMetricExist (gotMetrics , "memory_unevictable_used" , map [string ]string {}, true )
91
+ assertMetricExist (gotMetrics , "memory_dirty_used" , map [string ]string {}, false )
92
+ assertMetricExist (gotMetrics , "host_uptime" , map [string ]string {}, false )
80
93
})
81
94
82
95
ginkgo .It ("NPD should not report any problem" , func () {
@@ -180,6 +193,11 @@ var _ = ginkgo.Describe("NPD should export Prometheus metrics.", func() {
180
193
})
181
194
})
182
195
196
+ func assertMetricExist (metricList []metrics.Float64MetricRepresentation , metricName string , labels map [string ]string , strictLabelMatching bool ) {
197
+ _ , err := metrics .GetFloat64Metric (metricList , metricName , labels , strictLabelMatching )
198
+ Expect (err ).NotTo (HaveOccurred (), fmt .Sprintf ("Failed to find metric %q: %v.\n Here is all NPD exported metrics: %v" , metricName , err , metricList ))
199
+ }
200
+
183
201
func assertMetricValueInBound (instance gce.Instance , metricName string , labels map [string ]string , lowBound float64 , highBound float64 ) {
184
202
value , err := npd .FetchNPDMetric (instance , metricName , labels )
185
203
if err != nil {
0 commit comments