@@ -801,7 +801,46 @@ var comparer = cmp.Comparer(func(x, y model.Value) bool {
801
801
const fraction = 1.e-10 // 0.00000001%
802
802
return cmp .Equal (l , r , cmpopts .EquateNaNs (), cmpopts .EquateApprox (fraction , epsilon ))
803
803
}
804
+ // count_values returns a metrics with one label {"value": "1.012321"}
805
+ compareValueMetrics := func (l , r model.Metric ) (valueMetric bool , equals bool ) {
806
+ lLabels := model .LabelSet (l ).Clone ()
807
+ rLabels := model .LabelSet (r ).Clone ()
808
+ var (
809
+ lVal , rVal model.LabelValue
810
+ lFloat , rFloat float64
811
+ ok bool
812
+ err error
813
+ )
814
+
815
+ if lVal , ok = lLabels ["value" ]; ! ok {
816
+ return false , false
817
+ }
818
+
819
+ if rVal , ok = rLabels ["value" ]; ! ok {
820
+ return false , false
821
+ }
822
+
823
+ if lFloat , err = strconv .ParseFloat (string (lVal ), 64 ); err != nil {
824
+ return false , false
825
+ }
826
+ if rFloat , err = strconv .ParseFloat (string (rVal ), 64 ); err != nil {
827
+ return false , false
828
+ }
829
+
830
+ // Exclude the value label in comparison.
831
+ delete (lLabels , "value" )
832
+ delete (rLabels , "value" )
833
+
834
+ if ! lLabels .Equal (rLabels ) {
835
+ return false , false
836
+ }
837
+
838
+ return true , compareFloats (lFloat , rFloat )
839
+ }
804
840
compareMetrics := func (l , r model.Metric ) bool {
841
+ if valueMetric , equals := compareValueMetrics (l , r ); valueMetric {
842
+ return equals
843
+ }
805
844
return l .Equal (r )
806
845
}
807
846
0 commit comments