mirror of
https://github.com/prometheus/prometheus.git
synced 2026-02-03 20:39:32 -05:00
fix(tsdb): remove useless code
We are calculating histogram counter reset at the beginning for chunks
however, we always throw away the answer:
076369fad0/tsdb/chunkenc/histogram_meta.go (L481)
This PR removes this code and updates dependencies.
Related to
https://github.com/prometheus/prometheus/issues/15346
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
This commit is contained in:
parent
076369fad0
commit
67829c7fc5
15 changed files with 100 additions and 263 deletions
|
|
@ -3740,12 +3740,12 @@ func TestHistogramRateWithFloatStaleness(t *testing.T) {
|
|||
recoded bool
|
||||
)
|
||||
|
||||
newc, recoded, app, err = app.AppendHistogram(nil, 0, 0, h1.Copy(), false)
|
||||
newc, recoded, app, err = app.AppendHistogram(0, 0, h1.Copy(), false)
|
||||
require.NoError(t, err)
|
||||
require.False(t, recoded)
|
||||
require.Nil(t, newc)
|
||||
|
||||
newc, recoded, _, err = app.AppendHistogram(nil, 0, 10, h1.Copy(), false)
|
||||
newc, recoded, _, err = app.AppendHistogram(0, 10, h1.Copy(), false)
|
||||
require.NoError(t, err)
|
||||
require.False(t, recoded)
|
||||
require.Nil(t, newc)
|
||||
|
|
@ -3766,12 +3766,12 @@ func TestHistogramRateWithFloatStaleness(t *testing.T) {
|
|||
app, err = c3.Appender()
|
||||
require.NoError(t, err)
|
||||
|
||||
newc, recoded, app, err = app.AppendHistogram(nil, 0, 30, h2.Copy(), false)
|
||||
newc, recoded, app, err = app.AppendHistogram(0, 30, h2.Copy(), false)
|
||||
require.NoError(t, err)
|
||||
require.False(t, recoded)
|
||||
require.Nil(t, newc)
|
||||
|
||||
newc, recoded, _, err = app.AppendHistogram(nil, 0, 40, h2.Copy(), false)
|
||||
newc, recoded, _, err = app.AppendHistogram(0, 40, h2.Copy(), false)
|
||||
require.NoError(t, err)
|
||||
require.False(t, recoded)
|
||||
require.Nil(t, newc)
|
||||
|
|
|
|||
|
|
@ -373,7 +373,7 @@ func (s *seriesToChunkEncoder) Iterator(it chunks.Iterator) chunks.Iterator {
|
|||
case chunkenc.ValHistogram:
|
||||
t, h = seriesIter.AtHistogram(nil)
|
||||
st = seriesIter.AtST()
|
||||
newChk, recoded, app, err = app.AppendHistogram(nil, st, t, h, false)
|
||||
newChk, recoded, app, err = app.AppendHistogram(st, t, h, false)
|
||||
if err != nil {
|
||||
return errChunksIterator{err: err}
|
||||
}
|
||||
|
|
@ -389,7 +389,7 @@ func (s *seriesToChunkEncoder) Iterator(it chunks.Iterator) chunks.Iterator {
|
|||
case chunkenc.ValFloatHistogram:
|
||||
t, fh = seriesIter.AtFloatHistogram(nil)
|
||||
st = seriesIter.AtST()
|
||||
newChk, recoded, app, err = app.AppendFloatHistogram(nil, st, t, fh, false)
|
||||
newChk, recoded, app, err = app.AppendFloatHistogram(st, t, fh, false)
|
||||
if err != nil {
|
||||
return errChunksIterator{err: err}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,8 +114,8 @@ type Appender interface {
|
|||
// The returned bool isRecoded can be used to distinguish between the new Chunk c being a completely new Chunk
|
||||
// or the current Chunk recoded to a new Chunk.
|
||||
// The Appender app that can be used for the next append is always returned.
|
||||
AppendHistogram(prev *HistogramAppender, st, t int64, h *histogram.Histogram, appendOnly bool) (c Chunk, isRecoded bool, app Appender, err error)
|
||||
AppendFloatHistogram(prev *FloatHistogramAppender, st, t int64, h *histogram.FloatHistogram, appendOnly bool) (c Chunk, isRecoded bool, app Appender, err error)
|
||||
AppendHistogram(st, t int64, h *histogram.Histogram, appendOnly bool) (c Chunk, isRecoded bool, app Appender, err error)
|
||||
AppendFloatHistogram(st, t int64, h *histogram.FloatHistogram, appendOnly bool) (c Chunk, isRecoded bool, app Appender, err error)
|
||||
}
|
||||
|
||||
// Iterator is a simple iterator that can only get the next value.
|
||||
|
|
|
|||
|
|
@ -682,31 +682,21 @@ func (*FloatHistogramAppender) recodeHistogram(
|
|||
}
|
||||
}
|
||||
|
||||
func (*FloatHistogramAppender) AppendHistogram(*HistogramAppender, int64, int64, *histogram.Histogram, bool) (Chunk, bool, Appender, error) {
|
||||
func (*FloatHistogramAppender) AppendHistogram(int64, int64, *histogram.Histogram, bool) (Chunk, bool, Appender, error) {
|
||||
panic("appended a histogram sample to a float histogram chunk")
|
||||
}
|
||||
|
||||
func (a *FloatHistogramAppender) AppendFloatHistogram(prev *FloatHistogramAppender, _, t int64, h *histogram.FloatHistogram, appendOnly bool) (Chunk, bool, Appender, error) {
|
||||
func (a *FloatHistogramAppender) AppendFloatHistogram(_, t int64, h *histogram.FloatHistogram, appendOnly bool) (Chunk, bool, Appender, error) {
|
||||
if a.NumSamples() == 0 {
|
||||
a.appendFloatHistogram(t, h)
|
||||
if h.CounterResetHint == histogram.GaugeType {
|
||||
switch h.CounterResetHint {
|
||||
case histogram.GaugeType:
|
||||
a.setCounterResetHeader(GaugeType)
|
||||
return nil, false, a, nil
|
||||
case histogram.CounterReset:
|
||||
a.setCounterResetHeader(CounterReset)
|
||||
}
|
||||
|
||||
switch {
|
||||
case h.CounterResetHint == histogram.CounterReset:
|
||||
// Always honor the explicit counter reset hint.
|
||||
a.setCounterResetHeader(CounterReset)
|
||||
case prev != nil:
|
||||
// This is a new chunk, but continued from a previous one. We need to calculate the reset header unless already set.
|
||||
_, _, _, _, _, counterReset := prev.appendable(h)
|
||||
if counterReset {
|
||||
a.setCounterResetHeader(CounterReset)
|
||||
} else {
|
||||
a.setCounterResetHeader(NotCounterReset)
|
||||
}
|
||||
}
|
||||
return nil, false, a, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ func TestFirstFloatHistogramExplicitCounterReset(t *testing.T) {
|
|||
chk := NewFloatHistogramChunk()
|
||||
app, err := chk.Appender()
|
||||
require.NoError(t, err)
|
||||
newChk, recoded, newApp, err := app.AppendFloatHistogram(nil, 0, 0, h, false)
|
||||
newChk, recoded, newApp, err := app.AppendFloatHistogram(0, 0, h, false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, newChk)
|
||||
require.False(t, recoded)
|
||||
|
|
@ -101,7 +101,7 @@ func TestFloatHistogramChunkSameBuckets(t *testing.T) {
|
|||
},
|
||||
NegativeBuckets: []int64{2, 1, -1, -1}, // counts: 2, 3, 2, 1 (total 8)
|
||||
}
|
||||
chk, _, app, err := app.AppendFloatHistogram(nil, 0, ts, h.ToFloat(nil), false)
|
||||
chk, _, app, err := app.AppendFloatHistogram(0, ts, h.ToFloat(nil), false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
exp = append(exp, floatResult{t: ts, h: h.ToFloat(nil)})
|
||||
|
|
@ -115,7 +115,7 @@ func TestFloatHistogramChunkSameBuckets(t *testing.T) {
|
|||
h.Sum = 24.4
|
||||
h.PositiveBuckets = []int64{5, -2, 1, -2} // counts: 5, 3, 4, 2 (total 14)
|
||||
h.NegativeBuckets = []int64{4, -1, 1, -1} // counts: 4, 3, 4, 4 (total 15)
|
||||
chk, _, _, err = app.AppendFloatHistogram(nil, 0, ts, h.ToFloat(nil), false)
|
||||
chk, _, _, err = app.AppendFloatHistogram(0, ts, h.ToFloat(nil), false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
expH := h.ToFloat(nil)
|
||||
|
|
@ -134,7 +134,7 @@ func TestFloatHistogramChunkSameBuckets(t *testing.T) {
|
|||
h.Sum = 24.4
|
||||
h.PositiveBuckets = []int64{6, 1, -3, 6} // counts: 6, 7, 4, 10 (total 27)
|
||||
h.NegativeBuckets = []int64{5, 1, -2, 3} // counts: 5, 6, 4, 7 (total 22)
|
||||
chk, _, _, err = app.AppendFloatHistogram(nil, 0, ts, h.ToFloat(nil), false)
|
||||
chk, _, _, err = app.AppendFloatHistogram(0, ts, h.ToFloat(nil), false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
expH = h.ToFloat(nil)
|
||||
|
|
@ -224,7 +224,7 @@ func TestFloatHistogramChunkBucketChanges(t *testing.T) {
|
|||
NegativeBuckets: []int64{1},
|
||||
}
|
||||
|
||||
chk, _, app, err := app.AppendFloatHistogram(nil, 0, ts1, h1.ToFloat(nil), false)
|
||||
chk, _, app, err := app.AppendFloatHistogram(0, ts1, h1.ToFloat(nil), false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
require.Equal(t, 1, c.NumSamples())
|
||||
|
|
@ -260,7 +260,7 @@ func TestFloatHistogramChunkBucketChanges(t *testing.T) {
|
|||
require.True(t, ok) // Only new buckets came in.
|
||||
require.False(t, cr)
|
||||
c, app = hApp.recode(posInterjections, negInterjections, h2.PositiveSpans, h2.NegativeSpans)
|
||||
chk, _, _, err = app.AppendFloatHistogram(nil, 0, ts2, h2.ToFloat(nil), false)
|
||||
chk, _, _, err = app.AppendFloatHistogram(0, ts2, h2.ToFloat(nil), false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
require.Equal(t, 2, c.NumSamples())
|
||||
|
|
@ -330,7 +330,7 @@ func TestFloatHistogramChunkAppendable(t *testing.T) {
|
|||
|
||||
ts := int64(1234567890)
|
||||
|
||||
chk, _, app, err := app.AppendFloatHistogram(nil, 0, ts, h.Copy(), false)
|
||||
chk, _, app, err := app.AppendFloatHistogram(0, ts, h.Copy(), false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
require.Equal(t, 1, c.NumSamples())
|
||||
|
|
@ -550,68 +550,6 @@ func TestFloatHistogramChunkAppendable(t *testing.T) {
|
|||
assertNewFloatHistogramChunkOnAppend(t, c, hApp, ts+1, h2, CounterReset, histogram.UnknownCounterReset)
|
||||
}
|
||||
|
||||
{ // Start new chunk explicitly, and append a new histogram that is considered appendable to the previous chunk.
|
||||
_, hApp, ts, h1 := setup(eh)
|
||||
h2 := h1.Copy() // Identity is appendable.
|
||||
|
||||
nextChunk := NewFloatHistogramChunk()
|
||||
app, err := nextChunk.Appender()
|
||||
require.NoError(t, err)
|
||||
newChunk, recoded, newApp, err := app.AppendFloatHistogram(hApp, 0, ts+1, h2, false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, newChunk)
|
||||
require.False(t, recoded)
|
||||
require.Equal(t, app, newApp)
|
||||
assertSampleCount(t, nextChunk, 1, ValFloatHistogram)
|
||||
require.Equal(t, NotCounterReset, nextChunk.GetCounterResetHeader())
|
||||
assertFirstFloatHistogramSampleHint(t, nextChunk, histogram.UnknownCounterReset)
|
||||
}
|
||||
|
||||
{ // Start new chunk explicitly, and append a new histogram that is not considered appendable to the previous chunk.
|
||||
_, hApp, ts, h1 := setup(eh)
|
||||
h2 := h1.Copy()
|
||||
h2.Count-- // Make this not appendable due to counter reset.
|
||||
|
||||
nextChunk := NewFloatHistogramChunk()
|
||||
app, err := nextChunk.Appender()
|
||||
require.NoError(t, err)
|
||||
newChunk, recoded, newApp, err := app.AppendFloatHistogram(hApp, 0, ts+1, h2, false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, newChunk)
|
||||
require.False(t, recoded)
|
||||
require.Equal(t, app, newApp)
|
||||
assertSampleCount(t, nextChunk, 1, ValFloatHistogram)
|
||||
require.Equal(t, CounterReset, nextChunk.GetCounterResetHeader())
|
||||
assertFirstFloatHistogramSampleHint(t, nextChunk, histogram.UnknownCounterReset)
|
||||
}
|
||||
|
||||
{ // Start new chunk explicitly, and append a new histogram that would need recoding if we added it to the chunk.
|
||||
_, hApp, ts, h1 := setup(eh)
|
||||
h2 := h1.Copy()
|
||||
h2.PositiveSpans = []histogram.Span{
|
||||
{Offset: 0, Length: 3},
|
||||
{Offset: 1, Length: 1},
|
||||
{Offset: 1, Length: 4},
|
||||
{Offset: 3, Length: 3},
|
||||
}
|
||||
h2.Count += 9
|
||||
h2.ZeroCount++
|
||||
h2.Sum = 30
|
||||
h2.PositiveBuckets = []float64{7, 5, 1, 3, 1, 0, 2, 5, 5, 0, 1}
|
||||
|
||||
nextChunk := NewFloatHistogramChunk()
|
||||
app, err := nextChunk.Appender()
|
||||
require.NoError(t, err)
|
||||
newChunk, recoded, newApp, err := app.AppendFloatHistogram(hApp, 0, ts+1, h2, false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, newChunk)
|
||||
require.False(t, recoded)
|
||||
require.Equal(t, app, newApp)
|
||||
assertSampleCount(t, nextChunk, 1, ValFloatHistogram)
|
||||
require.Equal(t, NotCounterReset, nextChunk.GetCounterResetHeader())
|
||||
assertFirstFloatHistogramSampleHint(t, nextChunk, histogram.UnknownCounterReset)
|
||||
}
|
||||
|
||||
{
|
||||
// Start a new chunk with a histogram that has an empty bucket.
|
||||
// Add a histogram that has the same bucket missing.
|
||||
|
|
@ -717,7 +655,7 @@ func TestFloatHistogramChunkAppendable(t *testing.T) {
|
|||
|
||||
func assertNewFloatHistogramChunkOnAppend(t *testing.T, oldChunk Chunk, hApp *FloatHistogramAppender, ts int64, h *histogram.FloatHistogram, expectHeader CounterResetHeader, expectHint histogram.CounterResetHint) {
|
||||
oldChunkBytes := oldChunk.Bytes()
|
||||
newChunk, recoded, newAppender, err := hApp.AppendFloatHistogram(nil, 0, ts, h, false)
|
||||
newChunk, recoded, newAppender, err := hApp.AppendFloatHistogram(0, ts, h, false)
|
||||
require.Equal(t, oldChunkBytes, oldChunk.Bytes()) // Sanity check that previous chunk is untouched.
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, newChunk)
|
||||
|
|
@ -732,7 +670,7 @@ func assertNewFloatHistogramChunkOnAppend(t *testing.T, oldChunk Chunk, hApp *Fl
|
|||
|
||||
func assertNoNewFloatHistogramChunkOnAppend(t *testing.T, oldChunk Chunk, hApp *FloatHistogramAppender, ts int64, h *histogram.FloatHistogram, expectHeader CounterResetHeader) {
|
||||
oldChunkBytes := oldChunk.Bytes()
|
||||
newChunk, recoded, newAppender, err := hApp.AppendFloatHistogram(nil, 0, ts, h, false)
|
||||
newChunk, recoded, newAppender, err := hApp.AppendFloatHistogram(0, ts, h, false)
|
||||
require.Greater(t, len(oldChunk.Bytes()), len(oldChunkBytes)) // Check that current chunk is bigger than previously.
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, newChunk)
|
||||
|
|
@ -745,7 +683,7 @@ func assertNoNewFloatHistogramChunkOnAppend(t *testing.T, oldChunk Chunk, hApp *
|
|||
|
||||
func assertRecodedFloatHistogramChunkOnAppend(t *testing.T, prevChunk Chunk, hApp *FloatHistogramAppender, ts int64, h *histogram.FloatHistogram, expectHeader CounterResetHeader) {
|
||||
prevChunkBytes := prevChunk.Bytes()
|
||||
newChunk, recoded, newAppender, err := hApp.AppendFloatHistogram(nil, 0, ts, h, false)
|
||||
newChunk, recoded, newAppender, err := hApp.AppendFloatHistogram(0, ts, h, false)
|
||||
require.Equal(t, prevChunkBytes, prevChunk.Bytes()) // Sanity check that previous chunk is untouched. This may change in the future if we implement in-place recoding.
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, newChunk)
|
||||
|
|
@ -959,7 +897,7 @@ func TestFloatHistogramChunkAppendableWithEmptySpan(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, 0, c.NumSamples())
|
||||
|
||||
_, _, _, err = app.AppendFloatHistogram(nil, 0, 1, tc.h1, true)
|
||||
_, _, _, err = app.AppendFloatHistogram(0, 1, tc.h1, true)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, c.NumSamples())
|
||||
hApp, _ := app.(*FloatHistogramAppender)
|
||||
|
|
@ -1019,7 +957,7 @@ func TestFloatHistogramChunkAppendableGauge(t *testing.T) {
|
|||
|
||||
ts := int64(1234567890)
|
||||
|
||||
chk, _, app, err := app.AppendFloatHistogram(nil, 0, ts, h.Copy(), false)
|
||||
chk, _, app, err := app.AppendFloatHistogram(0, ts, h.Copy(), false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
require.Equal(t, 1, c.NumSamples())
|
||||
|
|
@ -1259,7 +1197,7 @@ func TestFloatHistogramAppendOnlyErrors(t *testing.T) {
|
|||
|
||||
h := tsdbutil.GenerateTestFloatHistogram(0)
|
||||
var isRecoded bool
|
||||
c, isRecoded, app, err = app.AppendFloatHistogram(nil, 0, 1, h, true)
|
||||
c, isRecoded, app, err = app.AppendFloatHistogram(0, 1, h, true)
|
||||
require.Nil(t, c)
|
||||
require.False(t, isRecoded)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -1267,7 +1205,7 @@ func TestFloatHistogramAppendOnlyErrors(t *testing.T) {
|
|||
// Add erroring histogram.
|
||||
h2 := h.Copy()
|
||||
h2.Schema++
|
||||
c, isRecoded, _, err = app.AppendFloatHistogram(nil, 0, 2, h2, true)
|
||||
c, isRecoded, _, err = app.AppendFloatHistogram(0, 2, h2, true)
|
||||
require.Nil(t, c)
|
||||
require.False(t, isRecoded)
|
||||
require.EqualError(t, err, "float histogram schema change")
|
||||
|
|
@ -1281,7 +1219,7 @@ func TestFloatHistogramAppendOnlyErrors(t *testing.T) {
|
|||
|
||||
h := tsdbutil.GenerateTestFloatHistogram(0)
|
||||
var isRecoded bool
|
||||
c, isRecoded, app, err = app.AppendFloatHistogram(nil, 0, 1, h, true)
|
||||
c, isRecoded, app, err = app.AppendFloatHistogram(0, 1, h, true)
|
||||
require.Nil(t, c)
|
||||
require.False(t, isRecoded)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -1289,7 +1227,7 @@ func TestFloatHistogramAppendOnlyErrors(t *testing.T) {
|
|||
// Add erroring histogram.
|
||||
h2 := h.Copy()
|
||||
h2.CounterResetHint = histogram.CounterReset
|
||||
c, isRecoded, _, err = app.AppendFloatHistogram(nil, 0, 2, h2, true)
|
||||
c, isRecoded, _, err = app.AppendFloatHistogram(0, 2, h2, true)
|
||||
require.Nil(t, c)
|
||||
require.False(t, isRecoded)
|
||||
require.EqualError(t, err, "float histogram counter reset")
|
||||
|
|
@ -1303,7 +1241,7 @@ func TestFloatHistogramAppendOnlyErrors(t *testing.T) {
|
|||
|
||||
h := tsdbutil.GenerateTestCustomBucketsFloatHistogram(0)
|
||||
var isRecoded bool
|
||||
c, isRecoded, app, err = app.AppendFloatHistogram(nil, 0, 1, h, true)
|
||||
c, isRecoded, app, err = app.AppendFloatHistogram(0, 1, h, true)
|
||||
require.Nil(t, c)
|
||||
require.False(t, isRecoded)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -1311,7 +1249,7 @@ func TestFloatHistogramAppendOnlyErrors(t *testing.T) {
|
|||
// Add erroring histogram.
|
||||
h2 := h.Copy()
|
||||
h2.CustomValues = []float64{0, 1, 2, 3, 4, 5, 6, 7}
|
||||
c, isRecoded, _, err = app.AppendFloatHistogram(nil, 0, 2, h2, true)
|
||||
c, isRecoded, _, err = app.AppendFloatHistogram(0, 2, h2, true)
|
||||
require.Nil(t, c)
|
||||
require.False(t, isRecoded)
|
||||
require.EqualError(t, err, "float histogram counter reset")
|
||||
|
|
@ -1344,10 +1282,10 @@ func TestFloatHistogramUniqueSpansAfterNext(t *testing.T) {
|
|||
app, err := c.Appender()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendFloatHistogram(nil, 0, 0, h1, false)
|
||||
_, _, _, err = app.AppendFloatHistogram(0, 0, h1, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendFloatHistogram(nil, 0, 1, h2, false)
|
||||
_, _, _, err = app.AppendFloatHistogram(0, 1, h2, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create an iterator and advance to the first histogram.
|
||||
|
|
@ -1390,10 +1328,10 @@ func TestFloatHistogramUniqueCustomValuesAfterNext(t *testing.T) {
|
|||
app, err := c.Appender()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendFloatHistogram(nil, 0, 0, h1, false)
|
||||
_, _, _, err = app.AppendFloatHistogram(0, 0, h1, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendFloatHistogram(nil, 0, 1, h2, false)
|
||||
_, _, _, err = app.AppendFloatHistogram(0, 1, h2, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create an iterator and advance to the first histogram.
|
||||
|
|
@ -1435,7 +1373,7 @@ func TestFloatHistogramEmptyBucketsWithGaps(t *testing.T) {
|
|||
c := NewFloatHistogramChunk()
|
||||
app, err := c.Appender()
|
||||
require.NoError(t, err)
|
||||
_, _, _, err = app.AppendFloatHistogram(nil, 0, 1, h1, false)
|
||||
_, _, _, err = app.AppendFloatHistogram(0, 1, h1, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
h2 := &histogram.FloatHistogram{
|
||||
|
|
@ -1448,7 +1386,7 @@ func TestFloatHistogramEmptyBucketsWithGaps(t *testing.T) {
|
|||
}
|
||||
require.NoError(t, h2.Validate())
|
||||
|
||||
newC, recoded, _, err := app.AppendFloatHistogram(nil, 0, 2, h2, false)
|
||||
newC, recoded, _, err := app.AppendFloatHistogram(0, 2, h2, false)
|
||||
require.NoError(t, err)
|
||||
require.True(t, recoded)
|
||||
require.NotNil(t, newC)
|
||||
|
|
@ -1483,7 +1421,7 @@ func TestFloatHistogramIteratorFailIfSchemaInValid(t *testing.T) {
|
|||
app, err := c.Appender()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendFloatHistogram(nil, 0, 1, h, false)
|
||||
_, _, _, err = app.AppendFloatHistogram(0, 1, h, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
it := c.Iterator(nil)
|
||||
|
|
@ -1512,7 +1450,7 @@ func TestFloatHistogramIteratorReduceSchema(t *testing.T) {
|
|||
app, err := c.Appender()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendFloatHistogram(nil, 0, 1, h, false)
|
||||
_, _, _, err = app.AppendFloatHistogram(0, 1, h, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
it := c.Iterator(nil)
|
||||
|
|
|
|||
|
|
@ -734,27 +734,20 @@ func (a *HistogramAppender) writeSumDelta(v float64) {
|
|||
xorWrite(a.b, v, a.sum, &a.leading, &a.trailing)
|
||||
}
|
||||
|
||||
func (*HistogramAppender) AppendFloatHistogram(*FloatHistogramAppender, int64, int64, *histogram.FloatHistogram, bool) (Chunk, bool, Appender, error) {
|
||||
func (*HistogramAppender) AppendFloatHistogram(int64, int64, *histogram.FloatHistogram, bool) (Chunk, bool, Appender, error) {
|
||||
panic("appended a float histogram sample to a histogram chunk")
|
||||
}
|
||||
|
||||
func (a *HistogramAppender) AppendHistogram(prev *HistogramAppender, _, t int64, h *histogram.Histogram, appendOnly bool) (Chunk, bool, Appender, error) {
|
||||
func (a *HistogramAppender) AppendHistogram(_, t int64, h *histogram.Histogram, appendOnly bool) (Chunk, bool, Appender, error) {
|
||||
if a.NumSamples() == 0 {
|
||||
a.appendHistogram(t, h)
|
||||
if h.CounterResetHint == histogram.GaugeType {
|
||||
switch h.CounterResetHint {
|
||||
case histogram.GaugeType:
|
||||
a.setCounterResetHeader(GaugeType)
|
||||
return nil, false, a, nil
|
||||
case histogram.CounterReset:
|
||||
a.setCounterResetHeader(CounterReset)
|
||||
}
|
||||
|
||||
switch {
|
||||
case h.CounterResetHint == histogram.CounterReset:
|
||||
// Always honor the explicit counter reset hint.
|
||||
a.setCounterResetHeader(CounterReset)
|
||||
case prev != nil:
|
||||
// This is a new chunk, but continued from a previous one. We need to calculate the reset header unless already set.
|
||||
_, _, _, _, _, counterReset := prev.appendable(h)
|
||||
a.setCounterResetHeader(counterReset)
|
||||
}
|
||||
return nil, false, a, nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func TestFirstHistogramExplicitCounterReset(t *testing.T) {
|
|||
chk := NewHistogramChunk()
|
||||
app, err := chk.Appender()
|
||||
require.NoError(t, err)
|
||||
newChk, recoded, newApp, err := app.AppendHistogram(nil, 0, 0, h, false)
|
||||
newChk, recoded, newApp, err := app.AppendHistogram(0, 0, h, false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, newChk)
|
||||
require.False(t, recoded)
|
||||
|
|
@ -102,7 +102,7 @@ func TestHistogramChunkSameBuckets(t *testing.T) {
|
|||
},
|
||||
NegativeBuckets: []int64{2, 1, -1, -1}, // counts: 2, 3, 2, 1 (total 8)
|
||||
}
|
||||
chk, _, app, err := app.AppendHistogram(nil, 0, ts, h, false)
|
||||
chk, _, app, err := app.AppendHistogram(0, ts, h, false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
exp = append(exp, result{t: ts, h: h, fh: h.ToFloat(nil)})
|
||||
|
|
@ -116,7 +116,7 @@ func TestHistogramChunkSameBuckets(t *testing.T) {
|
|||
h.Sum = 24.4
|
||||
h.PositiveBuckets = []int64{5, -2, 1, -2} // counts: 5, 3, 4, 2 (total 14)
|
||||
h.NegativeBuckets = []int64{4, -1, 1, -1} // counts: 4, 3, 4, 4 (total 15)
|
||||
chk, _, _, err = app.AppendHistogram(nil, 0, ts, h, false)
|
||||
chk, _, _, err = app.AppendHistogram(0, ts, h, false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
hExp := h.Copy()
|
||||
|
|
@ -135,7 +135,7 @@ func TestHistogramChunkSameBuckets(t *testing.T) {
|
|||
h.Sum = 24.4
|
||||
h.PositiveBuckets = []int64{6, 1, -3, 6} // counts: 6, 7, 4, 10 (total 27)
|
||||
h.NegativeBuckets = []int64{5, 1, -2, 3} // counts: 5, 6, 4, 7 (total 22)
|
||||
chk, _, _, err = app.AppendHistogram(nil, 0, ts, h, false)
|
||||
chk, _, _, err = app.AppendHistogram(0, ts, h, false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
hExp = h.Copy()
|
||||
|
|
@ -235,7 +235,7 @@ func TestHistogramChunkBucketChanges(t *testing.T) {
|
|||
NegativeBuckets: []int64{1},
|
||||
}
|
||||
|
||||
chk, _, app, err := app.AppendHistogram(nil, 0, ts1, h1, false)
|
||||
chk, _, app, err := app.AppendHistogram(0, ts1, h1, false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
require.Equal(t, 1, c.NumSamples())
|
||||
|
|
@ -271,7 +271,7 @@ func TestHistogramChunkBucketChanges(t *testing.T) {
|
|||
require.True(t, ok) // Only new buckets came in.
|
||||
require.Equal(t, NotCounterReset, cr)
|
||||
c, app = hApp.recode(posInterjections, negInterjections, h2.PositiveSpans, h2.NegativeSpans)
|
||||
chk, _, _, err = app.AppendHistogram(nil, 0, ts2, h2, false)
|
||||
chk, _, _, err = app.AppendHistogram(0, ts2, h2, false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
|
||||
|
|
@ -344,7 +344,7 @@ func TestHistogramChunkAppendable(t *testing.T) {
|
|||
|
||||
ts := int64(1234567890)
|
||||
|
||||
chk, _, app, err := app.AppendHistogram(nil, 0, ts, h.Copy(), false)
|
||||
chk, _, app, err := app.AppendHistogram(0, ts, h.Copy(), false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
require.Equal(t, 1, c.NumSamples())
|
||||
|
|
@ -574,71 +574,6 @@ func TestHistogramChunkAppendable(t *testing.T) {
|
|||
assertNewHistogramChunkOnAppend(t, c, hApp, ts+1, h2, CounterReset, histogram.UnknownCounterReset)
|
||||
}
|
||||
|
||||
{ // Start new chunk explicitly, and append a new histogram that is considered appendable to the previous chunk.
|
||||
_, hApp, ts, h1 := setup(eh)
|
||||
h2 := h1.Copy() // Identity is appendable.
|
||||
|
||||
nextChunk := NewHistogramChunk()
|
||||
app, err := nextChunk.Appender()
|
||||
require.NoError(t, err)
|
||||
newChunk, recoded, newApp, err := app.AppendHistogram(hApp, 0, ts+1, h2, false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, newChunk)
|
||||
require.False(t, recoded)
|
||||
require.Equal(t, app, newApp)
|
||||
assertSampleCount(t, nextChunk, 1, ValHistogram)
|
||||
require.Equal(t, NotCounterReset, nextChunk.GetCounterResetHeader())
|
||||
assertFirstIntHistogramSampleHint(t, nextChunk, histogram.UnknownCounterReset)
|
||||
}
|
||||
|
||||
{ // Start new chunk explicitly, and append a new histogram that is not considered appendable to the previous chunk.
|
||||
_, hApp, ts, h1 := setup(eh)
|
||||
h2 := h1.Copy()
|
||||
h2.Count-- // Make this not appendable due to counter reset.
|
||||
|
||||
nextChunk := NewHistogramChunk()
|
||||
app, err := nextChunk.Appender()
|
||||
require.NoError(t, err)
|
||||
newChunk, recoded, newApp, err := app.AppendHistogram(hApp, 0, ts+1, h2, false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, newChunk)
|
||||
require.False(t, recoded)
|
||||
require.Equal(t, app, newApp)
|
||||
assertSampleCount(t, nextChunk, 1, ValHistogram)
|
||||
require.Equal(t, CounterReset, nextChunk.GetCounterResetHeader())
|
||||
assertFirstIntHistogramSampleHint(t, nextChunk, histogram.UnknownCounterReset)
|
||||
}
|
||||
|
||||
{ // Start new chunk explicitly, and append a new histogram that would need recoding if we added it to the chunk.
|
||||
_, hApp, ts, h1 := setup(eh)
|
||||
h2 := h1.Copy()
|
||||
h2.PositiveSpans = []histogram.Span{
|
||||
{Offset: 0, Length: 3},
|
||||
{Offset: 1, Length: 1},
|
||||
{Offset: 1, Length: 4},
|
||||
{Offset: 3, Length: 3},
|
||||
}
|
||||
h2.Count += 9
|
||||
h2.ZeroCount++
|
||||
h2.Sum = 30
|
||||
// Existing histogram should get values converted from the above to:
|
||||
// 6 3 0 3 0 0 2 4 5 0 1 (previous values with some new empty buckets in between)
|
||||
// so the new histogram should have new counts >= these per-bucket counts, e.g.:
|
||||
h2.PositiveBuckets = []int64{7, -2, -4, 2, -2, -1, 2, 3, 0, -5, 1} // 7 5 1 3 1 0 2 5 5 0 1 (total 30)
|
||||
|
||||
nextChunk := NewHistogramChunk()
|
||||
app, err := nextChunk.Appender()
|
||||
require.NoError(t, err)
|
||||
newChunk, recoded, newApp, err := app.AppendHistogram(hApp, 0, ts+1, h2, false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, newChunk)
|
||||
require.False(t, recoded)
|
||||
require.Equal(t, app, newApp)
|
||||
assertSampleCount(t, nextChunk, 1, ValHistogram)
|
||||
require.Equal(t, NotCounterReset, nextChunk.GetCounterResetHeader())
|
||||
assertFirstIntHistogramSampleHint(t, nextChunk, histogram.UnknownCounterReset)
|
||||
}
|
||||
|
||||
{
|
||||
// Start a new chunk with a histogram that has an empty bucket.
|
||||
// Add a histogram that has the same bucket missing.
|
||||
|
|
@ -776,7 +711,7 @@ func TestHistogramChunkAppendable(t *testing.T) {
|
|||
|
||||
func assertNewHistogramChunkOnAppend(t *testing.T, oldChunk Chunk, hApp *HistogramAppender, ts int64, h *histogram.Histogram, expectHeader CounterResetHeader, expectHint histogram.CounterResetHint) {
|
||||
oldChunkBytes := oldChunk.Bytes()
|
||||
newChunk, recoded, newAppender, err := hApp.AppendHistogram(nil, 0, ts, h, false)
|
||||
newChunk, recoded, newAppender, err := hApp.AppendHistogram(0, ts, h, false)
|
||||
require.Equal(t, oldChunkBytes, oldChunk.Bytes()) // Sanity check that previous chunk is untouched.
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, newChunk)
|
||||
|
|
@ -791,7 +726,7 @@ func assertNewHistogramChunkOnAppend(t *testing.T, oldChunk Chunk, hApp *Histogr
|
|||
|
||||
func assertNoNewHistogramChunkOnAppend(t *testing.T, currChunk Chunk, hApp *HistogramAppender, ts int64, h *histogram.Histogram, expectHeader CounterResetHeader) {
|
||||
prevChunkBytes := currChunk.Bytes()
|
||||
newChunk, recoded, newAppender, err := hApp.AppendHistogram(nil, 0, ts, h, false)
|
||||
newChunk, recoded, newAppender, err := hApp.AppendHistogram(0, ts, h, false)
|
||||
require.Greater(t, len(currChunk.Bytes()), len(prevChunkBytes)) // Check that current chunk is bigger than previously.
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, newChunk)
|
||||
|
|
@ -804,7 +739,7 @@ func assertNoNewHistogramChunkOnAppend(t *testing.T, currChunk Chunk, hApp *Hist
|
|||
|
||||
func assertRecodedHistogramChunkOnAppend(t *testing.T, prevChunk Chunk, hApp *HistogramAppender, ts int64, h *histogram.Histogram, expectHeader CounterResetHeader) {
|
||||
prevChunkBytes := prevChunk.Bytes()
|
||||
newChunk, recoded, newAppender, err := hApp.AppendHistogram(nil, 0, ts, h, false)
|
||||
newChunk, recoded, newAppender, err := hApp.AppendHistogram(0, ts, h, false)
|
||||
require.Equal(t, prevChunkBytes, prevChunk.Bytes()) // Sanity check that previous chunk is untouched. This may change in the future if we implement in-place recoding.
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, newChunk)
|
||||
|
|
@ -1029,7 +964,7 @@ func TestHistogramChunkAppendableWithEmptySpan(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, 0, c.NumSamples())
|
||||
|
||||
_, _, _, err = app.AppendHistogram(nil, 1, 0, tc.h1, true)
|
||||
_, _, _, err = app.AppendHistogram(1, 0, tc.h1, true)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, c.NumSamples())
|
||||
hApp, _ := app.(*HistogramAppender)
|
||||
|
|
@ -1172,7 +1107,7 @@ func TestAtFloatHistogram(t *testing.T) {
|
|||
app, err := chk.Appender()
|
||||
require.NoError(t, err)
|
||||
for i := range input {
|
||||
newc, _, _, err := app.AppendHistogram(nil, 0, int64(i), &input[i], false)
|
||||
newc, _, _, err := app.AppendHistogram(0, int64(i), &input[i], false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, newc)
|
||||
}
|
||||
|
|
@ -1230,7 +1165,7 @@ func TestHistogramChunkAppendableGauge(t *testing.T) {
|
|||
|
||||
ts := int64(1234567890)
|
||||
|
||||
chk, _, app, err := app.AppendHistogram(nil, 0, ts, h.Copy(), false)
|
||||
chk, _, app, err := app.AppendHistogram(0, ts, h.Copy(), false)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, chk)
|
||||
require.Equal(t, 1, c.NumSamples())
|
||||
|
|
@ -1471,7 +1406,7 @@ func TestHistogramAppendOnlyErrors(t *testing.T) {
|
|||
|
||||
h := tsdbutil.GenerateTestHistogram(0)
|
||||
var isRecoded bool
|
||||
c, isRecoded, app, err = app.AppendHistogram(nil, 0, 1, h, true)
|
||||
c, isRecoded, app, err = app.AppendHistogram(0, 1, h, true)
|
||||
require.Nil(t, c)
|
||||
require.False(t, isRecoded)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -1479,7 +1414,7 @@ func TestHistogramAppendOnlyErrors(t *testing.T) {
|
|||
// Add erroring histogram.
|
||||
h2 := h.Copy()
|
||||
h2.Schema++
|
||||
c, isRecoded, _, err = app.AppendHistogram(nil, 0, 2, h2, true)
|
||||
c, isRecoded, _, err = app.AppendHistogram(0, 2, h2, true)
|
||||
require.Nil(t, c)
|
||||
require.False(t, isRecoded)
|
||||
require.EqualError(t, err, "histogram schema change")
|
||||
|
|
@ -1493,7 +1428,7 @@ func TestHistogramAppendOnlyErrors(t *testing.T) {
|
|||
|
||||
h := tsdbutil.GenerateTestHistogram(0)
|
||||
var isRecoded bool
|
||||
c, isRecoded, app, err = app.AppendHistogram(nil, 0, 1, h, true)
|
||||
c, isRecoded, app, err = app.AppendHistogram(0, 1, h, true)
|
||||
require.Nil(t, c)
|
||||
require.False(t, isRecoded)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -1501,7 +1436,7 @@ func TestHistogramAppendOnlyErrors(t *testing.T) {
|
|||
// Add erroring histogram.
|
||||
h2 := h.Copy()
|
||||
h2.CounterResetHint = histogram.CounterReset
|
||||
c, isRecoded, _, err = app.AppendHistogram(nil, 0, 2, h2, true)
|
||||
c, isRecoded, _, err = app.AppendHistogram(0, 2, h2, true)
|
||||
require.Nil(t, c)
|
||||
require.False(t, isRecoded)
|
||||
require.EqualError(t, err, "histogram counter reset")
|
||||
|
|
@ -1515,7 +1450,7 @@ func TestHistogramAppendOnlyErrors(t *testing.T) {
|
|||
|
||||
h := tsdbutil.GenerateTestCustomBucketsHistogram(0)
|
||||
var isRecoded bool
|
||||
c, isRecoded, app, err = app.AppendHistogram(nil, 0, 1, h, true)
|
||||
c, isRecoded, app, err = app.AppendHistogram(0, 1, h, true)
|
||||
require.Nil(t, c)
|
||||
require.False(t, isRecoded)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -1523,7 +1458,7 @@ func TestHistogramAppendOnlyErrors(t *testing.T) {
|
|||
// Add erroring histogram.
|
||||
h2 := h.Copy()
|
||||
h2.CustomValues = []float64{0, 1, 2, 3, 4, 5, 6, 7}
|
||||
c, isRecoded, _, err = app.AppendHistogram(nil, 0, 2, h2, true)
|
||||
c, isRecoded, _, err = app.AppendHistogram(0, 2, h2, true)
|
||||
require.Nil(t, c)
|
||||
require.False(t, isRecoded)
|
||||
require.EqualError(t, err, "histogram counter reset")
|
||||
|
|
@ -1556,10 +1491,10 @@ func TestHistogramUniqueSpansAfterNextWithAtHistogram(t *testing.T) {
|
|||
app, err := c.Appender()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendHistogram(nil, 0, 0, h1, false)
|
||||
_, _, _, err = app.AppendHistogram(0, 0, h1, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendHistogram(nil, 0, 1, h2, false)
|
||||
_, _, _, err = app.AppendHistogram(0, 1, h2, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create an iterator and advance to the first histogram.
|
||||
|
|
@ -1607,10 +1542,10 @@ func TestHistogramUniqueSpansAfterNextWithAtFloatHistogram(t *testing.T) {
|
|||
app, err := c.Appender()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendHistogram(nil, 0, 0, h1, false)
|
||||
_, _, _, err = app.AppendHistogram(0, 0, h1, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendHistogram(nil, 0, 1, h2, false)
|
||||
_, _, _, err = app.AppendHistogram(0, 1, h2, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create an iterator and advance to the first histogram.
|
||||
|
|
@ -1653,10 +1588,10 @@ func TestHistogramCustomValuesInternedAfterNextWithAtHistogram(t *testing.T) {
|
|||
app, err := c.Appender()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendHistogram(nil, 0, 0, h1, false)
|
||||
_, _, _, err = app.AppendHistogram(0, 0, h1, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendHistogram(nil, 0, 1, h2, false)
|
||||
_, _, _, err = app.AppendHistogram(0, 1, h2, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create an iterator and advance to the first histogram.
|
||||
|
|
@ -1699,10 +1634,10 @@ func TestHistogramCustomValuesInternedAfterNextWithAtFloatHistogram(t *testing.T
|
|||
app, err := c.Appender()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendHistogram(nil, 0, 0, h1, false)
|
||||
_, _, _, err = app.AppendHistogram(0, 0, h1, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendHistogram(nil, 0, 1, h2, false)
|
||||
_, _, _, err = app.AppendHistogram(0, 1, h2, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create an iterator and advance to the first histogram.
|
||||
|
|
@ -1754,7 +1689,7 @@ func BenchmarkAppendable(b *testing.B) {
|
|||
b.Fatal(err)
|
||||
}
|
||||
|
||||
_, _, _, err = app.AppendHistogram(nil, 0, 1, h, true)
|
||||
_, _, _, err = app.AppendHistogram(0, 1, h, true)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
|
@ -1791,7 +1726,7 @@ func TestIntHistogramEmptyBucketsWithGaps(t *testing.T) {
|
|||
c := NewHistogramChunk()
|
||||
app, err := c.Appender()
|
||||
require.NoError(t, err)
|
||||
_, _, _, err = app.AppendHistogram(nil, 0, 1, h1, false)
|
||||
_, _, _, err = app.AppendHistogram(0, 1, h1, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
h2 := &histogram.Histogram{
|
||||
|
|
@ -1804,7 +1739,7 @@ func TestIntHistogramEmptyBucketsWithGaps(t *testing.T) {
|
|||
}
|
||||
require.NoError(t, h2.Validate())
|
||||
|
||||
newC, recoded, _, err := app.AppendHistogram(nil, 0, 2, h2, false)
|
||||
newC, recoded, _, err := app.AppendHistogram(0, 2, h2, false)
|
||||
require.NoError(t, err)
|
||||
require.True(t, recoded)
|
||||
require.NotNil(t, newC)
|
||||
|
|
@ -1839,7 +1774,7 @@ func TestHistogramIteratorFailIfSchemaInValid(t *testing.T) {
|
|||
app, err := c.Appender()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendHistogram(nil, 0, 1, h, false)
|
||||
_, _, _, err = app.AppendHistogram(0, 1, h, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
it := c.Iterator(nil)
|
||||
|
|
@ -1868,7 +1803,7 @@ func TestHistogramIteratorReduceSchema(t *testing.T) {
|
|||
app, err := c.Appender()
|
||||
require.NoError(t, err)
|
||||
|
||||
_, _, _, err = app.AppendHistogram(nil, 0, 1, h, false)
|
||||
_, _, _, err = app.AppendHistogram(0, 1, h, false)
|
||||
require.NoError(t, err)
|
||||
|
||||
it := c.Iterator(nil)
|
||||
|
|
|
|||
|
|
@ -225,11 +225,11 @@ func (a *xorAppender) writeVDelta(v float64) {
|
|||
xorWrite(a.b, v, a.v, &a.leading, &a.trailing)
|
||||
}
|
||||
|
||||
func (*xorAppender) AppendHistogram(*HistogramAppender, int64, int64, *histogram.Histogram, bool) (Chunk, bool, Appender, error) {
|
||||
func (*xorAppender) AppendHistogram(int64, int64, *histogram.Histogram, bool) (Chunk, bool, Appender, error) {
|
||||
panic("appended a histogram sample to a float chunk")
|
||||
}
|
||||
|
||||
func (*xorAppender) AppendFloatHistogram(*FloatHistogramAppender, int64, int64, *histogram.FloatHistogram, bool) (Chunk, bool, Appender, error) {
|
||||
func (*xorAppender) AppendFloatHistogram(int64, int64, *histogram.FloatHistogram, bool) (Chunk, bool, Appender, error) {
|
||||
panic("appended a float histogram sample to a float chunk")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ func ChunkFromSamplesGeneric(s Samples) (Meta, error) {
|
|||
case chunkenc.ValFloat:
|
||||
ca.Append(s.Get(i).ST(), s.Get(i).T(), s.Get(i).F())
|
||||
case chunkenc.ValHistogram:
|
||||
newChunk, _, ca, err = ca.AppendHistogram(nil, s.Get(i).ST(), s.Get(i).T(), s.Get(i).H(), false)
|
||||
newChunk, _, ca, err = ca.AppendHistogram(s.Get(i).ST(), s.Get(i).T(), s.Get(i).H(), false)
|
||||
if err != nil {
|
||||
return emptyChunk, err
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ func ChunkFromSamplesGeneric(s Samples) (Meta, error) {
|
|||
return emptyChunk, errors.New("did not expect to start a second chunk")
|
||||
}
|
||||
case chunkenc.ValFloatHistogram:
|
||||
newChunk, _, ca, err = ca.AppendFloatHistogram(nil, s.Get(i).ST(), s.Get(i).T(), s.Get(i).FH(), false)
|
||||
newChunk, _, ca, err = ca.AppendFloatHistogram(s.Get(i).ST(), s.Get(i).T(), s.Get(i).FH(), false)
|
||||
if err != nil {
|
||||
return emptyChunk, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1860,9 +1860,6 @@ func (s *memSeries) appendHistogram(t int64, h *histogram.Histogram, appendID ui
|
|||
// Head controls the execution of recoding, so that we own the proper
|
||||
// chunk reference afterwards and mmap used up chunks.
|
||||
|
||||
// Ignoring ok is ok, since we don't want to compare to the wrong previous appender anyway.
|
||||
prevApp, _ := s.app.(*chunkenc.HistogramAppender)
|
||||
|
||||
c, sampleInOrder, chunkCreated := s.histogramsAppendPreprocessor(t, chunkenc.EncHistogram, o)
|
||||
if !sampleInOrder {
|
||||
return sampleInOrder, chunkCreated
|
||||
|
|
@ -1873,13 +1870,8 @@ func (s *memSeries) appendHistogram(t int64, h *histogram.Histogram, appendID ui
|
|||
recoded bool
|
||||
)
|
||||
|
||||
if !chunkCreated {
|
||||
// Ignore the previous appender if we continue the current chunk.
|
||||
prevApp = nil
|
||||
}
|
||||
|
||||
// TODO(krajorama): pass ST.
|
||||
newChunk, recoded, s.app, _ = s.app.AppendHistogram(prevApp, 0, t, h, false) // false=request a new chunk if needed
|
||||
newChunk, recoded, s.app, _ = s.app.AppendHistogram(0, t, h, false) // false=request a new chunk if needed
|
||||
|
||||
s.lastHistogramValue = h
|
||||
s.lastFloatHistogramValue = nil
|
||||
|
|
@ -1918,9 +1910,6 @@ func (s *memSeries) appendFloatHistogram(t int64, fh *histogram.FloatHistogram,
|
|||
// Head controls the execution of recoding, so that we own the proper
|
||||
// chunk reference afterwards and mmap used up chunks.
|
||||
|
||||
// Ignoring ok is ok, since we don't want to compare to the wrong previous appender anyway.
|
||||
prevApp, _ := s.app.(*chunkenc.FloatHistogramAppender)
|
||||
|
||||
c, sampleInOrder, chunkCreated := s.histogramsAppendPreprocessor(t, chunkenc.EncFloatHistogram, o)
|
||||
if !sampleInOrder {
|
||||
return sampleInOrder, chunkCreated
|
||||
|
|
@ -1931,13 +1920,8 @@ func (s *memSeries) appendFloatHistogram(t int64, fh *histogram.FloatHistogram,
|
|||
recoded bool
|
||||
)
|
||||
|
||||
if !chunkCreated {
|
||||
// Ignore the previous appender if we continue the current chunk.
|
||||
prevApp = nil
|
||||
}
|
||||
|
||||
// TODO(krajorama): pass ST.
|
||||
newChunk, recoded, s.app, _ = s.app.AppendFloatHistogram(prevApp, 0, t, fh, false) // False means request a new chunk if needed.
|
||||
newChunk, recoded, s.app, _ = s.app.AppendFloatHistogram(0, t, fh, false) // False means request a new chunk if needed.
|
||||
|
||||
s.lastHistogramValue = nil
|
||||
s.lastFloatHistogramValue = fh
|
||||
|
|
|
|||
|
|
@ -2550,7 +2550,8 @@ func TestHeadAppenderV2_Append_CounterResetHeader(t *testing.T) {
|
|||
appendHistogram(h)
|
||||
}
|
||||
|
||||
checkExpCounterResetHeader(chunkenc.NotCounterReset, chunkenc.NotCounterReset)
|
||||
// There is no check for implicit counter reset between chunks.
|
||||
checkExpCounterResetHeader(chunkenc.UnknownCounterReset, chunkenc.UnknownCounterReset)
|
||||
|
||||
// Changing schema will cut a new chunk with unknown counter reset.
|
||||
h.Schema++
|
||||
|
|
@ -2578,7 +2579,8 @@ func TestHeadAppenderV2_Append_CounterResetHeader(t *testing.T) {
|
|||
for range 2000 {
|
||||
appendHistogram(h)
|
||||
}
|
||||
checkExpCounterResetHeader(chunkenc.NotCounterReset, chunkenc.NotCounterReset)
|
||||
// There is no check for implicit counter reset between chunks.
|
||||
checkExpCounterResetHeader(chunkenc.UnknownCounterReset, chunkenc.UnknownCounterReset)
|
||||
|
||||
// Counter reset with counter reset in a positive bucket.
|
||||
h.PositiveBuckets[len(h.PositiveBuckets)-1]--
|
||||
|
|
|
|||
|
|
@ -5041,7 +5041,8 @@ func TestHistogramCounterResetHeader(t *testing.T) {
|
|||
appendHistogram(h)
|
||||
}
|
||||
|
||||
checkExpCounterResetHeader(chunkenc.NotCounterReset, chunkenc.NotCounterReset)
|
||||
// There is no check for implicit counter reset between chunks.
|
||||
checkExpCounterResetHeader(chunkenc.UnknownCounterReset, chunkenc.UnknownCounterReset)
|
||||
|
||||
// Changing schema will cut a new chunk with unknown counter reset.
|
||||
h.Schema++
|
||||
|
|
@ -5069,7 +5070,8 @@ func TestHistogramCounterResetHeader(t *testing.T) {
|
|||
for range 2000 {
|
||||
appendHistogram(h)
|
||||
}
|
||||
checkExpCounterResetHeader(chunkenc.NotCounterReset, chunkenc.NotCounterReset)
|
||||
// There is no check for implicit counter reset between chunks.
|
||||
checkExpCounterResetHeader(chunkenc.UnknownCounterReset, chunkenc.UnknownCounterReset)
|
||||
|
||||
// Counter reset with counter reset in a positive bucket.
|
||||
h.PositiveBuckets[len(h.PositiveBuckets)-1]--
|
||||
|
|
|
|||
|
|
@ -103,9 +103,6 @@ func (o *OOOChunk) ToEncodedChunks(mint, maxt int64) (chks []memChunk, err error
|
|||
encoding = chunkenc.EncFloatHistogram
|
||||
}
|
||||
|
||||
// prevApp is the appender for the previous sample.
|
||||
prevApp := app
|
||||
|
||||
if encoding != prevEncoding { // For the first sample, this will always be true as EncNone != EncXOR | EncHistogram | EncFloatHistogram
|
||||
if prevEncoding != chunkenc.EncNone {
|
||||
chks = append(chks, memChunk{chunk, cmint, cmaxt, nil})
|
||||
|
|
@ -131,14 +128,12 @@ func (o *OOOChunk) ToEncodedChunks(mint, maxt int64) (chks []memChunk, err error
|
|||
// TODO(krajorama): pass ST.
|
||||
app.Append(0, s.t, s.f)
|
||||
case chunkenc.EncHistogram:
|
||||
// Ignoring ok is ok, since we don't want to compare to the wrong previous appender anyway.
|
||||
prevHApp, _ := prevApp.(*chunkenc.HistogramAppender)
|
||||
var (
|
||||
newChunk chunkenc.Chunk
|
||||
recoded bool
|
||||
)
|
||||
// TODO(krajorama): pass ST.
|
||||
newChunk, recoded, app, _ = app.AppendHistogram(prevHApp, 0, s.t, s.h, false)
|
||||
newChunk, recoded, app, _ = app.AppendHistogram(0, s.t, s.h, false)
|
||||
if newChunk != nil { // A new chunk was allocated.
|
||||
if !recoded {
|
||||
chks = append(chks, memChunk{chunk, cmint, cmaxt, nil})
|
||||
|
|
@ -147,14 +142,12 @@ func (o *OOOChunk) ToEncodedChunks(mint, maxt int64) (chks []memChunk, err error
|
|||
chunk = newChunk
|
||||
}
|
||||
case chunkenc.EncFloatHistogram:
|
||||
// Ignoring ok is ok, since we don't want to compare to the wrong previous appender anyway.
|
||||
prevHApp, _ := prevApp.(*chunkenc.FloatHistogramAppender)
|
||||
var (
|
||||
newChunk chunkenc.Chunk
|
||||
recoded bool
|
||||
)
|
||||
// TODO(krajorama): pass ST.
|
||||
newChunk, recoded, app, _ = app.AppendFloatHistogram(prevHApp, 0, s.t, s.fh, false)
|
||||
newChunk, recoded, app, _ = app.AppendFloatHistogram(0, s.t, s.fh, false)
|
||||
if newChunk != nil { // A new chunk was allocated.
|
||||
if !recoded {
|
||||
chks = append(chks, memChunk{chunk, cmint, cmaxt, nil})
|
||||
|
|
|
|||
|
|
@ -900,7 +900,7 @@ func (p *populateWithDelChunkSeriesIterator) populateCurrForSingleChunk() bool {
|
|||
var h *histogram.Histogram
|
||||
t, h = p.currDelIter.AtHistogram(nil)
|
||||
st = p.currDelIter.AtST()
|
||||
_, _, app, err = app.AppendHistogram(nil, st, t, h, true)
|
||||
_, _, app, err = app.AppendHistogram(st, t, h, true)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
|
@ -933,7 +933,7 @@ func (p *populateWithDelChunkSeriesIterator) populateCurrForSingleChunk() bool {
|
|||
var h *histogram.FloatHistogram
|
||||
t, h = p.currDelIter.AtFloatHistogram(nil)
|
||||
st = p.currDelIter.AtST()
|
||||
_, _, app, err = app.AppendFloatHistogram(nil, st, t, h, true)
|
||||
_, _, app, err = app.AppendFloatHistogram(st, t, h, true)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
|
@ -1024,7 +1024,7 @@ func (p *populateWithDelChunkSeriesIterator) populateChunksFromIterable() bool {
|
|||
st = p.currDelIter.AtST()
|
||||
// No need to set prevApp as AppendHistogram will set the
|
||||
// counter reset header for the appender that's returned.
|
||||
newChunk, recoded, app, err = app.AppendHistogram(nil, st, t, v, false)
|
||||
newChunk, recoded, app, err = app.AppendHistogram(st, t, v, false)
|
||||
}
|
||||
case chunkenc.ValFloatHistogram:
|
||||
{
|
||||
|
|
@ -1033,7 +1033,7 @@ func (p *populateWithDelChunkSeriesIterator) populateChunksFromIterable() bool {
|
|||
st = p.currDelIter.AtST()
|
||||
// No need to set prevApp as AppendHistogram will set the
|
||||
// counter reset header for the appender that's returned.
|
||||
newChunk, recoded, app, err = app.AppendFloatHistogram(nil, st, t, v, false)
|
||||
newChunk, recoded, app, err = app.AppendFloatHistogram(st, t, v, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ func createIdxChkReaders(t *testing.T, tc []seriesSamples) (IndexReader, ChunkRe
|
|||
app, _ := chunk.Appender()
|
||||
for _, smpl := range chk {
|
||||
require.NotNil(t, smpl.fh, "chunk can only contain one type of sample")
|
||||
_, _, _, err := app.AppendFloatHistogram(nil, 0, smpl.t, smpl.fh, true)
|
||||
_, _, _, err := app.AppendFloatHistogram(0, smpl.t, smpl.fh, true)
|
||||
require.NoError(t, err, "chunk should be appendable")
|
||||
}
|
||||
chkReader[chunkRef] = chunk
|
||||
|
|
@ -150,7 +150,7 @@ func createIdxChkReaders(t *testing.T, tc []seriesSamples) (IndexReader, ChunkRe
|
|||
app, _ := chunk.Appender()
|
||||
for _, smpl := range chk {
|
||||
require.NotNil(t, smpl.h, "chunk can only contain one type of sample")
|
||||
_, _, _, err := app.AppendHistogram(nil, 0, smpl.t, smpl.h, true)
|
||||
_, _, _, err := app.AppendHistogram(0, smpl.t, smpl.h, true)
|
||||
require.NoError(t, err, "chunk should be appendable")
|
||||
}
|
||||
chkReader[chunkRef] = chunk
|
||||
|
|
|
|||
Loading…
Reference in a new issue