@@ -10,6 +10,7 @@ import (
10
10
"os"
11
11
"path"
12
12
"path/filepath"
13
+ "regexp"
13
14
"sort"
14
15
"strconv"
15
16
"strings"
@@ -970,15 +971,34 @@ var comparer = cmp.Comparer(func(x, y model.Value) bool {
970
971
return l == r || (compareFloats (float64 (l .Count ), float64 (r .Count )) && compareFloats (float64 (l .Sum ), float64 (r .Sum )) && compareHistogramBuckets (l .Buckets , r .Buckets ))
971
972
}
972
973
974
+ fetchValuesFromNH := func (nhString string ) []float64 {
975
+ // Regex to match float numbers
976
+ re := regexp .MustCompile (`-?\d+(\.\d+)?` )
977
+
978
+ matches := re .FindAllString (nhString , - 1 )
979
+
980
+ var ret []float64
981
+ for _ , match := range matches {
982
+ f , err := strconv .ParseFloat (match , 64 )
983
+ if err != nil {
984
+ continue
985
+ }
986
+ ret = append (ret , f )
987
+ }
988
+ return ret
989
+ }
990
+
973
991
// count_values returns a metrics with one label {"value": "1.012321"}
992
+ // or {"value": "{count:114, sum:226.93333333333334, [-4,-2.82842712474619):12.333333333333332, [-2.82842712474619,-2):12.333333333333332, [-1.414213562373095,-1):13.333333333333334, [-1,-0.7071067811865475):12.333333333333332, [-0.001,0.001]:13.333333333333334, (0.7071067811865475,1]:12.333333333333332, (1,1.414213562373095]:13.333333333333334, (2,2.82842712474619]:12.333333333333332, (2.82842712474619,4]:12.333333333333332}"}}
974
993
compareValueMetrics := func (l , r model.Metric ) (valueMetric bool , equals bool ) {
975
994
lLabels := model .LabelSet (l ).Clone ()
976
995
rLabels := model .LabelSet (r ).Clone ()
977
996
var (
978
- lVal , rVal model.LabelValue
979
- lFloat , rFloat float64
980
- ok bool
981
- err error
997
+ lVal , rVal model.LabelValue
998
+ lFloats , rFloats []float64 // when NH, these contain float64 values in NH
999
+ lFloat , rFloat float64
1000
+ ok bool
1001
+ err error
982
1002
)
983
1003
984
1004
if lVal , ok = lLabels ["value" ]; ! ok {
@@ -989,6 +1009,24 @@ var comparer = cmp.Comparer(func(x, y model.Value) bool {
989
1009
return false , false
990
1010
}
991
1011
1012
+ if strings .Contains (string (lVal ), "count" ) && strings .Contains (string (rVal ), "count" ) {
1013
+ // the values are histograms
1014
+ lFloats = fetchValuesFromNH (string (lVal ))
1015
+ rFloats = fetchValuesFromNH (string (rVal ))
1016
+
1017
+ if len (lFloats ) != len (rFloats ) {
1018
+ return true , false
1019
+ }
1020
+
1021
+ for i := 0 ; i < len (lFloats ); i ++ {
1022
+ if ! compareFloats (lFloats [i ], rFloats [i ]) {
1023
+ return true , false
1024
+ }
1025
+ }
1026
+
1027
+ return true , true
1028
+ }
1029
+
992
1030
if lFloat , err = strconv .ParseFloat (string (lVal ), 64 ); err != nil {
993
1031
return false , false
994
1032
}
0 commit comments