Skip to content

Commit 8c02c6d

Browse files
author
Xuewei Zhang
committed
Check metric sanity in e2e tests
1 parent 83b0927 commit 8c02c6d

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

test/e2e/metriconly/metrics_test.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,28 @@ var _ = ginkgo.Describe("NPD should export Prometheus metrics.", func() {
6868

6969
ginkgo.Context("On a clean node", func() {
7070

71-
ginkgo.It("NPD should export host_uptime metric", func() {
71+
ginkgo.It("NPD should export cpu/disk/host/memory metric", func() {
7272
err := npd.WaitForNPD(instance, []string{"host_uptime"}, 120)
7373
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Expect NPD to become ready in 120s, but hit error: %v", err))
7474

7575
gotMetrics, err := npd.FetchNPDMetrics(instance)
7676
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Error fetching NPD metrics: %v", err))
7777

78-
_, err = metrics.GetFloat64Metric(gotMetrics, "host_uptime", map[string]string{}, false)
79-
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Failed to find uptime metric: %v.\nHere 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)
8093
})
8194

8295
ginkgo.It("NPD should not report any problem", func() {
@@ -180,6 +193,11 @@ var _ = ginkgo.Describe("NPD should export Prometheus metrics.", func() {
180193
})
181194
})
182195

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.\nHere is all NPD exported metrics: %v", metricName, err, metricList))
199+
}
200+
183201
func assertMetricValueInBound(instance gce.Instance, metricName string, labels map[string]string, lowBound float64, highBound float64) {
184202
value, err := npd.FetchNPDMetric(instance, metricName, labels)
185203
if err != nil {

0 commit comments

Comments
 (0)