Merge pull request #10105 from prometheus/beorn7/histogram2

sparsehistogram: Address two TODOs
This commit is contained in:
Björn Rabenstein 2022-01-04 13:19:49 +01:00 committed by GitHub
commit 927557dc5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 6 deletions

View file

@ -470,7 +470,10 @@ type FloatBucket struct {
Lower, Upper float64
LowerInclusive, UpperInclusive bool
Count float64
Index int32 // Index within schema. To easily compare buckets that share the same schema.
// Index within schema. To easily compare buckets that share the same
// schema and sign (positive or negative). Irrelevant for the zero bucket.
Index int32
}
// String returns a string representation of a FloatBucket, using the usual
@ -686,7 +689,7 @@ func (r *allFloatBucketIterator) Next() bool {
LowerInclusive: true,
UpperInclusive: true,
Count: r.h.ZeroCount,
Index: math.MinInt32, // TODO(codesome): What is the index for this?
// Index is irrelevant for the zero bucket.
}
return true
}

View file

@ -15,7 +15,6 @@ package histogram
import (
"fmt"
"math"
"testing"
"github.com/stretchr/testify/require"
@ -973,7 +972,6 @@ func TestAllFloatBucketIterator(t *testing.T) {
LowerInclusive: true,
UpperInclusive: true,
Count: c.h.ZeroCount,
Index: math.MinInt32,
})
}
if c.includePos {

View file

@ -3002,8 +3002,8 @@ func TestSparseHistogram_Sum_AddOperator(t *testing.T) {
ts := int64(i+1) * int64(10*time.Minute/time.Millisecond)
app := test.Storage().Appender(context.TODO())
for idx, h := range c.histograms {
// TODO(codesome): Without h.Copy(), it was working weird. TSDB is keeping reference of last histogram. AppendHistogram should not take pointers!
lbls := labels.FromStrings("__name__", seriesName, "idx", fmt.Sprintf("%d", idx))
// Since we mutate h later, we need to create a copy here.
_, err = app.AppendHistogram(0, lbls, ts, h.Copy())
}
require.NoError(t, err)

View file

@ -234,7 +234,11 @@ type HistogramAppender interface {
// histograms in the same or later transactions. Returned reference
// numbers are ephemeral and may be rejected in calls to Append() at any
// point. Adding the sample via Append() returns a new reference number.
// If the reference is 0 it must not be used for caching.
// If the reference is 0, it must not be used for caching.
//
// For efficiency reasons, the histogram is passed as a
// pointer. AppendHistogram won't mutate the histogram, but in turn
// depends on the caller to not mutate it either.
AppendHistogram(ref SeriesRef, l labels.Labels, t int64, h *histogram.Histogram) (SeriesRef, error)
}