@@ -129,9 +129,9 @@ var _ = ginkgo.Describe("NPD should export Prometheus metrics.", func() {
129
129
130
130
ginkgo .It ("NPD should update problem_counter{reason:Ext4Error} and problem_gauge{type:ReadonlyFilesystem}" , func () {
131
131
time .Sleep (5 * time .Second )
132
- assertMetricValueInBound (instance ,
132
+ assertMetricValueAtLeast (instance ,
133
133
"problem_counter" , map [string ]string {"reason" : "Ext4Error" },
134
- 1.0 , 2.0 )
134
+ 1.0 )
135
135
assertMetricValueInBound (instance ,
136
136
"problem_gauge" , map [string ]string {"reason" : "FilesystemIsReadOnly" , "type" : "ReadonlyFilesystem" },
137
137
1.0 , 1.0 )
@@ -202,13 +202,29 @@ func assertMetricExist(metricList []metrics.Float64MetricRepresentation, metricN
202
202
Expect (err ).NotTo (HaveOccurred (), fmt .Sprintf ("Failed to find metric %q: %v.\n Here is all NPD exported metrics: %v" , metricName , err , metricList ))
203
203
}
204
204
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
+
205
215
func assertMetricValueInBound (instance gce.Instance , metricName string , labels map [string ]string , lowBound float64 , highBound float64 ) {
206
216
value , err := npd .FetchNPDMetric (instance , metricName , labels )
207
217
if err != nil {
208
218
ginkgo .Fail (fmt .Sprintf ("Failed to find %s metric with label %v: %v" , metricName , labels , err ))
209
219
}
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 )
214
230
}
0 commit comments