mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Fix NaN sum check in [Float]Histogram.Equals method
Signed-off-by: Linas Medziunas <linas.medziunas@gmail.com>
This commit is contained in:
parent
5d233df7ef
commit
cbd01fc296
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue