From db4df8a13e8f5f7cce37c8140662af24ae14f518 Mon Sep 17 00:00:00 2001 From: SuperQ Date: Tue, 12 Jul 2022 09:28:33 +0200 Subject: [PATCH] Update queryfrontend for Cortex changes. Signed-off-by: SuperQ --- go.mod | 1 - go.sum | 1 - pkg/queryfrontend/config.go | 7 ++++--- pkg/queryfrontend/request.go | 27 +++++++++++++++++++++++++++ pkg/queryfrontend/response.go | 10 ++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index ee111151259..7ba051a7f8b 100644 --- a/go.mod +++ b/go.mod @@ -40,7 +40,6 @@ require ( github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da github.com/golang/snappy v0.0.4 github.com/googleapis/gax-go v2.0.2+incompatible - github.com/grafana/dskit v0.0.0-20211021180445-3bd016e9d7f1 github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware/providers/kit/v2 v2.0.0-20201002093600-73cf2ae9d891 github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.2.0.20201207153454-9f6bf00c00a7 diff --git a/go.sum b/go.sum index c911195a322..4d1c1193fbd 100644 --- a/go.sum +++ b/go.sum @@ -833,7 +833,6 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7 github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/grafana/dskit v0.0.0-20211021180445-3bd016e9d7f1 h1:Qf+/W3Tup0nO21tgJmO14WJK0yyrm4L2UJipZP+Zoow= github.com/grafana/dskit v0.0.0-20211021180445-3bd016e9d7f1/go.mod h1:uPG2nyK4CtgNDmWv7qyzYcdI+S90kHHRWvHnBtEMBXM= github.com/grafana/regexp v0.0.0-20220304095617-2e8d9baf4ac2 h1:uirlL/j72L93RhV4+mkWhjv0cov2I0MIgPOG9rMDr1k= github.com/grafana/regexp v0.0.0-20220304095617-2e8d9baf4ac2/go.mod h1:M5qHK+eWfAv8VR/265dIuEpL3fNfeC21tXXp9itM24A= diff --git a/pkg/queryfrontend/config.go b/pkg/queryfrontend/config.go index d0b24596b85..898ee35a0c7 100644 --- a/pkg/queryfrontend/config.go +++ b/pkg/queryfrontend/config.go @@ -9,11 +9,12 @@ import ( cortexcache "github.com/cortexproject/cortex/pkg/chunk/cache" "github.com/cortexproject/cortex/pkg/frontend/transport" + "github.com/cortexproject/cortex/pkg/querier" "github.com/cortexproject/cortex/pkg/querier/queryrange" + "github.com/cortexproject/cortex/pkg/util/flagext" cortexvalidation "github.com/cortexproject/cortex/pkg/util/validation" "github.com/go-kit/log" "github.com/go-kit/log/level" - "github.com/grafana/dskit/flagext" "github.com/pkg/errors" "gopkg.in/yaml.v2" @@ -244,7 +245,7 @@ func (cfg *Config) Validate() error { if cfg.QueryRangeConfig.SplitQueriesByInterval <= 0 { return errors.New("split queries interval should be greater than 0 when caching is enabled") } - if err := cfg.QueryRangeConfig.ResultsCacheConfig.Validate(); err != nil { + if err := cfg.QueryRangeConfig.ResultsCacheConfig.Validate(querier.Config{}); err != nil { return errors.Wrap(err, "invalid ResultsCache config for query_range tripperware") } } @@ -253,7 +254,7 @@ func (cfg *Config) Validate() error { if cfg.LabelsConfig.SplitQueriesByInterval <= 0 { return errors.New("split queries interval should be greater than 0 when caching is enabled") } - if err := cfg.LabelsConfig.ResultsCacheConfig.Validate(); err != nil { + if err := cfg.LabelsConfig.ResultsCacheConfig.Validate(querier.Config{}); err != nil { return errors.Wrap(err, "invalid ResultsCache config for labels tripperware") } } diff --git a/pkg/queryfrontend/request.go b/pkg/queryfrontend/request.go index 81142d556f1..818f4864c51 100644 --- a/pkg/queryfrontend/request.go +++ b/pkg/queryfrontend/request.go @@ -44,6 +44,7 @@ type ThanosQueryRangeRequest struct { StoreMatchers [][]*labels.Matcher CachingOptions queryrange.CachingOptions Headers []*RequestHeader + Stats string } // IsDedupEnabled returns true if deduplication is enabled. @@ -68,6 +69,14 @@ func (r *ThanosQueryRangeRequest) GetCachingOptions() queryrange.CachingOptions return r.CachingOptions } +func (r *ThanosQueryRangeRequest) GetStats() string { return r.Stats } + +func (r *ThanosQueryRangeRequest) WithStats(stats string) queryrange.Request { + q := *r + q.Stats = stats + return &q +} + // WithStartEnd clone the current request with different start and end timestamp. func (r *ThanosQueryRangeRequest) WithStartEnd(start, end int64) queryrange.Request { q := *r @@ -123,6 +132,7 @@ type ThanosLabelsRequest struct { PartialResponse bool CachingOptions queryrange.CachingOptions Headers []*RequestHeader + Stats string } // GetStoreMatchers returns store matches. @@ -143,6 +153,14 @@ func (r *ThanosLabelsRequest) GetQuery() string { return "" } func (r *ThanosLabelsRequest) GetCachingOptions() queryrange.CachingOptions { return r.CachingOptions } +func (r *ThanosLabelsRequest) GetStats() string { return r.Stats } + +func (r *ThanosLabelsRequest) WithStats(stats string) queryrange.Request { + q := *r + q.Stats = stats + return &q +} + // WithStartEnd clone the current request with different start and end timestamp. func (r *ThanosLabelsRequest) WithStartEnd(start, end int64) queryrange.Request { q := *r @@ -196,6 +214,7 @@ type ThanosSeriesRequest struct { StoreMatchers [][]*labels.Matcher CachingOptions queryrange.CachingOptions Headers []*RequestHeader + Stats string } // IsDedupEnabled returns true if deduplication is enabled. @@ -219,6 +238,14 @@ func (r *ThanosSeriesRequest) GetQuery() string { return "" } func (r *ThanosSeriesRequest) GetCachingOptions() queryrange.CachingOptions { return r.CachingOptions } +func (r *ThanosSeriesRequest) GetStats() string { return r.Stats } + +func (r *ThanosSeriesRequest) WithStats(stats string) queryrange.Request { + q := *r + q.Stats = stats + return &q +} + // WithStartEnd clone the current request with different start and end timestamp. func (r *ThanosSeriesRequest) WithStartEnd(start, end int64) queryrange.Request { q := *r diff --git a/pkg/queryfrontend/response.go b/pkg/queryfrontend/response.go index 4eb754c68a7..5add07bc85f 100644 --- a/pkg/queryfrontend/response.go +++ b/pkg/queryfrontend/response.go @@ -29,6 +29,16 @@ func (ThanosResponseExtractor) ResponseWithoutHeaders(resp queryrange.Response) return resp } +func (ThanosResponseExtractor) ResponseWithoutStats(resp queryrange.Response) queryrange.Response { + switch tr := resp.(type) { + case *ThanosLabelsResponse: + return &ThanosLabelsResponse{Status: queryrange.StatusSuccess, Data: tr.Data} + case *ThanosSeriesResponse: + return &ThanosSeriesResponse{Status: queryrange.StatusSuccess, Data: tr.Data} + } + return resp +} + // headersToQueryRangeHeaders convert slice of ResponseHeader to Cortex queryrange.PrometheusResponseHeader in an // unsafe manner. It reuses the same memory. func headersToQueryRangeHeaders(headers []*ResponseHeader) []*queryrange.PrometheusResponseHeader {