From dba04fc7aa54ce84eac7f72b2f845129badcd877 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 --- pkg/queryfrontend/config.go | 7 ++++--- pkg/queryfrontend/request.go | 27 +++++++++++++++++++++++++++ pkg/queryfrontend/response.go | 10 ++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) 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 {