diff --git a/model/histogram/float_histogram.go b/model/histogram/float_histogram.go index 41873278cb..6272b66831 100644 --- a/model/histogram/float_histogram.go +++ b/model/histogram/float_histogram.go @@ -313,7 +313,8 @@ func (h *FloatHistogram) Equals(h2 *FloatHistogram) bool { } if h.Schema != h2.Schema || h.ZeroThreshold != h2.ZeroThreshold || - h.ZeroCount != h2.ZeroCount || h.Count != h2.Count || h.Sum != h2.Sum { + h.ZeroCount != h2.ZeroCount || h.Count != h2.Count || + math.Float64bits(h.Sum) != math.Float64bits(h2.Sum) { return false } diff --git a/model/histogram/histogram.go b/model/histogram/histogram.go index 6d425307c5..31c3ce9fe4 100644 --- a/model/histogram/histogram.go +++ b/model/histogram/histogram.go @@ -178,7 +178,8 @@ func (h *Histogram) Equals(h2 *Histogram) bool { } if h.Schema != h2.Schema || h.ZeroThreshold != h2.ZeroThreshold || - h.ZeroCount != h2.ZeroCount || h.Count != h2.Count || h.Sum != h2.Sum { + h.ZeroCount != h2.ZeroCount || h.Count != h2.Count || + math.Float64bits(h.Sum) != math.Float64bits(h2.Sum) { return false } diff --git a/model/histogram/histogram_test.go b/model/histogram/histogram_test.go index 3975353d2a..2af90501e5 100644 --- a/model/histogram/histogram_test.go +++ b/model/histogram/histogram_test.go @@ -19,6 +19,8 @@ import ( "testing" "github.com/stretchr/testify/require" + + "github.com/prometheus/prometheus/model/value" ) func TestHistogramString(t *testing.T) { @@ -411,8 +413,8 @@ func TestHistogramToFloat(t *testing.T) { require.Equal(t, h.String(), fh.String()) } -// TestHistogramMatches tests both Histogram and FloatHistogram. -func TestHistogramMatches(t *testing.T) { +// TestHistogramEquals tests both Histogram and FloatHistogram. +func TestHistogramEquals(t *testing.T) { h1 := Histogram{ Schema: 3, Count: 61, @@ -537,6 +539,12 @@ func TestHistogramMatches(t *testing.T) { }) h2.NegativeBuckets = append(h2.NegativeBuckets, 1) notEquals(h1, *h2) + + // StaleNaN. + h2 = h1.Copy() + h2.Sum = math.Float64frombits(value.StaleNaN) + notEquals(h1, *h2) + equals(*h2, *h2) } func TestHistogramCompact(t *testing.T) {