prometheus/storage
beorn7 4696b46dd5 storage: Fix mixed samples handling in sampleRing
Two issues are fixed here, that lead to the same problem:

1. If `newSampleRing` is called with an unknown ValueType including
   ValueNone, we have initialized the interface buffer (`iBuf`).
   However, we would still use a specialized buffer for the first
   sample, opportunistically assuming that we might still not
   encounter mixed samples and we should go down the more efficient
   road.

2. If the `sampleRing` is `reset`, we leave all buffers alone,
   including `iBuf`, which is generally fine, but not for `iBuf`, see
   below.

In both cases, `iBuf` already contains values, but we will fill one of
the specialized buffers first. Once we then actually encounter mixed
samples, the content of the specialized buffer is copied into `iBuf`
using `append`. That's by itself the right idea because `iBuf` might
be `nil`, and even if not, it might or might not have the right
capacity. However, this approach assumes that `iBuf` is empty, or more
precisely has a length of zero.

This commit makes sure that `iBuf` does not get needlessly initialized
in `newSampleRing` and that it is emptied upon `reset`.

A test case is added to demonstrate both issues above.

Signed-off-by: beorn7 <beorn@grafana.com>
2023-10-31 16:18:09 +01:00
..
remote Update dependencies for 2.48 (#12964) 2023-10-15 13:47:42 -04:00
buffer_test.go storage: Fix mixed samples handling in sampleRing 2023-10-31 16:18:09 +01:00
buffer.go storage: Fix mixed samples handling in sampleRing 2023-10-31 16:18:09 +01:00
fanout_test.go Add warnings (and annotations) to PromQL query results (#12152) 2023-09-14 18:57:31 +02:00
fanout.go Add context argument to Querier.Select (#12660) 2023-09-12 12:37:38 +02:00
generic.go Add warnings (and annotations) to PromQL query results (#12152) 2023-09-14 18:57:31 +02:00
interface.go Add warnings (and annotations) to PromQL query results (#12152) 2023-09-14 18:57:31 +02:00
lazy.go Add warnings (and annotations) to PromQL query results (#12152) 2023-09-14 18:57:31 +02:00
memoized_iterator_test.go Make MemoizedSeriesIterator not implement chunkenc.Iterator 2023-05-03 12:45:39 -07:00
memoized_iterator.go Make MemoizedSeriesIterator not implement chunkenc.Iterator 2023-05-03 12:45:39 -07:00
merge_test.go storage: make histogram reset handling consistent in chainSampleIterator (#12779) 2023-09-19 17:06:46 +02:00
merge.go Storage: reduce memory allocations when merging series sets (#12938) 2023-10-06 12:28:07 +01:00
noop.go Add warnings (and annotations) to PromQL query results (#12152) 2023-09-14 18:57:31 +02:00
secondary.go Add warnings (and annotations) to PromQL query results (#12152) 2023-09-14 18:57:31 +02:00
series_test.go storage: make histogram reset handling consistent in chainSampleIterator (#12779) 2023-09-19 17:06:46 +02:00
series.go Add a chunk size limit in bytes (#12054) 2023-08-24 15:21:17 +02:00