diff --git a/tsdb/head_test.go b/tsdb/head_test.go index 46a65e0ef5..c0468c0142 100644 --- a/tsdb/head_test.go +++ b/tsdb/head_test.go @@ -4799,14 +4799,8 @@ func TestOOOHistogramCounterResetHeaders(t *testing.T) { expOOOMmappedChunks{ header: chunkenc.UnknownCounterReset, mint: 205, - maxt: 205, - numSamples: 1, - }, - expOOOMmappedChunks{ - header: chunkenc.UnknownCounterReset, - mint: 210, maxt: 210, - numSamples: 1, + numSamples: 2, }, expOOOMmappedChunks{ header: chunkenc.UnknownCounterReset, @@ -4825,7 +4819,7 @@ func TestOOOHistogramCounterResetHeaders(t *testing.T) { // One mmapped chunk with (ts, val) [(300, 3000), (301, 3001), (302, 3002), (303, 3003), (350, 4000)]. checkOOOExpCounterResetHeader(expOOOMmappedChunks{ - header: chunkenc.CounterReset, + header: chunkenc.UnknownCounterReset, mint: 300, maxt: 350, numSamples: 5, diff --git a/tsdb/ooo_head.go b/tsdb/ooo_head.go index 5e214a6d9c..1215b4ea1c 100644 --- a/tsdb/ooo_head.go +++ b/tsdb/ooo_head.go @@ -127,6 +127,11 @@ func (o *OOOChunk) ToEncodedChunks(mint, maxt int64) (chks []memChunk, err error case chunkenc.EncXOR: app.Append(s.t, s.f) case chunkenc.EncHistogram: + // Clear explicit counter reset headers in the chunk as we cannot trust + // them in OOO. + if s.h.CounterResetHint == histogram.CounterReset { + s.h.CounterResetHint = histogram.UnknownCounterReset + } // Ignoring ok is ok, since we don't want to compare to the wrong previous appender anyway. prevHApp, _ := prevApp.(*chunkenc.HistogramAppender) var ( @@ -148,6 +153,11 @@ func (o *OOOChunk) ToEncodedChunks(mint, maxt int64) (chks []memChunk, err error chunk = newChunk } case chunkenc.EncFloatHistogram: + // Clear explicit counter reset headers in the chunk as we cannot trust + // them in OOO. + if s.fh.CounterResetHint == histogram.CounterReset { + s.fh.CounterResetHint = histogram.UnknownCounterReset + } // Ignoring ok is ok, since we don't want to compare to the wrong previous appender anyway. prevHApp, _ := prevApp.(*chunkenc.FloatHistogramAppender) var ( diff --git a/tsdb/ooo_head_test.go b/tsdb/ooo_head_test.go index c5386757a5..63cb97734b 100644 --- a/tsdb/ooo_head_test.go +++ b/tsdb/ooo_head_test.go @@ -213,14 +213,22 @@ func TestOOOChunks_ToEncodedChunks(t *testing.T) { }, }, "has an explicit counter reset": { + samples: []sample{ + {t: 1100, h: h2explicit}, + }, + expectedCounterResets: []histogram.CounterResetHint{histogram.UnknownCounterReset}, + expectedChunks: []chunkVerify{ + {encoding: chunkenc.EncHistogram, minTime: 1100, maxTime: 1100}, + }, + }, + "has an explicit counter reset inside": { samples: []sample{ {t: 1000, h: h1}, {t: 1100, h: h2explicit}, }, - expectedCounterResets: []histogram.CounterResetHint{histogram.UnknownCounterReset, histogram.UnknownCounterReset}, + expectedCounterResets: []histogram.CounterResetHint{histogram.UnknownCounterReset, histogram.NotCounterReset}, expectedChunks: []chunkVerify{ - {encoding: chunkenc.EncHistogram, minTime: 1000, maxTime: 1000}, - {encoding: chunkenc.EncHistogram, minTime: 1100, maxTime: 1100}, + {encoding: chunkenc.EncHistogram, minTime: 1000, maxTime: 1100}, }, }, "has a recoded histogram": { // Regression test for wrong minT, maxT in histogram recoding.