Skip to content

Commit 70f7983

Browse files
authored
Merge pull request #570 from pwschuurman/fix-e2e-test-ext4-flake
Fix e2e-test flakes for Ext4 counter
2 parents cbb029d + 84a54c5 commit 70f7983

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

test/e2e/metriconly/metrics_test.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ var _ = ginkgo.Describe("NPD should export Prometheus metrics.", func() {
129129

130130
ginkgo.It("NPD should update problem_counter{reason:Ext4Error} and problem_gauge{type:ReadonlyFilesystem}", func() {
131131
time.Sleep(5 * time.Second)
132-
assertMetricValueInBound(instance,
132+
assertMetricValueAtLeast(instance,
133133
"problem_counter", map[string]string{"reason": "Ext4Error"},
134-
1.0, 2.0)
134+
1.0)
135135
assertMetricValueInBound(instance,
136136
"problem_gauge", map[string]string{"reason": "FilesystemIsReadOnly", "type": "ReadonlyFilesystem"},
137137
1.0, 1.0)
@@ -202,13 +202,29 @@ func assertMetricExist(metricList []metrics.Float64MetricRepresentation, metricN
202202
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("Failed to find metric %q: %v.\nHere is all NPD exported metrics: %v", metricName, err, metricList))
203203
}
204204

205+
func assertValueAtLeast(metricName string, labels map[string]string, value float64, lowBound float64) {
206+
Expect(value).Should(BeNumerically(">=", lowBound),
207+
"Got value for metric %s with label %v: %v, expect at least %v.", metricName, labels, value, lowBound)
208+
}
209+
210+
func assertValueAtMost(metricName string, labels map[string]string, value float64, highBound float64) {
211+
Expect(value).Should(BeNumerically("<=", highBound),
212+
"Got value for metric %s with label %v: %v, expect at most %v.", metricName, labels, value, highBound)
213+
}
214+
205215
func assertMetricValueInBound(instance gce.Instance, metricName string, labels map[string]string, lowBound float64, highBound float64) {
206216
value, err := npd.FetchNPDMetric(instance, metricName, labels)
207217
if err != nil {
208218
ginkgo.Fail(fmt.Sprintf("Failed to find %s metric with label %v: %v", metricName, labels, err))
209219
}
210-
Expect(value).Should(BeNumerically(">=", lowBound),
211-
"Got value for metric %s with label %v: %v, expect at least %v.", metricName, labels, value, lowBound)
212-
Expect(value).Should(BeNumerically("<=", highBound),
213-
"Got value for metric %s with label %v: %v, expect at most %v.", metricName, labels, value, highBound)
220+
assertValueAtLeast(metricName, labels, value, lowBound)
221+
assertValueAtMost(metricName, labels, value, highBound)
222+
}
223+
224+
func assertMetricValueAtLeast(instance gce.Instance, metricName string, labels map[string]string, lowBound float64) {
225+
value, err := npd.FetchNPDMetric(instance, metricName, labels)
226+
if err != nil {
227+
ginkgo.Fail(fmt.Sprintf("Failed to find %s metric with label %v: %v", metricName, labels, err))
228+
}
229+
assertValueAtLeast(metricName, labels, value, lowBound)
214230
}

0 commit comments

Comments
 (0)