diff --git a/CHANGELOG.md b/CHANGELOG.md index e9432cde7d..734a224121 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * [FEATURE] Introduced `ruler.for-grace-period`, Minimum duration between alert and restored "for" state. This is maintained only for alerts with configured "for" time greater than grace period. #2783 * [FEATURE] Introduced `ruler.for-resend-delay`, Minimum amount of time to wait before resending an alert to Alertmanager. #2783 * [ENHANCEMENT] Experimental: Querier can now optionally query secondary store. This is specified by using `-querier.second-store-engine` option, with values `chunks` or `tsdb`. Standard configuration options for this store are used. Additionally, this querying can be configured to happen only for queries that need data older than `-querier.use-second-store-before-time`. Default value of zero will always query secondary store. #2747 +* [BUGFIX] Fixed a bug in the index intersect code causing storage to return more chunks/series than required. #2796 * [BUGFIX] Fixed the number of reported keys in the background cache queue. #2764 * [BUGFIX] Fix race in processing of headers in sharded queries. #2762 diff --git a/pkg/chunk/chunk_store.go b/pkg/chunk/chunk_store.go index 41eef9c41b..4363696cf0 100644 --- a/pkg/chunk/chunk_store.go +++ b/pkg/chunk/chunk_store.go @@ -424,11 +424,13 @@ func (c *store) lookupChunksByMetricName(ctx context.Context, userID string, fro // Receive chunkSets from all matchers var chunkIDs []string var lastErr error + var initialized bool for i := 0; i < len(matchers); i++ { select { case incoming := <-incomingChunkIDs: - if chunkIDs == nil { + if !initialized { chunkIDs = incoming + initialized = true } else { chunkIDs = intersectStrings(chunkIDs, incoming) } diff --git a/pkg/chunk/chunk_store_test.go b/pkg/chunk/chunk_store_test.go index f983f71f30..24a49d30c7 100644 --- a/pkg/chunk/chunk_store_test.go +++ b/pkg/chunk/chunk_store_test.go @@ -177,6 +177,10 @@ func TestChunkStore_Get(t *testing.T) { query: `foo{toms="code", bar="baz"}`, expect: []Chunk{fooChunk1}, }, + { + query: `foo{a="b", bar="baz"}`, + expect: nil, + }, { query: `{__name__=~"foo"}`, err: "query must contain metric name", diff --git a/pkg/chunk/series_store.go b/pkg/chunk/series_store.go index a1e062f977..4792ca1ae2 100644 --- a/pkg/chunk/series_store.go +++ b/pkg/chunk/series_store.go @@ -305,12 +305,14 @@ func (c *seriesStore) lookupSeriesByMetricNameMatchers(ctx context.Context, from var lastErr error var cardinalityExceededErrors int var cardinalityExceededError CardinalityExceededError + var initialized bool for i := 0; i < len(matchers); i++ { select { case incoming := <-incomingIDs: preIntersectionCount += len(incoming) - if ids == nil { + if !initialized { ids = incoming + initialized = true } else { ids = intersectStrings(ids, incoming) }