From 1c55653d67258f14f3b10fe15e0ae3e41b79ae37 Mon Sep 17 00:00:00 2001 From: SuperQ Date: Sun, 29 Jan 2023 11:13:44 +0100 Subject: [PATCH] Store: Don't error when no stores are matched It's normal and not an error if a query does not match due to no downstream stores. This is common when querying with external labels and tiered query servers. This bug was introduced in https://github.com/thanos-io/thanos/pull/5296 Fixes: https://github.com/thanos-io/thanos/issues/5862 Signed-off-by: SuperQ --- CHANGELOG.md | 1 + pkg/store/proxy.go | 11 +++++------ pkg/store/proxy_test.go | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6fc6ae5ab8..624f38d191f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#6050](https://github.com/thanos-io/thanos/pull/6050) Store: Re-try bucket store initial sync upon failure. - [#6066](https://github.com/thanos-io/thanos/pull/6066) Tracing: fixed panic because of nil sampler - [#6067](https://github.com/thanos-io/thanos/pull/6067) Receive: fixed panic when querying uninitialized TSDBs. +- [#6082](https://github.com/thanos-io/thanos/pull/6082) Store: Don't error when no stores are matched. ### Changed diff --git a/pkg/store/proxy.go b/pkg/store/proxy.go index d969ddb64f6..ac4f69c9ef4 100644 --- a/pkg/store/proxy.go +++ b/pkg/store/proxy.go @@ -35,6 +35,10 @@ type ctxKey int // StoreMatcherKey is the context key for the store's allow list. const StoreMatcherKey = ctxKey(0) +// ErrorNoStoresMatched is returned if the query does match any data. +// This can happen with Query servers trees and external labels. +var ErrorNoStoresMatched = errors.New("No StoreAPIs matched for this query") + // Client holds meta information about a store. type Client interface { // StoreClient to access the store. @@ -278,12 +282,7 @@ func (s *ProxyStore) Series(originalRequest *storepb.SeriesRequest, srv storepb. } if len(stores) == 0 { - err := errors.New("No StoreAPIs matched for this query") - level.Debug(reqLogger).Log("err", err, "stores", strings.Join(storeDebugMsgs, ";")) - if sendErr := srv.Send(storepb.NewWarnSeriesResponse(err)); sendErr != nil { - level.Error(reqLogger).Log("err", sendErr) - return status.Error(codes.Unknown, errors.Wrap(sendErr, "send series response").Error()) - } + level.Debug(reqLogger).Log("err", ErrorNoStoresMatched, "stores", strings.Join(storeDebugMsgs, ";")) return nil } diff --git a/pkg/store/proxy_test.go b/pkg/store/proxy_test.go index 7c1064233f8..eb852d67c6a 100644 --- a/pkg/store/proxy_test.go +++ b/pkg/store/proxy_test.go @@ -133,7 +133,7 @@ func TestProxyStore_Series(t *testing.T) { MaxTime: 300, Matchers: []storepb.LabelMatcher{{Name: "a", Value: "a", Type: storepb.LabelMatcher_EQ}}, }, - expectedWarningsLen: 1, // No store matched for this query. + expectedWarningsLen: 0, // No store matched for this query. }, { title: "no storeAPI available for 301-302 time range", @@ -153,7 +153,7 @@ func TestProxyStore_Series(t *testing.T) { MaxTime: 400, Matchers: []storepb.LabelMatcher{{Name: "a", Value: "a", Type: storepb.LabelMatcher_EQ}}, }, - expectedWarningsLen: 1, // No store matched for this query. + expectedWarningsLen: 0, // No store matched for this query. }, { title: "storeAPI available for time range; no series for ext=2 external label matcher", @@ -174,7 +174,7 @@ func TestProxyStore_Series(t *testing.T) { MaxTime: 300, Matchers: []storepb.LabelMatcher{{Name: "ext", Value: "2", Type: storepb.LabelMatcher_EQ}}, }, - expectedWarningsLen: 1, // No store matched for this query. + expectedWarningsLen: 0, // No store matched for this query. }, { title: "storeAPI available for time range; available series for ext=1 external label matcher", @@ -499,7 +499,7 @@ func TestProxyStore_Series(t *testing.T) { Matchers: []storepb.LabelMatcher{{Name: "ext", Value: "1", Type: storepb.LabelMatcher_EQ}}, }, storeDebugMatchers: [][]*labels.Matcher{{labels.MustNewMatcher(labels.MatchEqual, "__address__", "foo")}}, - expectedWarningsLen: 1, // No stores match. + expectedWarningsLen: 0, // No stores match. }, { title: "sharded series response",