@@ -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.\n Here 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+
205215func 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